Commit 6ba39cea authored by Kev's avatar Kev

Add simple test for reverting_merge_request

parent 13a2352c
......@@ -2413,6 +2413,64 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
end
describe '#reverting_merge_request' do
subject { create(:merge_request, source_project: create(:project, :repository)) }
context 'when there is no merge_commit for the MR' do
before do
subject.metrics.update!(merged_at: Time.current.utc)
end
it 'returns nil' do
expect(subject.reverting_merge_request(nil)).to be_nil
end
end
context 'when the MR has been merged' do
before do
MergeRequests::MergeService
.new(subject.target_project, subject.author, { sha: subject.diff_head_sha })
.execute(subject)
end
context 'when there is no revert commit' do
it 'returns nil' do
expect(subject.reverting_merge_request(nil)).to be_nil
end
end
context 'when there is no merged_at for the MR' do
before do
subject.metrics.update!(merged_at: nil)
end
it 'returns nil' do
expect(subject.reverting_merge_request(nil)).to be_nil
end
end
context 'when there is a revert commit by MR' do
let(:current_user) { subject.author }
let(:branch) { subject.target_branch }
let(:project) { subject.target_project }
let(:revert_commit_id) do
params = {
commit: subject.merge_commit,
branch_name: branch,
start_branch: branch
}
Commits::RevertService.new(project, current_user, params).execute[:result]
end
it 'returns nil' do
expect(subject.reverting_merge_request(current_user)).to be_nil
end
end
end
end
describe '#can_be_reverted?' do
subject { create(:merge_request, source_project: create(:project, :repository)) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment