diff options
author | Brett Walker <brett@digitalmoksha.com> | 2017-09-13 16:02:27 +0300 |
---|---|---|
committer | Brett Walker <brett@digitalmoksha.com> | 2017-09-23 16:24:53 +0300 |
commit | 85d2bf778a72f82b10f4bb6ebddc3cedf8ce4e4e (patch) | |
tree | a9de7ecc0d7580f447f91cf325ae9887dd43e374 /spec/models/user_spec.rb | |
parent | b2d53791614da093a32fd7040371cf2054aa9817 (diff) |
when a primary email is replaced and added to the secondary emails list,
make sure it stays confirmed
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 08f58e6d069..45f0144f68e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -379,6 +379,44 @@ describe User do user.update_attributes!(email: 'shawnee.ritchie@denesik.com') end end + + describe '#update_emails_with_primary_email' do + before do + @user = create(:user, email: 'primary@example.com').tap do |user| + user.skip_reconfirmation! + end + @secondary = create :email, email: 'secondary@example.com', user: @user + @user.reload + end + + it 'gets called when email updated' do + expect(@user).to receive(:update_emails_with_primary_email) + @user.update_attributes!(email: 'new_primary@example.com') + end + + it 'does not add old primary to secondary emails' do + @user.update_attributes!(email: 'new_primary@example.com') + @user.reload + expect(@user.emails.count).to eq 1 + expect(@user.emails.first.email).to eq @secondary.email + end + + it 'adds old primary to secondary emails if secondary is becoming a primary' do + @user.update_attributes!(email: @secondary.email) + @user.reload + expect(@user.emails.count).to eq 1 + expect(@user.emails.first.email).to eq 'primary@example.com' + end + + it 'transfers old confirmation values into new secondary' do + org_user = @user + @user.update_attributes!(email: @secondary.email) + @user.reload + expect(@user.emails.count).to eq 1 + expect(@user.emails.first.confirmed_at).not_to eq nil + end + end + end describe '#update_tracked_fields!', :clean_gitlab_redis_shared_state do |