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
Léo-Paul Géneau
gitlab-ce
Commits
87010983
Commit
87010983
authored
Feb 23, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Treat special cases accordingly.
* Event without project * Fail early on unexpectedly missing author
parent
d4d0740e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
app/models/user_contributed_projects.rb
app/models/user_contributed_projects.rb
+15
-1
spec/models/user_contributed_projects_spec.rb
spec/models/user_contributed_projects_spec.rb
+8
-0
No files found.
app/models/user_contributed_projects.rb
View file @
87010983
...
@@ -8,7 +8,21 @@ class UserContributedProjects < ActiveRecord::Base
...
@@ -8,7 +8,21 @@ class UserContributedProjects < ActiveRecord::Base
CACHE_EXPIRY_TIME
=
1
.
day
CACHE_EXPIRY_TIME
=
1
.
day
def
self
.
track
(
event
)
def
self
.
track
(
event
)
attributes
=
{
project_id:
event
.
project_id
,
user_id:
event
.
author_id
}
# For events without a project, we simply don't care.
# An example of this is the creation of a snippet (which
# is not related to any project).
return
unless
event
.
project
# This is a precaution because the cache lookup
# will work just fine without an author.
#
# However, this should never happen (tm).
raise
'event#author not present unexpectedly'
unless
event
.
author
attributes
=
{
project_id:
event
.
project_id
,
user_id:
event
.
author_id
}
cached_exists?
(
attributes
)
do
cached_exists?
(
attributes
)
do
begin
begin
...
...
spec/models/user_contributed_projects_spec.rb
View file @
87010983
...
@@ -31,6 +31,14 @@ describe UserContributedProjects do
...
@@ -31,6 +31,14 @@ describe UserContributedProjects do
described_class
.
track
(
event
)
described_class
.
track
(
event
)
end
.
to
change
{
UserContributedProjects
.
count
}.
from
(
0
).
to
(
1
)
end
.
to
change
{
UserContributedProjects
.
count
}.
from
(
0
).
to
(
1
)
end
end
describe
'with an event without a project'
do
let
(
:event
)
{
build
(
:event
,
project:
nil
)
}
it
'ignores the event'
do
expect
{
subject
}.
not_to
change
{
UserContributedProjects
.
count
}
end
end
end
end
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
...
...
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