From b6b26692ea44cfeab7e8fd64b7df60852850fce2 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 28 Jun 2016 17:25:32 +0100 Subject: Collapse large diffs by default When rendering a list of diff files, skip those where the diff is over 10 KB and provide an endpoint to render individually instead. --- .../projects/compare_controller_spec.rb | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'spec/controllers/projects/compare_controller_spec.rb') diff --git a/spec/controllers/projects/compare_controller_spec.rb b/spec/controllers/projects/compare_controller_spec.rb index 4018dac95a2..40a068a87bb 100644 --- a/spec/controllers/projects/compare_controller_spec.rb +++ b/spec/controllers/projects/compare_controller_spec.rb @@ -64,4 +64,73 @@ describe Projects::CompareController do expect(assigns(:commits)).to eq(nil) end end + + describe 'GET #diff_for_path' do + def diff_for_path(extra_params = {}) + params = { + namespace_id: project.namespace.to_param, + project_id: project.to_param + } + + get :diff_for_path, params.merge(extra_params) + end + + let(:existing_path) { 'files/ruby/feature.rb' } + + context 'when the from and to refs exist' do + context 'when the user has access to the project' do + context 'when the path exists in the diff' do + it 'disables diff notes' do + diff_for_path(from: ref_from, to: ref_to, path: existing_path) + + expect(assigns(:diff_notes_disabled)).to be_truthy + end + + it 'only renders the diffs for the path given' do + expect(controller).to receive(:render_diff_for_path).and_wrap_original do |meth, diffs, diff_refs, project| + expect(diffs.map(&:new_path)).to contain_exactly(existing_path) + meth.call(diffs, diff_refs, project) + end + + diff_for_path(from: ref_from, to: ref_to, path: existing_path) + end + end + + context 'when the path does not exist in the diff' do + before { diff_for_path(from: ref_from, to: ref_to, path: existing_path.succ) } + + it 'returns a 404' do + expect(response).to have_http_status(404) + end + end + end + + context 'when the user does not have access to the project' do + before do + project.team.truncate + diff_for_path(from: ref_from, to: ref_to, path: existing_path) + end + + it 'returns a 404' do + expect(response).to have_http_status(404) + end + end + end + + context 'when the from ref does not exist' do + before { diff_for_path(from: ref_from.succ, to: ref_to, path: existing_path) } + + it 'returns a 404' do + expect(response).to have_http_status(404) + end + end + + context 'when the to ref does not exist' do + before { diff_for_path(from: ref_from, to: ref_to.succ, path: existing_path) } + + it 'returns a 404' do + expect(response).to have_http_status(404) + end + end + end end -- cgit v1.2.1 From e462e122784f40550c53224af5a58b201ed1fd8f Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 8 Jul 2016 18:11:47 +0100 Subject: Tidy up spec action names --- spec/controllers/projects/compare_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/projects/compare_controller_spec.rb') diff --git a/spec/controllers/projects/compare_controller_spec.rb b/spec/controllers/projects/compare_controller_spec.rb index 40a068a87bb..1dd144a7b72 100644 --- a/spec/controllers/projects/compare_controller_spec.rb +++ b/spec/controllers/projects/compare_controller_spec.rb @@ -65,7 +65,7 @@ describe Projects::CompareController do end end - describe 'GET #diff_for_path' do + describe 'GET diff_for_path' do def diff_for_path(extra_params = {}) params = { namespace_id: project.namespace.to_param, -- cgit v1.2.1 From 5266ae87c43a6760600e397257f9791d950dbe15 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 8 Jul 2016 22:50:06 +0100 Subject: Support renames in diff_for_path actions --- spec/controllers/projects/compare_controller_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/controllers/projects/compare_controller_spec.rb') diff --git a/spec/controllers/projects/compare_controller_spec.rb b/spec/controllers/projects/compare_controller_spec.rb index 1dd144a7b72..4058d5e2453 100644 --- a/spec/controllers/projects/compare_controller_spec.rb +++ b/spec/controllers/projects/compare_controller_spec.rb @@ -81,7 +81,7 @@ describe Projects::CompareController do context 'when the user has access to the project' do context 'when the path exists in the diff' do it 'disables diff notes' do - diff_for_path(from: ref_from, to: ref_to, path: existing_path) + diff_for_path(from: ref_from, to: ref_to, old_path: existing_path, new_path: existing_path) expect(assigns(:diff_notes_disabled)).to be_truthy end @@ -92,12 +92,12 @@ describe Projects::CompareController do meth.call(diffs, diff_refs, project) end - diff_for_path(from: ref_from, to: ref_to, path: existing_path) + diff_for_path(from: ref_from, to: ref_to, old_path: existing_path, new_path: existing_path) end end context 'when the path does not exist in the diff' do - before { diff_for_path(from: ref_from, to: ref_to, path: existing_path.succ) } + before { diff_for_path(from: ref_from, to: ref_to, old_path: existing_path.succ, new_path: existing_path.succ) } it 'returns a 404' do expect(response).to have_http_status(404) @@ -108,7 +108,7 @@ describe Projects::CompareController do context 'when the user does not have access to the project' do before do project.team.truncate - diff_for_path(from: ref_from, to: ref_to, path: existing_path) + diff_for_path(from: ref_from, to: ref_to, old_path: existing_path, new_path: existing_path) end it 'returns a 404' do @@ -118,7 +118,7 @@ describe Projects::CompareController do end context 'when the from ref does not exist' do - before { diff_for_path(from: ref_from.succ, to: ref_to, path: existing_path) } + before { diff_for_path(from: ref_from.succ, to: ref_to, old_path: existing_path, new_path: existing_path) } it 'returns a 404' do expect(response).to have_http_status(404) @@ -126,7 +126,7 @@ describe Projects::CompareController do end context 'when the to ref does not exist' do - before { diff_for_path(from: ref_from, to: ref_to.succ, path: existing_path) } + before { diff_for_path(from: ref_from, to: ref_to.succ, old_path: existing_path, new_path: existing_path) } it 'returns a 404' do expect(response).to have_http_status(404) -- cgit v1.2.1