summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/merge_requests/diffs_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/projects/merge_requests/diffs_controller_spec.rb')
-rw-r--r--spec/controllers/projects/merge_requests/diffs_controller_spec.rb139
1 files changed, 95 insertions, 44 deletions
diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb
index 8f4f85b55bb..d7e790360e3 100644
--- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb
@@ -5,6 +5,19 @@ require 'spec_helper'
describe Projects::MergeRequests::DiffsController do
include ProjectForksHelper
+ shared_examples '404 for unexistent diffable' do
+ context 'when diffable does not exists' do
+ it 'returns 404' do
+ unexistent_diff_id = 9999
+
+ go(diff_id: unexistent_diff_id)
+
+ expect(MergeRequestDiff.find_by(id: unexistent_diff_id)).to be_nil
+ expect(response).to have_gitlab_http_status(404)
+ end
+ end
+ end
+
shared_examples 'forked project with submodules' do
render_views
@@ -137,6 +150,8 @@ describe Projects::MergeRequests::DiffsController do
get :diffs_metadata, params: params.merge(extra_params)
end
+ it_behaves_like '404 for unexistent diffable'
+
context 'when not authorized' do
let(:another_user) { create(:user) }
@@ -159,14 +174,6 @@ describe Projects::MergeRequests::DiffsController do
end
end
- context 'when diffable does not exists' do
- it 'returns 404' do
- go(diff_id: 9999)
-
- expect(response).to have_gitlab_http_status(404)
- end
- end
-
context 'with valid diff_id' do
it 'returns success' do
go(diff_id: merge_request.merge_request_diff.id)
@@ -328,17 +335,53 @@ describe Projects::MergeRequests::DiffsController do
end
describe 'GET diffs_batch' do
+ shared_examples_for 'serializes diffs with expected arguments' do
+ it 'serializes paginated merge request diff collection' do
+ expect_next_instance_of(PaginatedDiffSerializer) do |instance|
+ expect(instance).to receive(:represent)
+ .with(an_instance_of(collection), expected_options)
+ .and_call_original
+ end
+
+ subject
+ end
+ end
+
+ shared_examples_for 'successful request' do
+ it 'returns success' do
+ subject
+
+ expect(response).to have_gitlab_http_status(200)
+ end
+ end
+
+ def collection_arguments(pagination_data = {})
+ {
+ merge_request: merge_request,
+ diff_view: :inline,
+ pagination_data: {
+ current_page: nil,
+ next_page: nil,
+ total_pages: nil
+ }.merge(pagination_data)
+ }
+ end
+
def go(extra_params = {})
params = {
namespace_id: project.namespace.to_param,
project_id: project,
id: merge_request.iid,
+ page: 1,
+ per_page: 20,
format: 'json'
}
get :diffs_batch, params: params.merge(extra_params)
end
+ it_behaves_like '404 for unexistent diffable'
+
context 'when feature is disabled' do
before do
stub_feature_flags(diffs_batch_load: false)
@@ -365,52 +408,60 @@ describe Projects::MergeRequests::DiffsController do
end
end
- context 'with default params' do
- let(:expected_options) do
- {
- merge_request: merge_request,
- diff_view: :inline,
- pagination_data: {
- current_page: 1,
- next_page: nil,
- total_pages: 1
- }
- }
+ context 'with valid diff_id' do
+ subject { go(diff_id: merge_request.merge_request_diff.id) }
+
+ it_behaves_like 'serializes diffs with expected arguments' do
+ let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
+ let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1) }
end
- it 'serializes paginated merge request diff collection' do
- expect_next_instance_of(PaginatedDiffSerializer) do |instance|
- expect(instance).to receive(:represent)
- .with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiffBatch), expected_options)
- .and_call_original
- end
+ it_behaves_like 'successful request'
+ end
- go
+ context 'with commit_id param' do
+ subject { go(commit_id: merge_request.diff_head_sha) }
+
+ it_behaves_like 'serializes diffs with expected arguments' do
+ let(:collection) { Gitlab::Diff::FileCollection::Commit }
+ let(:expected_options) { collection_arguments }
end
end
- context 'with smaller diff batch params' do
- let(:expected_options) do
- {
- merge_request: merge_request,
- diff_view: :inline,
- pagination_data: {
- current_page: 2,
- next_page: 3,
- total_pages: 4
- }
- }
+ context 'with diff_id and start_sha params' do
+ subject do
+ go(diff_id: merge_request.merge_request_diff.id,
+ start_sha: merge_request.merge_request_diff.start_commit_sha)
end
- it 'serializes paginated merge request diff collection' do
- expect_next_instance_of(PaginatedDiffSerializer) do |instance|
- expect(instance).to receive(:represent)
- .with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiffBatch), expected_options)
- .and_call_original
- end
+ it_behaves_like 'serializes diffs with expected arguments' do
+ let(:collection) { Gitlab::Diff::FileCollection::Compare }
+ let(:expected_options) { collection_arguments }
+ end
+
+ it_behaves_like 'successful request'
+ end
- go(page: 2, per_page: 5)
+ context 'with default params' do
+ subject { go }
+
+ it_behaves_like 'serializes diffs with expected arguments' do
+ let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
+ let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1) }
+ end
+
+ it_behaves_like 'successful request'
+ end
+
+ context 'with smaller diff batch params' do
+ subject { go(page: 2, per_page: 5) }
+
+ it_behaves_like 'serializes diffs with expected arguments' do
+ let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
+ let(:expected_options) { collection_arguments(current_page: 2, next_page: 3, total_pages: 4) }
end
+
+ it_behaves_like 'successful request'
end
it_behaves_like 'forked project with submodules'