summaryrefslogtreecommitdiff
path: root/spec/models/user_spec.rb
diff options
context:
space:
mode:
authorImre Farkas <ifarkas@gitlab.com>2018-11-15 20:08:46 +0100
committerImre Farkas <ifarkas@gitlab.com>2018-11-26 13:24:00 +0100
commit350f2ba7620812f8ae93e30029451f2c0af4cb1d (patch)
treed1563de7e73b5889b7b20e89103d2b32ce4b9a12 /spec/models/user_spec.rb
parent3b23d06cbee9fb36014e86dee532c858e5f20cca (diff)
downloadgitlab-ce-350f2ba7620812f8ae93e30029451f2c0af4cb1d.tar.gz
User#find_by_any_email to respect confirmed flag on secondary emails
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r--spec/models/user_spec.rb36
1 files changed, 31 insertions, 5 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 733c1c49f08..7bd6dccd0ad 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1137,12 +1137,38 @@ describe User do
expect(described_class.find_by_any_email(user.email.upcase, confirmed: true)).to eq user
end
- it 'finds by secondary email' do
- email = create(:email, email: 'foo@example.com')
- user = email.user
+ context 'finds by secondary email' do
+ let(:user) { email.user }
- expect(described_class.find_by_any_email(email.email)).to eq user
- expect(described_class.find_by_any_email(email.email, confirmed: true)).to eq user
+ context 'primary email confirmed' do
+ context 'secondary email confirmed' do
+ let!(:email) { create(:email, :confirmed, email: 'foo@example.com') }
+
+ it 'finds user respecting the confirmed flag' do
+ expect(described_class.find_by_any_email(email.email)).to eq user
+ expect(described_class.find_by_any_email(email.email, confirmed: true)).to eq user
+ end
+ end
+
+ context 'secondary email not confirmed' do
+ let!(:email) { create(:email, email: 'foo@example.com') }
+
+ it 'finds user respecting the confirmed flag' do
+ expect(described_class.find_by_any_email(email.email)).to eq user
+ expect(described_class.find_by_any_email(email.email, confirmed: true)).to be_nil
+ end
+ end
+ end
+
+ context 'primary email not confirmed' do
+ let(:user) { create(:user, confirmed_at: nil) }
+ let!(:email) { create(:email, :confirmed, user: user, email: 'foo@example.com') }
+
+ it 'finds user respecting the confirmed flag' do
+ expect(described_class.find_by_any_email(email.email)).to eq user
+ expect(described_class.find_by_any_email(email.email, confirmed: true)).to be_nil
+ end
+ end
end
it 'returns nil when nothing found' do