summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-10-06 16:50:54 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2017-11-07 22:28:52 +0100
commit44be82dd18c372862c2421a1934ff816f7cccd97 (patch)
tree0db110c64a8acd4221e13d48eb25966a9dd8df80 /spec/models
parent673b6be1fecedd3a4e7126134f3a764694fcf327 (diff)
downloadgitlab-ce-44be82dd18c372862c2421a1934ff816f7cccd97.tar.gz
Refactor User.find_by_any_email
By using SQL::Union we can return a proper ActiveRecord::Relation, making it possible to select the columns we're interested in (instead of all of them).
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/user_spec.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index d2f97009ad9..a3ebf649aa8 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -841,6 +841,19 @@ describe User do
end
end
+ describe '.by_any_email' do
+ it 'returns an ActiveRecord::Relation' do
+ expect(described_class.by_any_email('foo@example.com'))
+ .to be_a_kind_of(ActiveRecord::Relation)
+ end
+
+ it 'returns a relation of users' do
+ user = create(:user)
+
+ expect(described_class.by_any_email(user.email)).to eq([user])
+ end
+ end
+
describe '.search' do
let!(:user) { create(:user, name: 'user', username: 'usern', email: 'email@gmail.com') }
let!(:user2) { create(:user, name: 'user name', username: 'username', email: 'someemail@gmail.com') }