diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-06-17 16:07:09 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-06-17 16:37:11 -0400 |
commit | 7e31a369f55764a6bccab340b8a3827710623793 (patch) | |
tree | 308c155f8f76d54a2bc565278b117dea60570bb8 /spec/models | |
parent | 2efb0b6e935a9da206134a61d344b4d0334392a3 (diff) | |
download | gitlab-ce-7e31a369f55764a6bccab340b8a3827710623793.tar.gz |
Spec and refactor User.find_for_commit
Now it executes a single query instead of a possible three at the cost
of some scary-looking ARel calls.
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/user_spec.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f3e278e5c5f..fcd65467285 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -340,6 +340,31 @@ describe User do end end + describe '.find_for_commit' do + it 'finds by primary email' do + user = create(:user, email: 'foo@example.com') + + expect(User.find_for_commit(user.email, '')).to eq user + end + + it 'finds by secondary email' do + email = create(:email, email: 'foo@example.com') + user = email.user + + expect(User.find_for_commit(email.email, '')).to eq user + end + + it 'finds by name' do + user = create(:user, name: 'Joey JoJo') + + expect(User.find_for_commit('', 'Joey JoJo')).to eq user + end + + it 'returns nil when nothing found' do + expect(User.find_for_commit('', '')).to be_nil + end + end + describe 'search' do let(:user1) { create(:user, username: 'James', email: 'james@testing.com') } let(:user2) { create(:user, username: 'jameson', email: 'jameson@example.com') } |