From 554baec9e8d2d077afff5502fdfa4ab78036499c Mon Sep 17 00:00:00 2001
From: Katarzyna Kobierska <kkobierska@gmail.com>
Date: Tue, 6 Sep 2016 16:48:59 +0200
Subject: [PATCH] Add method

---
 app/models/merge_request.rb       |  7 +++++++
 spec/models/merge_request_spec.rb | 13 +++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index f752a4fd1cc..5986a464bbc 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -327,6 +327,13 @@ class MergeRequest < ActiveRecord::Base
     !source_project.forked_from?(target_project)
   end
 
+  def can_reopen?
+    return false if closed_without_fork? || closed_without_source_project?
+    return true if closed?
+
+    # false
+  end
+
   def ensure_merge_request_diff
     merge_request_diff || create_merge_request_diff
   end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index e223d51aa6a..4780d9fb3fe 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -1076,4 +1076,17 @@ describe MergeRequest, models: true do
       end
     end
   end
+
+  describe '#can_reopen?' do
+    it "returns true" do
+      subject.close
+      binding.pry
+
+      expect(subject.can_reopen?).to be_truthy
+    end
+
+    it "returns false" do
+      expect(subject.can_reopen?).to be_falsey
+    end
+  end
 end
-- 
GitLab