Merge pull request #504 from dgilperez/tags_in_search

Incluyendo etiquetas en el buscador de debates
This commit is contained in:
Enrique García
2015-09-17 17:17:14 +02:00
2 changed files with 11 additions and 2 deletions

View File

@@ -114,7 +114,12 @@ 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?
debate_ids = where("debates.title ILIKE ? OR debates.description ILIKE ?",
"%#{terms}%", "%#{terms}%").pluck(:id)
tag_ids = tagged_with(terms, wild: true, any: true).pluck(:id)
where(id: [debate_ids, tag_ids].flatten.compact)
end
def conflictive?

View File

@@ -482,15 +482,19 @@ 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')
debate6 = create(:debate, tag_list: ['awesome foreign schwifty', 'major'])
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: 4)
expect(page).to have_content(debate2.title)
expect(page).to have_content(debate4.title)
expect(page).to have_content(debate5.title)
expect(page).to have_content(debate6.title)
expect(page).to_not have_content(debate1.title)
expect(page).to_not have_content(debate3.title)
end