2014-11-11 09:49:26 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MergeRequests::RefreshService do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:service) { MergeRequests::RefreshService }
|
|
|
|
|
|
|
|
describe :execute do
|
|
|
|
before do
|
|
|
|
@user = create(:user)
|
|
|
|
group = create(:group)
|
|
|
|
group.add_owner(@user)
|
|
|
|
|
|
|
|
@project = create(:project, namespace: group)
|
|
|
|
@fork_project = Projects::ForkService.new(@project, @user).execute
|
2015-06-23 01:24:39 -04:00
|
|
|
@merge_request = create(:merge_request,
|
|
|
|
source_project: @project,
|
2014-11-11 09:49:26 -05:00
|
|
|
source_branch: 'master',
|
|
|
|
target_branch: 'feature',
|
|
|
|
target_project: @project)
|
|
|
|
|
2015-06-23 01:24:39 -04:00
|
|
|
@fork_merge_request = create(:merge_request,
|
|
|
|
source_project: @fork_project,
|
2014-11-11 09:49:26 -05:00
|
|
|
source_branch: 'master',
|
|
|
|
target_branch: 'feature',
|
|
|
|
target_project: @project)
|
|
|
|
|
|
|
|
@commits = @merge_request.commits
|
|
|
|
|
|
|
|
@oldrev = @commits.last.id
|
|
|
|
@newrev = @commits.first.id
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'push to origin repo source branch' do
|
2015-02-26 03:17:25 -05:00
|
|
|
let(:refresh_service) { service.new(@project, @user) }
|
2014-11-11 09:49:26 -05:00
|
|
|
before do
|
2015-02-26 03:17:25 -05:00
|
|
|
allow(refresh_service).to receive(:execute_hooks)
|
|
|
|
refresh_service.execute(@oldrev, @newrev, 'refs/heads/master')
|
2014-11-11 09:49:26 -05:00
|
|
|
reload_mrs
|
|
|
|
end
|
|
|
|
|
2015-02-26 03:17:25 -05:00
|
|
|
it 'should execute hooks with update action' do
|
|
|
|
expect(refresh_service).to have_received(:execute_hooks).
|
|
|
|
with(@merge_request, 'update')
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@merge_request.notes).not_to be_empty }
|
|
|
|
it { expect(@merge_request).to be_open }
|
|
|
|
it { expect(@fork_merge_request).to be_open }
|
|
|
|
it { expect(@fork_merge_request.notes).to be_empty }
|
2014-11-11 09:49:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'push to origin repo target branch' do
|
|
|
|
before do
|
|
|
|
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
|
|
|
|
reload_mrs
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@merge_request.notes.last.note).to include('changed to merged') }
|
|
|
|
it { expect(@merge_request).to be_merged }
|
|
|
|
it { expect(@fork_merge_request).to be_merged }
|
|
|
|
it { expect(@fork_merge_request.notes.last.note).to include('changed to merged') }
|
2014-11-11 09:49:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'push to fork repo source branch' do
|
2015-02-26 03:17:25 -05:00
|
|
|
let(:refresh_service) { service.new(@fork_project, @user) }
|
2014-11-11 09:49:26 -05:00
|
|
|
before do
|
2015-02-26 03:17:25 -05:00
|
|
|
allow(refresh_service).to receive(:execute_hooks)
|
|
|
|
refresh_service.execute(@oldrev, @newrev, 'refs/heads/master')
|
2014-11-11 09:49:26 -05:00
|
|
|
reload_mrs
|
|
|
|
end
|
|
|
|
|
2015-02-26 03:17:25 -05:00
|
|
|
it 'should execute hooks with update action' do
|
|
|
|
expect(refresh_service).to have_received(:execute_hooks).
|
|
|
|
with(@fork_merge_request, 'update')
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@merge_request.notes).to be_empty }
|
|
|
|
it { expect(@merge_request).to be_open }
|
2015-03-06 11:14:19 -05:00
|
|
|
it { expect(@fork_merge_request.notes.last.note).to include('Added 4 commits') }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@fork_merge_request).to be_open }
|
2014-11-11 09:49:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'push to fork repo target branch' do
|
|
|
|
before do
|
|
|
|
service.new(@fork_project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
|
|
|
|
reload_mrs
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@merge_request.notes).to be_empty }
|
|
|
|
it { expect(@merge_request).to be_open }
|
|
|
|
it { expect(@fork_merge_request.notes).to be_empty }
|
|
|
|
it { expect(@fork_merge_request).to be_open }
|
2014-11-11 09:49:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'push to origin repo target branch after fork project was removed' do
|
|
|
|
before do
|
|
|
|
@fork_project.destroy
|
|
|
|
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
|
|
|
|
reload_mrs
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@merge_request.notes.last.note).to include('changed to merged') }
|
|
|
|
it { expect(@merge_request).to be_merged }
|
|
|
|
it { expect(@fork_merge_request).to be_open }
|
|
|
|
it { expect(@fork_merge_request.notes).to be_empty }
|
2014-11-11 09:49:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload_mrs
|
|
|
|
@merge_request.reload
|
|
|
|
@fork_merge_request.reload
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|