moves search by author name to full text searches
This commit is contained in:
@@ -2,7 +2,6 @@ module Filterable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
scope :by_author, -> (username) { where(users: { username: username }).joins(:author) }
|
||||
scope :by_official_level, -> (official_level) { where(users: { official_level: official_level }).joins(:author) }
|
||||
scope :by_date_range, -> (date_range) { where(created_at: date_range) }
|
||||
end
|
||||
@@ -21,7 +20,7 @@ module Filterable
|
||||
|
||||
def allowed_filter?(filter, value)
|
||||
return if value.blank?
|
||||
['author', 'official_level', 'date_range'].include?(filter)
|
||||
['official_level', 'date_range'].include?(filter)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -68,6 +68,7 @@ class Proposal < ActiveRecord::Base
|
||||
description => 'D'
|
||||
}
|
||||
tag_list.each{ |tag| values[tag] = 'D' }
|
||||
values[author.username] = 'D'
|
||||
values
|
||||
end
|
||||
|
||||
|
||||
@@ -13,12 +13,6 @@
|
||||
placeholder: t("shared.advanced_search.general_placeholder") %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 advanced-search columns">
|
||||
<h5 class='search-option inline-block'><%= t("shared.advanced_search.author") %></h5>
|
||||
<%= text_field_tag "advanced_search[author]", params[:advanced_search].try(:[], :author),
|
||||
placeholder: t("shared.advanced_search.author_placeholder") %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 advanced-search columns">
|
||||
<h5 class='search-option'><%= t("shared.advanced_search.author_type") %></h5>
|
||||
<%= select_tag('advanced_search[official_level]', official_level_search_options,
|
||||
|
||||
@@ -512,29 +512,6 @@ feature 'Debates' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Search by author", :js do
|
||||
ana = create :user, username: "Ana06"
|
||||
john = create :user, username: "John Smith"
|
||||
|
||||
debate1 = create(:debate, author: ana)
|
||||
debate2 = create(:debate, author: ana)
|
||||
debate3 = create(:debate, author: john)
|
||||
|
||||
visit debates_path
|
||||
|
||||
click_link "Advanced search"
|
||||
fill_in "Write the author name", with: "Ana06"
|
||||
click_button "Filter"
|
||||
|
||||
within("#debates") do
|
||||
expect(page).to have_css('.debate', count: 2)
|
||||
|
||||
expect(page).to have_content(debate1.title)
|
||||
expect(page).to have_content(debate2.title)
|
||||
expect(page).to_not have_content(debate3.title)
|
||||
end
|
||||
end
|
||||
|
||||
context "Search by author type" do
|
||||
|
||||
scenario "Public employee", :js do
|
||||
@@ -763,18 +740,17 @@ feature 'Debates' do
|
||||
end
|
||||
|
||||
scenario "Search by multiple filters", :js do
|
||||
ana = create :user, username: "Ana06", official_level: 1
|
||||
john = create :user, username: "John", official_level: 1
|
||||
ana = create :user, official_level: 1
|
||||
john = create :user, official_level: 1
|
||||
|
||||
debate1 = create(:debate, title: "Get Schwifty", author: ana, created_at: 1.minute.ago)
|
||||
debate2 = create(:debate, title: "Hello Schwifty", author: john, created_at: 1.minute.ago)
|
||||
debate2 = create(:debate, title: "Hello Schwifty", author: john, created_at: 2.days.ago)
|
||||
debate3 = create(:debate, title: "Save the forest")
|
||||
|
||||
visit debates_path
|
||||
|
||||
click_link "Advanced search"
|
||||
fill_in "Write the text", with: "Schwifty"
|
||||
fill_in "Write the author name", with: "Ana06"
|
||||
fill_in "Write the text", with: "Schwifty"
|
||||
select "Public employee", from: "advanced_search_official_level"
|
||||
select "Last 24 hours", from: "js-advanced-search-date-min"
|
||||
|
||||
@@ -791,7 +767,6 @@ feature 'Debates' do
|
||||
click_link "Advanced search"
|
||||
|
||||
fill_in "Write the text", with: "Schwifty"
|
||||
fill_in "Write the author name", with: "Ana06"
|
||||
select "Public employee", from: "advanced_search_official_level"
|
||||
select "Last 24 hours", from: "js-advanced-search-date-min"
|
||||
|
||||
@@ -799,7 +774,6 @@ feature 'Debates' do
|
||||
|
||||
within "#js-advanced-search" do
|
||||
expect(page).to have_selector("input[name='search'][value='Schwifty']")
|
||||
expect(page).to have_selector("input[name='advanced_search[author]'][value='Ana06']")
|
||||
expect(page).to have_select('advanced_search[official_level]', selected: 'Public employee')
|
||||
expect(page).to have_select('advanced_search[date_min]', selected: 'Last 24 hours')
|
||||
end
|
||||
|
||||
@@ -575,29 +575,6 @@ feature 'Proposals' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Search by author", :js do
|
||||
ana = create :user, username: "Ana06"
|
||||
john = create :user, username: "John Smith"
|
||||
|
||||
proposal1 = create(:proposal, author: ana)
|
||||
proposal2 = create(:proposal, author: ana)
|
||||
proposal3 = create(:proposal, author: john)
|
||||
|
||||
visit proposals_path
|
||||
|
||||
click_link "Advanced search"
|
||||
fill_in "Write the author name", with: "Ana06"
|
||||
click_button "Filter"
|
||||
|
||||
within("#proposals") do
|
||||
expect(page).to have_css('.proposal', count: 2)
|
||||
|
||||
expect(page).to have_content(proposal1.title)
|
||||
expect(page).to have_content(proposal2.title)
|
||||
expect(page).to_not have_content(proposal3.title)
|
||||
end
|
||||
end
|
||||
|
||||
context "Search by author type" do
|
||||
|
||||
scenario "Public employee", :js do
|
||||
@@ -826,18 +803,17 @@ feature 'Proposals' do
|
||||
end
|
||||
|
||||
scenario "Search by multiple filters", :js do
|
||||
ana = create :user, username: "Ana06", official_level: 1
|
||||
john = create :user, username: "John", official_level: 1
|
||||
ana = create :user, official_level: 1
|
||||
john = create :user, official_level: 1
|
||||
|
||||
proposal1 = create(:proposal, title: "Get Schwifty", author: ana, created_at: 1.minute.ago)
|
||||
proposal2 = create(:proposal, title: "Hello Schwifty", author: john, created_at: 1.minute.ago)
|
||||
proposal2 = create(:proposal, title: "Hello Schwifty", author: john, created_at: 2.days.ago)
|
||||
proposal3 = create(:proposal, title: "Save the forest")
|
||||
|
||||
visit proposals_path
|
||||
|
||||
click_link "Advanced search"
|
||||
fill_in "Write the text", with: "Schwifty"
|
||||
fill_in "Write the author name", with: "Ana06"
|
||||
fill_in "Write the text", with: "Schwifty"
|
||||
select "Public employee", from: "advanced_search_official_level"
|
||||
select "Last 24 hours", from: "js-advanced-search-date-min"
|
||||
|
||||
@@ -845,7 +821,6 @@ feature 'Proposals' do
|
||||
|
||||
within("#proposals") do
|
||||
expect(page).to have_css('.proposal', count: 1)
|
||||
|
||||
expect(page).to have_content(proposal1.title)
|
||||
end
|
||||
end
|
||||
@@ -855,7 +830,6 @@ feature 'Proposals' do
|
||||
click_link "Advanced search"
|
||||
|
||||
fill_in "Write the text", with: "Schwifty"
|
||||
fill_in "Write the author name", with: "Ana06"
|
||||
select "Public employee", from: "advanced_search_official_level"
|
||||
select "Last 24 hours", from: "js-advanced-search-date-min"
|
||||
|
||||
@@ -863,7 +837,6 @@ feature 'Proposals' do
|
||||
|
||||
within "#js-advanced-search" do
|
||||
expect(page).to have_selector("input[name='search'][value='Schwifty']")
|
||||
expect(page).to have_selector("input[name='advanced_search[author]'][value='Ana06']")
|
||||
expect(page).to have_select('advanced_search[official_level]', selected: 'Public employee')
|
||||
expect(page).to have_select('advanced_search[date_min]', selected: 'Last 24 hours')
|
||||
end
|
||||
|
||||
@@ -444,6 +444,13 @@ describe Debate do
|
||||
expect(results).to eq([debate])
|
||||
end
|
||||
|
||||
xit "searches by author name" do
|
||||
author = create(:user, username: 'Danny Trejo')
|
||||
debate = create(:debate, author: author)
|
||||
results = Debate.search('Danny')
|
||||
expect(results).to eq([debate])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "stemming" do
|
||||
|
||||
@@ -394,6 +394,13 @@ describe Proposal do
|
||||
expect(results).to eq([proposal])
|
||||
end
|
||||
|
||||
it "searches by author name" do
|
||||
author = create(:user, username: 'Danny Trejo')
|
||||
proposal = create(:proposal, author: author)
|
||||
results = Proposal.search('Danny')
|
||||
expect(results).to eq([proposal])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "stemming" do
|
||||
|
||||
Reference in New Issue
Block a user