debian-mirror-gitlab/spec/services/merge_requests/create_service_spec.rb

79 lines
2.2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe MergeRequests::CreateService, services: true do
2014-09-02 18:07:02 +05:30
let(:project) { create(:project) }
let(:user) { create(:user) }
2016-04-02 18:10:28 +05:30
let(:assignee) { create(:user) }
2014-09-02 18:07:02 +05:30
describe :execute do
2015-04-26 12:48:37 +05:30
context 'valid params' do
let(:opts) do
{
2014-09-02 18:07:02 +05:30
title: 'Awesome merge_request',
description: 'please fix',
2015-09-25 12:07:36 +05:30
source_branch: 'feature',
2016-06-02 11:05:42 +05:30
target_branch: 'master',
force_remove_source_branch: '1'
2014-09-02 18:07:02 +05:30
}
2015-04-26 12:48:37 +05:30
end
2016-04-02 18:10:28 +05:30
2015-04-26 12:48:37 +05:30
let(:service) { MergeRequests::CreateService.new(project, user, opts) }
before do
project.team << [user, :master]
2016-04-02 18:10:28 +05:30
project.team << [assignee, :developer]
2015-04-26 12:48:37 +05:30
allow(service).to receive(:execute_hooks)
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
@merge_request = service.execute
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
it { expect(@merge_request).to be_valid }
it { expect(@merge_request.title).to eq('Awesome merge_request') }
2016-04-02 18:10:28 +05:30
it { expect(@merge_request.assignee).to be_nil }
2016-06-02 11:05:42 +05:30
it { expect(@merge_request.merge_params['force_remove_source_branch']).to eq('1') }
2015-04-26 12:48:37 +05:30
it 'should execute hooks with default action' do
expect(service).to have_received(:execute_hooks).with(@merge_request)
end
2016-04-02 18:10:28 +05:30
it 'does not creates todos' do
attributes = {
project: project,
target_id: @merge_request.id,
target_type: @merge_request.class.name
}
expect(Todo.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 todo for new assignee' do
attributes = {
project: project,
author: user,
user: assignee,
target_id: @merge_request.id,
target_type: @merge_request.class.name,
action: Todo::ASSIGNED,
state: :pending
}
expect(Todo.where(attributes).count).to eq 1
end
end
2014-09-02 18:07:02 +05:30
end
end
end