Commit 93f2d6ee authored by Robert May's avatar Robert May

Lower allocations in _collapsed partial

parent e8525082
......@@ -203,6 +203,17 @@ module DiffHelper
set_secure_cookie(:diff_view, params.delete(:view), type: CookiesHelper::COOKIE_TYPE_PERMANENT) if params[:view].present?
end
def collapsed_diff_url(diff_file)
url_for(
safe_params.merge(
action: :diff_for_path,
old_path: diff_file.old_path,
new_path: diff_file.new_path,
file_identifier: diff_file.file_identifier
)
)
end
private
def diff_btn(title, name, selected)
......
- diff_file = viewer.diff_file
- url = url_for(safe_params.merge(action: :diff_for_path, old_path: diff_file.old_path, new_path: diff_file.new_path, file_identifier: diff_file.file_identifier))
.nothing-here-block.diff-collapsed{ data: { diff_for_path: url } }
.nothing-here-block.diff-collapsed{ data: { diff_for_path: collapsed_diff_url(viewer.diff_file) } }
= _("This diff is collapsed.")
%button.click-to-expand.btn.btn-link= _("Click to expand it.")
......@@ -358,4 +358,24 @@ RSpec.describe DiffHelper do
expect(diff_file_path_text(diff_file, max: 10)).to eq("...open.rb")
end
end
describe "#collapsed_diff_url" do
let(:params) do
{
controller: "projects/commit",
action: "show",
namespace_id: "foo",
project_id: "bar",
id: commit.sha
}
end
subject { helper.collapsed_diff_url(diff_file) }
it "returns a valid URL" do
allow(helper).to receive(:safe_params).and_return(params)
expect(subject).to match(/foo\/bar\/-\/commit\/#{commit.sha}\/diff_for_path/)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment