From f9b4d5efbde0bf3b6b1822177d47199ad2f02fbd Mon Sep 17 00:00:00 2001
From: Nick Thomas <nick@gitlab.com>
Date: Tue, 9 Apr 2019 20:30:52 +0100
Subject: [PATCH] Fix MR assignees for push options

With multiple MR assignees, `merge_request.assignee_id` is always nil,
and `merge_request.assignee_ids` isn't in `merge_request.attributes`.
So the existing code doesn't set assignees in the created MR.

This fix gets all the tests passing, but we should also check that no
other associations in the MergeRequest need similar fixups.
---
 app/services/merge_requests/push_options_handler_service.rb   | 4 ++--
 .../merge_requests/push_options_handler_service_spec.rb       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/services/merge_requests/push_options_handler_service.rb b/app/services/merge_requests/push_options_handler_service.rb
index d92eb0a68c3..a24163331e8 100644
--- a/app/services/merge_requests/push_options_handler_service.rb
+++ b/app/services/merge_requests/push_options_handler_service.rb
@@ -100,7 +100,7 @@ module MergeRequests
         merge_request = ::MergeRequests::CreateService.new(
           project,
           current_user,
-          merge_request.attributes
+          merge_request.attributes.merge(assignees: merge_request.assignees)
         ).execute
       end
 
@@ -119,7 +119,7 @@ module MergeRequests
 
     def create_params(branch)
       params = {
-        assignee: current_user,
+        assignees: [current_user],
         source_branch: branch,
         source_project: project,
         target_branch: push_options[:target] || target_project.default_branch,
diff --git a/spec/services/merge_requests/push_options_handler_service_spec.rb b/spec/services/merge_requests/push_options_handler_service_spec.rb
index 686b4b49f24..f7a39bb42d5 100644
--- a/spec/services/merge_requests/push_options_handler_service_spec.rb
+++ b/spec/services/merge_requests/push_options_handler_service_spec.rb
@@ -38,7 +38,7 @@ describe MergeRequests::PushOptionsHandlerService do
     it 'assigns the MR to the user' do
       service.execute
 
-      expect(last_mr.assignee).to eq(user)
+      expect(last_mr.assignees).to contain_exactly(user)
     end
 
     context 'when project has been forked' do
-- 
2.30.9