From 09cded29d8b86cafbcfaed57b1d915588195f69f Mon Sep 17 00:00:00 2001
From: Katarzyna Kobierska <kkobierska@gmail.com>
Date: Fri, 2 Sep 2016 13:36:25 +0200
Subject: [PATCH] Checks if deleting forked project closed all open merge
 requests

---
 app/controllers/projects/merge_requests_controller.rb | 4 ++--
 app/models/merge_request.rb                           | 2 +-
 spec/controllers/projects_controller_spec.rb          | 8 +++++---
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 8895cb955bd..479b2d1d900 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -429,7 +429,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
 
   def validates_merge_request
     # If source project was removed (Ex. mr from fork to origin)
-    return invalid_mr unless @merge_request.source_project
+    # return invalid_mr unless @merge_request.source_project
 
     # Show git not found page
     # if there is no saved commits between source & target branch
@@ -438,7 +438,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
       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?
+      # return invalid_mr unless @merge_request.source_branch_exists?
     end
   end
 
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index b0b1313f94a..7d3c8c5078a 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -313,7 +313,7 @@ class MergeRequest < ActiveRecord::Base
   end
 
   def closed_without_fork?
-    closed? && forked_source_project_missing?
+    closed? && (forked_source_project_missing? || !source_project)
   end
 
   def forked_source_project_missing?
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 95315d86c4d..4f5741f1647 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -192,10 +192,12 @@ describe ProjectsController do
       end
 
       it "closes all related merge requests" do
-        fork_project.destroy
+        project.merge_requests << merge_request
+        sign_in(admin)
 
-        expect(fork_project.destroyed?).to be_truthy
-        expect(merge_request.state).to eq('closed')
+        delete :destroy, namespace_id: fork_project.namespace.path, id: fork_project.path
+
+        expect(merge_request.reload.state).to eq('closed')
       end
     end
   end
-- 
GitLab