2015-01-17 19:34:34 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe MergeRequests::ReopenService 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
|
2017-05-26 09:29:42 -04:00
|
|
|
it_behaves_like 'cache counters invalidator'
|
|
|
|
|
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 }
|
2017-07-19 10:03:50 -04:00
|
|
|
it { expect(merge_request).to be_opened }
|
2015-01-17 19:34:34 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'executes hooks with reopen action' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(service).to have_received(:execute_hooks)
|
|
|
|
.with(merge_request, 'reopen')
|
2015-01-17 19:34:34 -05:00
|
|
|
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
|
2016-11-23 01:55:23 -05:00
|
|
|
expect(note.note).to include 'reopened'
|
2015-01-17 19:34:34 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-09 11:51:40 -04:00
|
|
|
|
2017-08-17 11:21:25 -04:00
|
|
|
it 'refreshes the number of open merge requests for a valid MR' do
|
|
|
|
service = described_class.new(project, user, {})
|
|
|
|
|
|
|
|
expect { service.execute(merge_request) }
|
|
|
|
.to change { project.open_merge_requests_count }.from(0).to(1)
|
|
|
|
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
|