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
20688cdf
Commit
20688cdf
authored
Jun 29, 2016
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be explicit which project and user ID are memoized
parent
8c29b0b0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
app/helpers/notes_helper.rb
app/helpers/notes_helper.rb
+6
-4
spec/helpers/notes_helper_spec.rb
spec/helpers/notes_helper_spec.rb
+14
-0
No files found.
app/helpers/notes_helper.rb
View file @
20688cdf
...
@@ -71,10 +71,12 @@ module NotesHelper
...
@@ -71,10 +71,12 @@ module NotesHelper
end
end
def
note_max_access_for_user
(
note
)
def
note_max_access_for_user
(
note
)
user_id
=
note
.
author
.
id
@max_access_by_user_id
||=
Hash
.
new
do
|
hash
,
key
|
project
=
note
.
project
project
=
key
[
:project
]
@max_access_by_user_id
||=
Hash
.
new
{
|
hash
,
key
|
hash
[
key
]
=
project
.
team
.
human_max_access
(
key
)
}
hash
[
key
]
=
project
.
team
.
human_max_access
(
key
[
:user_id
])
end
@max_access_by_user_id
[
user_id
]
full_key
=
{
project:
note
.
project
,
user_id:
note
.
author_id
}
@max_access_by_user_id
[
full_key
]
end
end
end
end
spec/helpers/notes_helper_spec.rb
View file @
20688cdf
...
@@ -22,11 +22,25 @@ describe NotesHelper do
...
@@ -22,11 +22,25 @@ describe NotesHelper do
end
end
it
'return human access levels'
do
it
'return human access levels'
do
original_method
=
project
.
team
.
method
(
:human_max_access
)
expect_any_instance_of
(
ProjectTeam
).
to
receive
(
:human_max_access
).
exactly
(
3
).
times
do
|*
args
|
original_method
.
call
(
args
[
1
])
end
expect
(
helper
.
note_max_access_for_user
(
owner_note
)).
to
eq
(
'Owner'
)
expect
(
helper
.
note_max_access_for_user
(
owner_note
)).
to
eq
(
'Owner'
)
expect
(
helper
.
note_max_access_for_user
(
master_note
)).
to
eq
(
'Master'
)
expect
(
helper
.
note_max_access_for_user
(
master_note
)).
to
eq
(
'Master'
)
expect
(
helper
.
note_max_access_for_user
(
reporter_note
)).
to
eq
(
'Reporter'
)
expect
(
helper
.
note_max_access_for_user
(
reporter_note
)).
to
eq
(
'Reporter'
)
# Call it again to ensure value is cached
# Call it again to ensure value is cached
expect
(
helper
.
note_max_access_for_user
(
owner_note
)).
to
eq
(
'Owner'
)
expect
(
helper
.
note_max_access_for_user
(
owner_note
)).
to
eq
(
'Owner'
)
end
end
it
'handles access in different projects'
do
second_project
=
create
(
:empty_project
)
second_project
.
team
<<
[
master
,
:reporter
]
other_note
=
create
(
:note
,
author:
master
,
project:
second_project
)
expect
(
helper
.
note_max_access_for_user
(
master_note
)).
to
eq
(
'Master'
)
expect
(
helper
.
note_max_access_for_user
(
other_note
)).
to
eq
(
'Reporter'
)
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