diff options
Diffstat (limited to 'spec/controllers/projects/blob_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/blob_controller_spec.rb | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index 00a7df6ccc8..4dcb7dc6c87 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -55,6 +55,25 @@ describe Projects::BlobController do expect(json_response).to have_key 'raw_path' end end + + context "with viewer=none" do + let(:id) { 'master/README.md' } + + before do + get(:show, + namespace_id: project.namespace, + project_id: project, + id: id, + format: :json, + viewer: 'none') + end + + it do + expect(response).to be_ok + expect(json_response).not_to have_key 'html' + expect(json_response).to have_key 'raw_path' + end + end end context 'with tree path' do @@ -103,10 +122,64 @@ describe Projects::BlobController do end context 'when essential params are present' do - it 'renders the diff content' do - do_get(since: 1, to: 5, offset: 10) + context 'when rendering for commit' do + it 'renders the diff content' do + do_get(since: 1, to: 5, offset: 10) + + expect(response.body).to be_present + end + end + + context 'when rendering for merge request' do + it 'renders diff context lines Gitlab::Diff::Line array' do + do_get(since: 1, to: 5, offset: 10, from_merge_request: true) + + lines = JSON.parse(response.body) + + expect(lines.first).to have_key('type') + expect(lines.first).to have_key('rich_text') + expect(lines.first).to have_key('rich_text') + end + + context 'when rendering match lines' do + it 'adds top match line when "since" is less than 1' do + do_get(since: 5, to: 10, offset: 10, from_merge_request: true) + + match_line = JSON.parse(response.body).first + + expect(match_line['type']).to eq('match') + expect(match_line['meta_data']).to have_key('old_pos') + expect(match_line['meta_data']).to have_key('new_pos') + end + + it 'does not add top match line when when "since" is equal 1' do + do_get(since: 1, to: 10, offset: 10, from_merge_request: true) - expect(response.body).to be_present + match_line = JSON.parse(response.body).first + + expect(match_line['type']).to eq('context') + end + + it 'adds bottom match line when "t"o is less than blob size' do + do_get(since: 1, to: 5, offset: 10, from_merge_request: true, bottom: true) + + match_line = JSON.parse(response.body).last + + expect(match_line['type']).to eq('match') + expect(match_line['meta_data']).to have_key('old_pos') + expect(match_line['meta_data']).to have_key('new_pos') + end + + it 'does not add bottom match line when "to" is less than blob size' do + commit_id = project.repository.commit('master').id + blob = project.repository.blob_at(commit_id, 'CHANGELOG') + do_get(since: 1, to: blob.lines.count, offset: 10, from_merge_request: true, bottom: true) + + match_line = JSON.parse(response.body).last + + expect(match_line['type']).to eq('context') + end + end end end end |