diff options
author | Brett Walker <bwalker@gitlab.com> | 2017-10-28 15:45:44 +0200 |
---|---|---|
committer | digitalMoksha <bwalker@gitlab.com> | 2017-11-03 12:07:24 +0100 |
commit | 80e5d52630aa8f9a57742a54004caa45c7903ad6 (patch) | |
tree | 23288acdce20e193f450ba3fa96abc4931d7013c | |
parent | de4e0fa58c71d4c9b6e83d9487b2540ef4918497 (diff) | |
download | gitlab-ce-80e5d52630aa8f9a57742a54004caa45c7903ad6.tar.gz |
added additional specs
-rw-r--r-- | spec/factories/users.rb | 5 | ||||
-rw-r--r-- | spec/models/email_spec.rb | 30 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 18 | ||||
-rw-r--r-- | spec/services/confirmation_service_spec.rb | 4 |
4 files changed, 43 insertions, 14 deletions
diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 4000cd085b7..c7d8dc4cc5d 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -16,6 +16,11 @@ FactoryGirl.define do user.ensure_rss_token end + trait :unconfirmed do + confirmed_at { nil } + confirmation_token { 'token_1' } + end + trait :admin do admin true end diff --git a/spec/models/email_spec.rb b/spec/models/email_spec.rb index 400d6f05ea7..c3483220ec4 100644 --- a/spec/models/email_spec.rb +++ b/spec/models/email_spec.rb @@ -12,27 +12,33 @@ describe Email do it 'can not add the same email to same user' do create(:email, email: 'new@email.com', user: user1) - expect(build(:email, email: 'new@email.com', user: user1)).not_to be_valid + expect(build(:email, email: 'New@email.com', user: user1)).not_to be_valid end - it 'can add the same email for different users' do - create(:email, email: 'new@email.com', user: user1) + context 'secondary already added by another user' do + it 'does not add if the other one is already confirmed' do + create(:email, :confirmed, email: 'new@email.com', user: user1) - expect(build(:email, email: 'new@email.com', user: user2)).to be_valid - end + expect(build(:email, email: 'New@email.com', user: user2)).not_to be_valid + end - it 'does not add duplicate email if the other one is already confirmed' do - create(:email, :confirmed, email: 'new@email.com', user: user1) + it 'adds if the other one is not confirmed' do + create(:email, email: 'new@email.com', user: user1) - expect(build(:email, email: 'new@email.com', user: user2)).not_to be_valid + expect(build(:email, email: 'New@email.com', user: user2)).to be_valid + end end - it 'adds if another user has same email and not confirmed' do - expect(build(:email, email: user1.email, user: user2)).not_to be_valid + context 'user email already registered' do + it 'does not add if user email is confirmed' do + expect(build(:email, email: user1.email, user: user2)).not_to be_valid + end - user1.update_attribute(:confirmed_at, nil) + it 'adds if user email is unconfirmed' do + user1 = create(:user, :unconfirmed) - expect(build(:email, email: user1.email, user: user2)).to be_valid + expect(build(:email, email: user1.email, user: user2)).to be_valid + end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 70734253277..309bfe0df9c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -271,12 +271,30 @@ describe User do it 'email should be allowed if it is not confirmed yet' do create(:email, email: 'secondary@example.com') user = build(:user, email: 'secondary@example.com') + expect(user).to be_valid end it 'email should not be allowed if it is confirmed' do create(:email, :confirmed, email: 'secondary@example.com') user = build(:user, email: 'secondary@example.com') + + expect(user).not_to be_valid + end + end + + context 'email registered by another user' do + it 'email should not be allowed if it is unconfirmed' do + create(:user, :unconfirmed, email: 'NewUser@example.com') + user = build(:user, email: 'newuser@example.com') + + expect(user).not_to be_valid + end + + it 'email should not be allowed if it is confirmed' do + create(:user, email: 'NewUser@example.com') + user = build(:user, email: 'newuser@example.com') + expect(user).not_to be_valid end end diff --git a/spec/services/confirmation_service_spec.rb b/spec/services/confirmation_service_spec.rb index 66c82ef93ac..d0217092b7f 100644 --- a/spec/services/confirmation_service_spec.rb +++ b/spec/services/confirmation_service_spec.rb @@ -9,7 +9,7 @@ describe ConfirmationService do context 'confirming secondary email' do it 'removes secondary email duplicates' do user.emails.create(email: 'new@email.com', confirmation_token: 'token_1') - user2.emails.create(email: 'new@email.com') + user2.emails.create(email: 'New@email.com') expect(Email.where(email: 'new@email.com').count).to eq 2 @@ -39,7 +39,7 @@ describe ConfirmationService do it 'does not confirm with a confirmed secondary with same email' do user.emails.create(email: 'new@email.com', confirmation_token: 'token_1') - user2.emails.create(email: 'new@email.com', confirmed_at: Time.now) + user2.emails.create(email: 'New@email.com', confirmed_at: Time.now) expect(Email.confirmed.count).to eq 1 |