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
ebcf3c73
Commit
ebcf3c73
authored
Feb 23, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track which projects a user contributed to.
Closes #43460.
parent
f88d5132
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
0 deletions
+63
-0
app/models/event.rb
app/models/event.rb
+5
-0
app/models/user_contributed_projects.rb
app/models/user_contributed_projects.rb
+13
-0
spec/models/event_spec.rb
spec/models/event_spec.rb
+8
-0
spec/models/user_contributed_projects_spec.rb
spec/models/user_contributed_projects_spec.rb
+37
-0
No files found.
app/models/event.rb
View file @
ebcf3c73
...
...
@@ -65,6 +65,7 @@ class Event < ActiveRecord::Base
# Callbacks
after_create
:reset_project_activity
after_create
:set_last_repository_updated_at
,
if: :push?
after_create
:track_user_contributed_projects
# Scopes
scope
:recent
,
->
{
reorder
(
id: :desc
)
}
...
...
@@ -389,4 +390,8 @@ class Event < ActiveRecord::Base
Project
.
unscoped
.
where
(
id:
project_id
)
.
update_all
(
last_repository_updated_at:
created_at
)
end
def
track_user_contributed_projects
UserContributedProjects
.
track
(
self
)
end
end
app/models/user_contributed_projects.rb
0 → 100644
View file @
ebcf3c73
class
UserContributedProjects
<
ActiveRecord
::
Base
belongs_to
:user
belongs_to
:project
validates
:project
,
presence:
true
validates
:user
,
presence:
true
def
self
.
track
(
event
)
find_or_create_by!
(
project:
event
.
project
,
user:
event
.
author
)
rescue
ActiveRecord
::
RecordNotUnique
retry
end
end
spec/models/event_spec.rb
View file @
ebcf3c73
...
...
@@ -49,6 +49,14 @@ describe Event do
end
end
end
describe
'after_create :track_user_contributed_projects'
do
it
'passes event to UserContributedProjects.track'
do
event
=
build
(
:push_event
,
project:
project
,
author:
project
.
owner
)
expect
(
UserContributedProjects
).
to
receive
(
:track
).
with
(
event
)
event
.
save
end
end
end
describe
"Push event"
do
...
...
spec/models/user_contributed_projects_spec.rb
0 → 100644
View file @
ebcf3c73
require
'spec_helper'
describe
UserContributedProjects
do
describe
'.track'
do
subject
{
described_class
.
track
(
event
)
}
let
(
:event
)
{
build
(
:event
)
}
Event
::
ACTIONS
.
each
do
|
action
|
context
"for all actions (event types)"
do
let
(
:event
)
{
build
(
:event
,
action:
action
)
}
it
'creates a record'
do
expect
{
subject
}.
to
change
{
UserContributedProjects
.
count
}.
from
(
0
).
to
(
1
)
end
end
end
it
'sets project accordingly'
do
expect
(
subject
.
project
).
to
eq
(
event
.
project
)
end
it
'sets user accordingly'
do
expect
(
subject
.
user
).
to
eq
(
event
.
author
)
end
it
'only creates a record once per user/project'
do
expect
do
subject
described_class
.
track
(
event
)
end
.
to
change
{
UserContributedProjects
.
count
}.
from
(
0
).
to
(
1
)
end
end
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
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