diff options
author | Sean McGivern <sean@gitlab.com> | 2016-07-08 22:50:06 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-07-11 09:31:34 +0100 |
commit | 5266ae87c43a6760600e397257f9791d950dbe15 (patch) | |
tree | 83e840670b4c772020be590e5934586fe746df6e /spec | |
parent | e462e122784f40550c53224af5a58b201ed1fd8f (diff) | |
download | gitlab-ce-5266ae87c43a6760600e397257f9791d950dbe15.tar.gz |
Support renames in diff_for_path actions
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/commit_controller_spec.rb | 10 | ||||
-rw-r--r-- | spec/controllers/projects/compare_controller_spec.rb | 12 | ||||
-rw-r--r-- | spec/controllers/projects/merge_requests_controller_spec.rb | 24 | ||||
-rw-r--r-- | spec/features/merge_requests/expand_collapse_diffs_spec.rb | 37 | ||||
-rw-r--r-- | spec/models/merge_request_diff_spec.rb | 6 | ||||
-rw-r--r-- | spec/support/test_env.rb | 28 |
6 files changed, 75 insertions, 42 deletions
diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb index 472c4904919..3001d32e719 100644 --- a/spec/controllers/projects/commit_controller_spec.rb +++ b/spec/controllers/projects/commit_controller_spec.rb @@ -267,7 +267,7 @@ describe Projects::CommitController do context 'when the user has access to the project' do context 'when the path exists in the diff' do it 'enables diff notes' do - diff_for_path(id: commit.id, path: existing_path) + diff_for_path(id: commit.id, old_path: existing_path, new_path: existing_path) expect(assigns(:diff_notes_disabled)).to be_falsey expect(assigns(:comments_target)).to eq(noteable_type: 'Commit', @@ -280,12 +280,12 @@ describe Projects::CommitController do meth.call(diffs, diff_refs, project) end - diff_for_path(id: commit.id, path: existing_path) + diff_for_path(id: commit.id, 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(id: commit.id, path: existing_path.succ) } + before { diff_for_path(id: commit.id, old_path: existing_path.succ, new_path: existing_path.succ) } it 'returns a 404' do expect(response).to have_http_status(404) @@ -296,7 +296,7 @@ describe Projects::CommitController do context 'when the user does not have access to the project' do before do project.team.truncate - diff_for_path(id: commit.id, path: existing_path) + diff_for_path(id: commit.id, old_path: existing_path, new_path: existing_path) end it 'returns a 404' do @@ -306,7 +306,7 @@ describe Projects::CommitController do end context 'when the commit does not exist' do - before { diff_for_path(id: commit.id.succ, path: existing_path) } + before { diff_for_path(id: commit.id.succ, old_path: existing_path, new_path: existing_path) } it 'returns a 404' do expect(response).to have_http_status(404) 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) diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index ff160f51329..210085e3b1a 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -384,7 +384,7 @@ describe Projects::MergeRequestsController do context 'when the user can view the merge request' do context 'when the path exists in the diff' do it 'enables diff notes' do - diff_for_path(id: merge_request.iid, path: existing_path) + diff_for_path(id: merge_request.iid, old_path: existing_path, new_path: existing_path) expect(assigns(:diff_notes_disabled)).to be_falsey expect(assigns(:comments_target)).to eq(noteable_type: 'MergeRequest', @@ -397,12 +397,12 @@ describe Projects::MergeRequestsController do meth.call(diffs, diff_refs, project) end - diff_for_path(id: merge_request.iid, path: existing_path) + diff_for_path(id: merge_request.iid, 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(id: merge_request.iid, path: 'files/ruby/nopen.rb') } + before { diff_for_path(id: merge_request.iid, old_path: 'files/ruby/nopen.rb', new_path: 'files/ruby/nopen.rb') } it 'returns a 404' do expect(response).to have_http_status(404) @@ -413,7 +413,7 @@ describe Projects::MergeRequestsController do context 'when the user cannot view the merge request' do before do project.team.truncate - diff_for_path(id: merge_request.iid, path: existing_path) + diff_for_path(id: merge_request.iid, old_path: existing_path, new_path: existing_path) end it 'returns a 404' do @@ -423,7 +423,7 @@ describe Projects::MergeRequestsController do end context 'when the merge request does not exist' do - before { diff_for_path(id: merge_request.iid.succ, path: existing_path) } + before { diff_for_path(id: merge_request.iid.succ, old_path: existing_path, new_path: existing_path) } it 'returns a 404' do expect(response).to have_http_status(404) @@ -435,7 +435,7 @@ describe Projects::MergeRequestsController do before do other_project.team << [user, :master] - diff_for_path(id: merge_request.iid, path: existing_path, project_id: other_project.to_param) + diff_for_path(id: merge_request.iid, old_path: existing_path, new_path: existing_path, project_id: other_project.to_param) end it 'returns a 404' do @@ -449,7 +449,7 @@ describe Projects::MergeRequestsController do context 'when both branches are in the same project' do it 'disables diff notes' do - diff_for_path(path: existing_path, merge_request: { source_branch: 'feature', target_branch: 'master' }) + diff_for_path(old_path: existing_path, new_path: existing_path, merge_request: { source_branch: 'feature', target_branch: 'master' }) expect(assigns(:diff_notes_disabled)).to be_truthy end @@ -460,7 +460,7 @@ describe Projects::MergeRequestsController do meth.call(diffs, diff_refs, project) end - diff_for_path(path: existing_path, merge_request: { source_branch: 'feature', target_branch: 'master' }) + diff_for_path(old_path: existing_path, new_path: existing_path, merge_request: { source_branch: 'feature', target_branch: 'master' }) end end @@ -471,7 +471,7 @@ describe Projects::MergeRequestsController do context 'when the path exists in the diff' do it 'disables diff notes' do - diff_for_path(path: existing_path, merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' }) + diff_for_path(old_path: existing_path, new_path: existing_path, merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' }) expect(assigns(:diff_notes_disabled)).to be_truthy end @@ -482,12 +482,12 @@ describe Projects::MergeRequestsController do meth.call(diffs, diff_refs, project) end - diff_for_path(path: existing_path, merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' }) + diff_for_path(old_path: existing_path, new_path: existing_path, merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' }) end end context 'when the path does not exist in the diff' do - before { diff_for_path(path: 'files/ruby/nopen.rb', merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' }) } + before { diff_for_path(old_path: 'files/ruby/nopen.rb', new_path: 'files/ruby/nopen.rb', merge_request: { source_project: other_project, source_branch: 'feature', target_branch: 'master' }) } it 'returns a 404' do expect(response).to have_http_status(404) @@ -497,7 +497,7 @@ describe Projects::MergeRequestsController do end end - describe 'GET #commits' do + describe 'GET commits' do def go(format: 'html') get :commits, namespace_id: project.namespace.to_param, diff --git a/spec/features/merge_requests/expand_collapse_diffs_spec.rb b/spec/features/merge_requests/expand_collapse_diffs_spec.rb index f9c89c4ad96..7a05bb47979 100644 --- a/spec/features/merge_requests/expand_collapse_diffs_spec.rb +++ b/spec/features/merge_requests/expand_collapse_diffs_spec.rb @@ -5,7 +5,7 @@ feature 'Expand and collapse diffs', js: true, feature: true do before do login_as :admin - merge_request = create(:merge_request, source_branch: 'expand-collapse-diffs', target_branch: 'master') + merge_request = create(:merge_request, target_branch: 'expand-collapse-diffs-start', source_branch: 'expand-collapse-diffs') project = merge_request.source_project # Ensure that undiffable.md is in .gitattributes @@ -21,7 +21,12 @@ feature 'Expand and collapse diffs', js: true, feature: true do # Use define_method instead of let (which is memoized) so that this just works across a # reload. # - ['small_diff.md', 'large_diff.md', 'undiffable.md', 'too_large.md', 'too_large_image.jpg'].each do |file| + files = [ + 'small_diff.md', 'large_diff.md', 'large_diff_renamed.md', 'undiffable.md', + 'too_large.md', 'too_large_image.jpg' + ] + + files.each do |file| define_method(file.split('.').first) { file_container(file) } end @@ -31,11 +36,18 @@ feature 'Expand and collapse diffs', js: true, feature: true do expect(small_diff).not_to have_selector('.nothing-here-block') end - it 'collapses larges diffs by default' do + it 'collapses large diffs by default' do expect(large_diff).not_to have_selector('.code') expect(large_diff).to have_selector('.nothing-here-block') end + it 'collapses large diffs for renamed files by default' do + expect(large_diff_renamed).not_to have_selector('.code') + expect(large_diff_renamed).to have_selector('.nothing-here-block') + expect(large_diff_renamed).to have_selector('.file-title .deletion') + expect(large_diff_renamed).to have_selector('.file-title .addition') + end + it 'shows non-renderable diffs as such immediately, regardless of their size' do expect(undiffable).not_to have_selector('.code') expect(undiffable).to have_selector('.nothing-here-block') @@ -53,6 +65,25 @@ feature 'Expand and collapse diffs', js: true, feature: true do expect(too_large_image).to have_selector('.image') end + context 'expanding a diff for a renamed file' do + before do + large_diff_renamed.find('.nothing-here-block').click + wait_for_ajax + end + + it 'shows the old content' do + old_line = large_diff_renamed.find('.line_content.old') + + expect(old_line).to have_content('four copies') + end + + it 'shows the new content' do + new_line = large_diff_renamed.find('.line_content.new', match: :prefer_exact) + + expect(new_line).to have_content('six copies') + end + end + context 'expanding a large diff' do before do click_link('large_diff.md') diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index 3f5763b6408..9a637c94fbe 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -30,10 +30,10 @@ describe MergeRequestDiff, models: true do end context 'when the :paths option is set' do - let(:diffs) { mr_diff.diffs(paths: ['.gitignore', 'files/ruby/popen.rb', 'files/ruby/string.rb']) } + let(:diffs) { mr_diff.diffs(paths: ['files/ruby/popen.rb', 'files/ruby/popen.rb']) } - it 'only returns diffs that match the paths given' do - expect(diffs.map(&:new_path)).to contain_exactly('.gitignore', 'files/ruby/popen.rb') + it 'only returns diffs that match the (old path, new path) given' do + expect(diffs.map(&:new_path)).to contain_exactly('files/ruby/popen.rb') end it 'uses the diffs from the DB' do diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 6b99b0f24cb..311610c9911 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -5,19 +5,21 @@ module TestEnv # When developing the seed repository, comment out the branch you will modify. BRANCH_SHA = { - 'empty-branch' => '7efb185', - 'flatten-dir' => 'e56497b', - 'feature' => '0b4bc9a', - 'feature_conflict' => 'bb5206f', - 'fix' => '48f0be4', - 'improve/awesome' => '5937ac0', - 'markdown' => '0ed8c6c', - 'lfs' => 'be93687', - 'master' => '5937ac0', - "'test'" => 'e56497b', - 'orphaned-branch' => '45127a9', - 'binary-encoding' => '7b1cf43', - 'gitattributes' => '5a62481', + 'empty-branch' => '7efb185', + 'flatten-dir' => 'e56497b', + 'feature' => '0b4bc9a', + 'feature_conflict' => 'bb5206f', + 'fix' => '48f0be4', + 'improve/awesome' => '5937ac0', + 'markdown' => '0ed8c6c', + 'lfs' => 'be93687', + 'master' => '5937ac0', + "'test'" => 'e56497b', + 'orphaned-branch' => '45127a9', + 'binary-encoding' => '7b1cf43', + 'gitattributes' => '5a62481', + 'expand-collapse-diffs-start' => '65b04e4', + 'expand-collapse-diffs' => '865e6d5' } # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily |