diff options
author | Igor <idrozdov@gitlab.com> | 2019-08-01 19:51:14 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2019-08-01 19:51:14 +0300 |
commit | f74b33cf6e5ee415417d9f2ee255f97ab6fcf7ad (patch) | |
tree | e05c4aaaf46e2f8d080c49f5a3575f32d962bdc8 /spec | |
parent | 5b38fced90e81241b4266bac78c8e53a432f5144 (diff) |
Add can_merge option to autocomplete response
It's used only if merge_request_iid param is provided
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/autocomplete_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/serializers/user_serializer_spec.rb | 30 |
2 files changed, 44 insertions, 0 deletions
diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb index eaa5d6cd073..6cdd61e7abd 100644 --- a/spec/controllers/autocomplete_controller_spec.rb +++ b/spec/controllers/autocomplete_controller_spec.rb @@ -222,6 +222,20 @@ describe AutocompleteController do expect(response_user_ids).to contain_exactly(non_member.id) end end + + context 'merge_request_iid parameter included' do + before do + sign_in(user) + end + + it 'includes can_merge option to users' do + merge_request = create(:merge_request, source_project: project) + + get(:users, params: { merge_request_iid: merge_request.iid, project_id: project.id }) + + expect(json_response.first).to have_key('can_merge') + end + end end context 'GET projects' do diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb new file mode 100644 index 00000000000..2e4a8c644fe --- /dev/null +++ b/spec/serializers/user_serializer_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe UserSerializer do + let(:user1) { create(:user) } + let(:user2) { create(:user) } + + context 'serializer with merge request context' do + let(:merge_request) { create(:merge_request) } + let(:project) { merge_request.project } + let(:serializer) { described_class.new(merge_request_iid: merge_request.iid) } + + before do + allow(project).to( + receive_message_chain(:merge_requests, :find_by_iid!) + .with(merge_request.iid).and_return(merge_request) + ) + + project.add_maintainer(user1) + end + + it 'returns a user with can_merge option' do + serialized_user1, serialized_user2 = serializer.represent([user1, user2], project: project).as_json + + expect(serialized_user1).to include("id" => user1.id, "can_merge" => true) + expect(serialized_user2).to include("id" => user2.id, "can_merge" => false) + end + end +end |