Permalink
Browse files

search on other comment fields besides content

  • Loading branch information...
1 parent fbe42df commit 90e0ec3ea4102831873ced8c6e378438a49ed405 @ryanb committed Aug 2, 2011
Showing with 9 additions and 2 deletions.
  1. +2 −1 app/models/comment.rb
  2. +6 −0 spec/models/comment_spec.rb
  3. +1 −1 spec/requests/comments_request_spec.rb
View
3 app/models/comment.rb
@@ -13,7 +13,8 @@ def self.search(query)
if query.blank?
scoped
else
- where("comments.content like ?", "%#{query}%")
+ conditions = %w[content name email site_url].map { |c| "comments.#{c} like :query" }
+ where(conditions.join(" or "), :query => "%#{query}%")
end
end
View
6 spec/models/comment_spec.rb
@@ -41,4 +41,10 @@
c4 = Factory(:comment, :parent => c3)
c4.users_to_notify.should eq([])
end
+
+ it "searches by comment site url" do
+ c1 = Factory(:comment, :site_url => "http://example.com")
+ c2 = Factory(:comment, :site_url => "http://example2.com")
+ Comment.search("example.com").should eq([c1])
+ end
end
View
2 spec/requests/comments_request_spec.rb
@@ -67,7 +67,7 @@
it "lists and search recent comments" do
login Factory(:user, :admin => true)
Factory(:comment, :content => "Hello world!")
- Factory(:comment, :content => "Back to the Future")
+ Factory(:comment, :content => "Back to the Future", :site_url => "http://example.com")
visit comments_path
page.should have_content("Hello world!")
page.should have_content("Back to the Future")

0 comments on commit 90e0ec3

Please sign in to comment.