From b7f9b8223e40aa9e4aa8579d9a062df7e2e1d959 Mon Sep 17 00:00:00 2001
From: Robert Speicher <rspeicher@gmail.com>
Date: Thu, 9 Aug 2012 13:45:12 -0400
Subject: [PATCH] Fix `search` class method for IssueCommonality

Also adds specs to the two affected classes that would have caught my
dumb mistake.
---
 app/roles/issue_commonality.rb    | 6 ++++--
 spec/models/issue_spec.rb         | 8 ++++++++
 spec/models/merge_request_spec.rb | 9 +++++++++
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/app/roles/issue_commonality.rb b/app/roles/issue_commonality.rb
index 424b9cfb11b..353d6a5c977 100644
--- a/app/roles/issue_commonality.rb
+++ b/app/roles/issue_commonality.rb
@@ -36,8 +36,10 @@ module IssueCommonality
     attr_accessor :author_id_of_changes
   end
 
-  def self.search query
-    where("title like :query", :query => "%#{query}%")
+  module ClassMethods
+    def search(query)
+      where("title like :query", :query => "%#{query}%")
+    end
   end
 
   def today?
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index fbd4031fa0b..806b8ee74e0 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -106,6 +106,14 @@ describe Issue do
     end
   end
 
+  describe ".search" do
+    let!(:issue) { Factory.create(:issue, :title => "Searchable issue",
+                                 :project => Factory.create(:project)) }
+
+    it "matches by title" do
+      Issue.search('able').all.should == [issue]
+    end
+  end
 end
 # == Schema Information
 #
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index ac986ccebe3..4ef6becf41b 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -56,6 +56,15 @@ describe MergeRequest do
       subject.upvotes.should == 2
     end
   end
+
+  describe ".search" do
+    let!(:issue) { Factory.create(:issue, :title => "Searchable issue",
+                                 :project => Factory.create(:project)) }
+
+    it "matches by title" do
+      Issue.search('able').all.should == [issue]
+    end
+  end
 end
 # == Schema Information
 #
-- 
GitLab