2015-01-17 19:34:34 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe MergeRequests::ReopenService, services: true do
|
2015-01-17 19:34:34 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
2016-08-09 11:51:40 -04:00
|
|
|
let(:guest) { create(:user) }
|
|
|
|
let(:merge_request) { create(:merge_request, :closed, assignee: user2) }
|
2015-01-17 19:34:34 -05:00
|
|
|
let(:project) { merge_request.project }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
project.team << [user2, :developer]
|
2016-08-09 11:51:40 -04:00
|
|
|
project.team << [guest, :guest]
|
2015-01-17 19:34:34 -05:00
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#execute' do
|
2015-01-17 19:34:34 -05:00
|
|
|
context 'valid params' do
|
2016-08-09 11:51:40 -04:00
|
|
|
let(:service) { described_class.new(project, user, {}) }
|
2015-01-17 19:34:34 -05:00
|
|
|
|
|
|
|
before do
|
2015-02-12 13:17:35 -05:00
|
|
|
allow(service).to receive(:execute_hooks)
|
2015-01-17 19:34:34 -05:00
|
|
|
|
2015-11-30 11:03:07 -05:00
|
|
|
perform_enqueued_jobs do
|
|
|
|
service.execute(merge_request)
|
|
|
|
end
|
2015-01-17 19:34:34 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(merge_request).to be_valid }
|
|
|
|
it { expect(merge_request).to be_reopened }
|
2015-01-17 19:34:34 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'executes hooks with reopen action' do
|
2015-01-17 19:34:34 -05:00
|
|
|
expect(service).to have_received(:execute_hooks).
|
|
|
|
with(merge_request, 'reopen')
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'sends email to user2 about reopen of merge_request' do
|
2015-01-17 19:34:34 -05:00
|
|
|
email = ActionMailer::Base.deliveries.last
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(email.to.first).to eq(user2.email)
|
|
|
|
expect(email.subject).to include(merge_request.title)
|
2015-01-17 19:34:34 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'creates system note about merge_request reopen' do
|
2015-01-17 19:34:34 -05:00
|
|
|
note = merge_request.notes.last
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(note.note).to include 'Status changed to reopened'
|
2015-01-17 19:34:34 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-09 11:51:40 -04:00
|
|
|
|
|
|
|
context 'current user is not authorized to reopen merge request' do
|
|
|
|
before do
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
@merge_request = described_class.new(project, guest).execute(merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not reopen the merge request' do
|
|
|
|
expect(@merge_request).to be_closed
|
|
|
|
end
|
|
|
|
end
|
2015-01-17 19:34:34 -05:00
|
|
|
end
|
|
|
|
end
|