diff --git a/app/models/concerns/filterable.rb b/app/models/concerns/filterable.rb
index 0deff1783..68e844782 100644
--- a/app/models/concerns/filterable.rb
+++ b/app/models/concerns/filterable.rb
@@ -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
diff --git a/app/models/proposal.rb b/app/models/proposal.rb
index ed2bf71a2..5c28d9bd4 100644
--- a/app/models/proposal.rb
+++ b/app/models/proposal.rb
@@ -68,6 +68,7 @@ class Proposal < ActiveRecord::Base
description => 'D'
}
tag_list.each{ |tag| values[tag] = 'D' }
+ values[author.username] = 'D'
values
end
diff --git a/app/views/shared/_advanced_search.html.erb b/app/views/shared/_advanced_search.html.erb
index ea1938110..df811144b 100644
--- a/app/views/shared/_advanced_search.html.erb
+++ b/app/views/shared/_advanced_search.html.erb
@@ -13,12 +13,6 @@
placeholder: t("shared.advanced_search.general_placeholder") %>
-
-
<%= t("shared.advanced_search.author") %>
- <%= text_field_tag "advanced_search[author]", params[:advanced_search].try(:[], :author),
- placeholder: t("shared.advanced_search.author_placeholder") %>
-
-
<%= t("shared.advanced_search.author_type") %>
<%= select_tag('advanced_search[official_level]', official_level_search_options,
diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb
index 8447004c3..1f1c8388c 100644
--- a/spec/features/debates_spec.rb
+++ b/spec/features/debates_spec.rb
@@ -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
diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb
index ec1085dc0..c8d81e9f0 100644
--- a/spec/features/proposals_spec.rb
+++ b/spec/features/proposals_spec.rb
@@ -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
diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb
index a90423645..527968700 100644
--- a/spec/models/debate_spec.rb
+++ b/spec/models/debate_spec.rb
@@ -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
diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb
index db9c356d0..058446341 100644
--- a/spec/models/proposal_spec.rb
+++ b/spec/models/proposal_spec.rb
@@ -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