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
Boxiang Sun
gitlab-ce
Commits
8dde0301
Commit
8dde0301
authored
Feb 26, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address rubocop offenses.
parent
87010983
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
34 deletions
+35
-34
app/models/user_contributed_projects.rb
app/models/user_contributed_projects.rb
+30
-28
spec/models/user_contributed_projects_spec.rb
spec/models/user_contributed_projects_spec.rb
+5
-6
No files found.
app/models/user_contributed_projects.rb
View file @
8dde0301
...
@@ -7,7 +7,8 @@ class UserContributedProjects < ActiveRecord::Base
...
@@ -7,7 +7,8 @@ class UserContributedProjects < ActiveRecord::Base
CACHE_EXPIRY_TIME
=
1
.
day
CACHE_EXPIRY_TIME
=
1
.
day
def
self
.
track
(
event
)
class
<<
self
def
track
(
event
)
# For events without a project, we simply don't care.
# For events without a project, we simply don't care.
# An example of this is the creation of a snippet (which
# An example of this is the creation of a snippet (which
# is not related to any project).
# is not related to any project).
...
@@ -36,8 +37,9 @@ class UserContributedProjects < ActiveRecord::Base
...
@@ -36,8 +37,9 @@ class UserContributedProjects < ActiveRecord::Base
private
private
def
self
.
cached_exists?
(
project_id
:,
user_id
:,
&
block
)
def
cached_exists?
(
project_id
:,
user_id
:,
&
block
)
cache_key
=
"user_contributed_projects:
#{
project_id
}
:
#{
user_id
}
"
cache_key
=
"user_contributed_projects:
#{
project_id
}
:
#{
user_id
}
"
Rails
.
cache
.
fetch
(
cache_key
,
expires_in:
CACHE_EXPIRY_TIME
,
&
block
)
Rails
.
cache
.
fetch
(
cache_key
,
expires_in:
CACHE_EXPIRY_TIME
,
&
block
)
end
end
end
end
end
spec/models/user_contributed_projects_spec.rb
View file @
8dde0301
require
'spec_helper'
require
'spec_helper'
describe
UserContributedProjects
do
describe
UserContributedProjects
do
describe
'.track'
do
describe
'.track'
do
subject
{
described_class
.
track
(
event
)
}
subject
{
described_class
.
track
(
event
)
}
let
(
:event
)
{
build
(
:event
)
}
let
(
:event
)
{
build
(
:event
)
}
...
@@ -10,33 +9,33 @@ describe UserContributedProjects do
...
@@ -10,33 +9,33 @@ describe UserContributedProjects do
context
"for all actions (event types)"
do
context
"for all actions (event types)"
do
let
(
:event
)
{
build
(
:event
,
action:
action
)
}
let
(
:event
)
{
build
(
:event
,
action:
action
)
}
it
'creates a record'
do
it
'creates a record'
do
expect
{
subject
}.
to
change
{
UserContributedProject
s
.
count
}.
from
(
0
).
to
(
1
)
expect
{
subject
}.
to
change
{
described_clas
s
.
count
}.
from
(
0
).
to
(
1
)
end
end
end
end
end
end
it
'sets project accordingly'
do
it
'sets project accordingly'
do
subject
subject
expect
(
UserContributedProject
s
.
first
.
project
).
to
eq
(
event
.
project
)
expect
(
described_clas
s
.
first
.
project
).
to
eq
(
event
.
project
)
end
end
it
'sets user accordingly'
do
it
'sets user accordingly'
do
subject
subject
expect
(
UserContributedProject
s
.
first
.
user
).
to
eq
(
event
.
author
)
expect
(
described_clas
s
.
first
.
user
).
to
eq
(
event
.
author
)
end
end
it
'only creates a record once per user/project'
do
it
'only creates a record once per user/project'
do
expect
do
expect
do
subject
subject
described_class
.
track
(
event
)
described_class
.
track
(
event
)
end
.
to
change
{
UserContributedProject
s
.
count
}.
from
(
0
).
to
(
1
)
end
.
to
change
{
described_clas
s
.
count
}.
from
(
0
).
to
(
1
)
end
end
describe
'with an event without a project'
do
describe
'with an event without a project'
do
let
(
:event
)
{
build
(
:event
,
project:
nil
)
}
let
(
:event
)
{
build
(
:event
,
project:
nil
)
}
it
'ignores the event'
do
it
'ignores the event'
do
expect
{
subject
}.
not_to
change
{
UserContributedProject
s
.
count
}
expect
{
subject
}.
not_to
change
{
described_clas
s
.
count
}
end
end
end
end
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