considers tags within a debate search

This commit is contained in:
David Gil
2015-09-15 15:06:34 +02:00
parent 21c9f3fead
commit 497c595704
2 changed files with 7 additions and 2 deletions

View File

@@ -114,7 +114,10 @@ class Debate < ActiveRecord::Base
end
def self.search(terms)
terms.present? ? where("title ILIKE ? OR description ILIKE ?", "%#{terms}%", "%#{terms}%") : none
return none unless terms.present?
ids = where("debates.title ILIKE ? OR debates.description ILIKE ?", "%#{terms}%", "%#{terms}%").pluck(:id) | tagged_with(terms).pluck(:id)
where(id: ids)
end
def conflictive?

View File

@@ -482,15 +482,17 @@ feature 'Debates' do
debate2 = create(:debate, title: "Get Schwifty")
debate3 = create(:debate)
debate4 = create(:debate, description: "Schwifty in here")
debate5 = create(:debate, tag_list: 'schwifty')
visit debates_path
fill_in "search", with: "Schwifty"
click_button "Search"
within("#debates") do
expect(page).to have_css('.debate', count: 2)
expect(page).to have_css('.debate', count: 3)
expect(page).to have_content(debate2.title)
expect(page).to have_content(debate4.title)
expect(page).to have_content(debate5.title)
expect(page).to_not have_content(debate1.title)
expect(page).to_not have_content(debate3.title)
end