Commit 81da7f13 authored by Katarzyna Kobierska's avatar Katarzyna Kobierska

Add test checking method closed_without_source_project

parent 31c37c6c
...@@ -428,17 +428,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -428,17 +428,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def validates_merge_request def validates_merge_request
# If source project was removed (Ex. mr from fork to origin)
# return invalid_mr unless @merge_request.source_project
# Show git not found page # Show git not found page
# if there is no saved commits between source & target branch # if there is no saved commits between source & target branch
if @merge_request.commits.blank? if @merge_request.commits.blank?
# and if target branch doesn't exist # and if target branch doesn't exist
return invalid_mr unless @merge_request.target_branch_exists? return invalid_mr unless @merge_request.target_branch_exists?
# or if source branch doesn't exist
# return invalid_mr unless @merge_request.source_branch_exists?
end end
end end
......
...@@ -1038,4 +1038,42 @@ describe MergeRequest, models: true do ...@@ -1038,4 +1038,42 @@ describe MergeRequest, models: true do
end end
end end
end end
describe "#closed_without_source_project?" do
let(:project) { create(:project) }
let(:fork_project) { create(:project, forked_from_project: project) }
let(:user) { create(:user) }
let(:destroy_project) { Projects::DestroyService.new(fork_project, user, {}) }
context "when the merge request is closed" do
let(:closed_merge_request) do
create(:closed_merge_request,
source_project: fork_project,
target_project: project)
end
it "returns false if the source project exist" do
expect(closed_merge_request.closed_without_source_project?).to be_falsey
end
it "returns true if the source project does not exist" do
destroy_project.async_execute
closed_merge_request.reload
expect(closed_merge_request.closed_without_source_project?).to be_truthy
end
end
context "when the merge request is open" do
let(:open_merge_request) do
create(:merge_request,
source_project: fork_project,
target_project: project)
end
it "returns false" do
expect(open_merge_request.closed_without_source_project?).to be_falsey
end
end
end
end end
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