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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
66ea7846
Commit
66ea7846
authored
Feb 03, 2021
by
Robert May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Memoize the fork suggestion button partial
parent
ca6cef2e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletion
+34
-1
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+9
-0
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+1
-1
spec/helpers/diff_helper_spec.rb
spec/helpers/diff_helper_spec.rb
+24
-0
No files found.
app/helpers/diff_helper.rb
View file @
66ea7846
...
...
@@ -214,6 +214,15 @@ module DiffHelper
)
end
# As the fork suggestion button is identical every time, we cache it for a full page load
def
render_fork_suggestion
return
unless
current_user
strong_memoize
(
:fork_suggestion
)
do
render
partial:
"projects/fork_suggestion"
end
end
private
def
diff_btn
(
title
,
name
,
selected
)
...
...
app/views/projects/diffs/_file.html.haml
View file @
66ea7846
...
...
@@ -30,6 +30,6 @@
=
view_file_button
(
diff_file
.
content_sha
,
diff_file
.
file_path
,
project
)
=
view_on_environment_button
(
diff_file
.
content_sha
,
diff_file
.
file_path
,
environment
)
if
environment
=
render
'projects/fork_suggestion'
=
render
_fork_suggestion
=
render
'projects/diffs/content'
,
diff_file:
diff_file
spec/helpers/diff_helper_spec.rb
View file @
66ea7846
...
...
@@ -378,4 +378,28 @@ RSpec.describe DiffHelper do
expect
(
subject
).
to
match
(
/foo\/bar\/-\/commit\/
#{
commit
.
sha
}
\/diff_for_path/
)
end
end
describe
"#render_fork_suggestion"
do
subject
{
helper
.
render_fork_suggestion
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
current_user
)
end
context
"user signed in"
do
let
(
:current_user
)
{
build
(
:user
)
}
it
"renders the partial"
do
expect
(
helper
).
to
receive
(
:render
).
with
(
partial:
"projects/fork_suggestion"
).
exactly
(
:once
)
5
.
times
{
subject
}
end
end
context
"guest"
do
let
(
:current_user
)
{
nil
}
it
{
is_expected
.
to
be_nil
}
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