Commit a1a17ac3 authored by Michael Kozono's avatar Michael Kozono

Clean up specs

parent 4bcbc770
...@@ -2,14 +2,12 @@ require 'spec_helper' ...@@ -2,14 +2,12 @@ require 'spec_helper'
describe RegistrationsController do describe RegistrationsController do
describe '#create' do describe '#create' do
let(:user_params) { { user: { name: 'new_user', username: 'new_username', email: 'new@user.com', password: 'Any_password', email_opted_in: email_opted_in } } }
context 'when the user opted-in' do context 'when the user opted-in' do
let(:email_opted_in) { '1' } let(:user_params) { { user: attributes_for(:user, email_opted_in: '1') } }
it 'sets the rest of the email_opted_in fields' do it 'sets the rest of the email_opted_in fields' do
post :create, user_params post :create, user_params
user = User.find_by_username('new_username') user = User.find_by_username!(user_params[:user][:username])
expect(user.email_opted_in).to be_truthy expect(user.email_opted_in).to be_truthy
expect(user.email_opted_in_ip).to be_present expect(user.email_opted_in_ip).to be_present
expect(user.email_opted_in_source).to eq('GitLab.com') expect(user.email_opted_in_source).to eq('GitLab.com')
...@@ -18,11 +16,11 @@ describe RegistrationsController do ...@@ -18,11 +16,11 @@ describe RegistrationsController do
end end
context 'when the user opted-out' do context 'when the user opted-out' do
let(:email_opted_in) { '0' } let(:user_params) { { user: attributes_for(:user, email_opted_in: '0') } }
it 'does not set the rest of the email_opted_in fields' do it 'does not set the rest of the email_opted_in fields' do
post :create, user_params post :create, user_params
user = User.find_by_username('new_username') user = User.find_by_username!(user_params[:user][:username])
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_blank expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank expect(user.email_opted_in_source).to be_blank
......
require 'spec_helper' require 'spec_helper'
feature 'Signup on EE' do feature 'Signup on EE' do
let(:user_attrs) { attributes_for(:user) }
context 'for Gitlab.com' do context 'for Gitlab.com' do
before do before do
expect(Gitlab).to receive(:com?).and_return(true).at_least(:once) expect(Gitlab).to receive(:com?).and_return(true).at_least(:once)
...@@ -8,19 +10,17 @@ feature 'Signup on EE' do ...@@ -8,19 +10,17 @@ feature 'Signup on EE' do
context 'when the user checks the opt-in to email updates box' do context 'when the user checks the opt-in to email updates box' do
it 'creates the user and sets the email_opted_in field truthy' do it 'creates the user and sets the email_opted_in field truthy' do
user = build(:user)
visit root_path visit root_path
fill_in 'new_user_name', with: user.name fill_in 'new_user_name', with: user_attrs[:name]
fill_in 'new_user_username', with: user.username fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user.email fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_email_confirmation', with: user.email fill_in 'new_user_email_confirmation', with: user_attrs[:email]
fill_in 'new_user_password', with: user.password fill_in 'new_user_password', with: user_attrs[:password]
check 'new_user_email_opted_in' check 'new_user_email_opted_in'
click_button "Register" click_button "Register"
user = User.find_by_username!(user.username) user = User.find_by_username!(user_attrs[:username])
expect(user.email_opted_in).to be_truthy expect(user.email_opted_in).to be_truthy
expect(user.email_opted_in_ip).to be_present expect(user.email_opted_in_ip).to be_present
expect(user.email_opted_in_source).to eq('GitLab.com') expect(user.email_opted_in_source).to eq('GitLab.com')
...@@ -30,18 +30,16 @@ feature 'Signup on EE' do ...@@ -30,18 +30,16 @@ feature 'Signup on EE' do
context 'when the user does not check the opt-in to email updates box' do context 'when the user does not check the opt-in to email updates box' do
it 'creates the user and sets the email_opted_in field falsey' do it 'creates the user and sets the email_opted_in field falsey' do
user = build(:user)
visit root_path visit root_path
fill_in 'new_user_name', with: user.name fill_in 'new_user_name', with: user_attrs[:name]
fill_in 'new_user_username', with: user.username fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user.email fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_email_confirmation', with: user.email fill_in 'new_user_email_confirmation', with: user_attrs[:email]
fill_in 'new_user_password', with: user.password fill_in 'new_user_password', with: user_attrs[:password]
click_button "Register" click_button "Register"
user = User.find_by_username!(user.username) user = User.find_by_username!(user_attrs[:username])
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_blank expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank expect(user.email_opted_in_source).to be_blank
...@@ -56,20 +54,18 @@ feature 'Signup on EE' do ...@@ -56,20 +54,18 @@ feature 'Signup on EE' do
end end
it 'does not have a opt-in checkbox, it creates the user and sets email_opted_in to falsey' do it 'does not have a opt-in checkbox, it creates the user and sets email_opted_in to falsey' do
user = build(:user)
visit root_path visit root_path
expect(page).not_to have_selector("[name='new_user_email_opted_in']") expect(page).not_to have_selector("[name='new_user_email_opted_in']")
fill_in 'new_user_name', with: user.name fill_in 'new_user_name', with: user_attrs[:name]
fill_in 'new_user_username', with: user.username fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user.email fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_email_confirmation', with: user.email fill_in 'new_user_email_confirmation', with: user_attrs[:email]
fill_in 'new_user_password', with: user.password fill_in 'new_user_password', with: user_attrs[:password]
click_button "Register" click_button "Register"
user = User.find_by_username!(user.username) user = User.find_by_username!(user_attrs[:username])
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_blank expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank expect(user.email_opted_in_source).to be_blank
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment