From 802bf6d012bf8edb8ea35429bd8b8cc4fe8e9bf1 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Tue, 16 Feb 2016 21:01:14 -0200 Subject: Create a pending task when an MR is assigned to someone --- .../services/merge_requests/create_service_spec.rb | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'spec/services/merge_requests/create_service_spec.rb') diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index be8f1676eeb..2e3c9f88369 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe MergeRequests::CreateService, services: true do let(:project) { create(:project) } let(:user) { create(:user) } + let(:assignee) { create(:user) } describe :execute do context 'valid params' do @@ -14,10 +15,12 @@ describe MergeRequests::CreateService, services: true do target_branch: 'master' } end + let(:service) { MergeRequests::CreateService.new(project, user, opts) } before do project.team << [user, :master] + project.team << [assignee, :developer] allow(service).to receive(:execute_hooks) @merge_request = service.execute @@ -25,10 +28,47 @@ describe MergeRequests::CreateService, services: true do it { expect(@merge_request).to be_valid } it { expect(@merge_request.title).to eq('Awesome merge_request') } + it { expect(@merge_request.assignee).to be_nil } it 'should execute hooks with default action' do expect(service).to have_received(:execute_hooks).with(@merge_request) end + + it 'does not creates a pending task' do + attributes = { + project: project, + target: @merge_request + } + + expect(Task.where(attributes).count).to be_zero + end + + context 'when merge request is assigned to someone' do + let(:opts) do + { + title: 'Awesome merge_request', + description: 'please fix', + source_branch: 'feature', + target_branch: 'master', + assignee: assignee + } + end + + it { expect(@merge_request.assignee).to eq assignee } + + it 'creates a pending task for new assignee' do + attributes = { + project: project, + author: user, + user: assignee, + target: @merge_request, + action: Task::ASSIGNED, + state: :pending + } + + expect(Task.where(attributes).count).to eq 1 + end + end end end end -- cgit v1.2.1