diff options
author | Felipe Artur <fcardozo@gitlab.com> | 2018-06-21 15:22:40 +0300 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-06-21 15:22:40 +0300 |
commit | 3e66795ef1ff1228906239763910b051d8afcc37 (patch) | |
tree | df6424d9ec008f5d1da455f8465681b371c4a11e /spec/controllers/projects/blob_controller_spec.rb | |
parent | 14e35ac9b19d358d84e0cfd167f74036937285b6 (diff) |
Changes tab VUE refactoring
Diffstat (limited to 'spec/controllers/projects/blob_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/blob_controller_spec.rb | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index 9e696e9cb29..4dcb7dc6c87 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -122,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 + 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) + + 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 |