From 45ff4e31094a8b79ed603ae506990b6fa0e7c96e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 28 Jul 2018 22:17:21 -0700 Subject: Add support for searching users by confirmed e-mails This is in preparation for modifying importers to assign e-mails for only confirmed emails. --- spec/models/user_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fc46551c3be..982d24e7eab 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -949,6 +949,7 @@ describe User do user = create(:user, email: 'foo@example.com') expect(described_class.find_by_any_email(user.email)).to eq user + expect(described_class.find_by_any_email(user.email, confirmed: true)).to eq user end it 'finds by secondary email' do @@ -956,11 +957,19 @@ describe User do 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 end it 'returns nil when nothing found' do expect(described_class.find_by_any_email('')).to be_nil end + + it 'returns nil when user is not confirmed' do + user = create(:user, email: 'foo@example.com', confirmed_at: nil) + + expect(described_class.find_by_any_email(user.email, confirmed: false)).to eq(user) + expect(described_class.find_by_any_email(user.email, confirmed: true)).to be_nil + end end describe '.by_any_email' do @@ -974,6 +983,12 @@ describe User do expect(described_class.by_any_email(user.email)).to eq([user]) end + + it 'returns a relation of users for confirmed users' do + user = create(:user) + + expect(described_class.by_any_email(user.email, confirmed: true)).to eq([user]) + end end describe '.search' do -- cgit v1.2.1