Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
81952b61
Commit
81952b61
authored
Jun 24, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
parents
b8af2ecc
43b444f4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
20 deletions
+10
-20
app/models/commit.rb
app/models/commit.rb
+2
-2
app/models/user.rb
app/models/user.rb
+4
-8
spec/models/user_spec.rb
spec/models/user_spec.rb
+4
-10
No files found.
app/models/commit.rb
View file @
81952b61
...
...
@@ -157,11 +157,11 @@ class Commit
end
def
author
User
.
find_for_commit
(
author_email
,
author_name
)
@author
||=
User
.
find_by_any_email
(
author_email
)
end
def
committer
User
.
find_for_commit
(
committer_email
,
committer_name
)
@committer
||=
User
.
find_by_any_email
(
committer_email
)
end
def
notes
...
...
app/models/user.rb
View file @
81952b61
...
...
@@ -225,7 +225,8 @@ class User < ActiveRecord::Base
end
end
def
find_for_commit
(
email
,
name
)
# Find a User by their primary email or any associated secondary email
def
find_by_any_email
(
email
)
user_table
=
arel_table
email_table
=
Email
.
arel_table
...
...
@@ -237,13 +238,8 @@ class User < ActiveRecord::Base
join
(
email_table
,
Arel
::
Nodes
::
OuterJoin
)
.
# ON "users"."id" = "emails"."user_id"
on
(
user_table
[
:id
].
eq
(
email_table
[
:user_id
]))
.
# WHERE ("user"."email" = '<email>' OR "user"."name" = '<name>')
# OR "emails"."email" = '<email>'
where
(
user_table
[
:email
].
eq
(
email
).
or
(
user_table
[
:name
].
eq
(
name
)).
or
(
email_table
[
:email
].
eq
(
email
))
)
# WHERE ("user"."email" = '<email>' OR "emails"."email" = '<email>')
where
(
user_table
[
:email
].
eq
(
email
).
or
(
email_table
[
:email
].
eq
(
email
)))
find_by_sql
(
query
.
to_sql
).
first
end
...
...
spec/models/user_spec.rb
View file @
81952b61
...
...
@@ -366,28 +366,22 @@ describe User do
end
end
describe
'.find_
for_commit
'
do
describe
'.find_
by_any_email
'
do
it
'finds by primary email'
do
user
=
create
(
:user
,
email:
'foo@example.com'
)
expect
(
User
.
find_
for_commit
(
user
.
email
,
''
)).
to
eq
user
expect
(
User
.
find_
by_any_email
(
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
expect
(
User
.
find_by_any_email
(
email
.
email
)).
to
eq
user
end
it
'returns nil when nothing found'
do
expect
(
User
.
find_
for_commit
(
''
,
''
)).
to
be_nil
expect
(
User
.
find_
by_any_email
(
''
)).
to
be_nil
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment