Implements searching in proposals
This commit is contained in:
@@ -65,6 +65,10 @@ class Proposal < ActiveRecord::Base
|
||||
6000
|
||||
end
|
||||
|
||||
def self.search(terms)
|
||||
terms.present? ? where("title ILIKE ? OR description ILIKE ? OR question ILIKE ?", "%#{terms}%", "%#{terms}%", "%#{terms}%") : none
|
||||
end
|
||||
|
||||
def editable?
|
||||
total_votes <= Setting.value_for("max_votes_for_proposal_edit").to_i
|
||||
end
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
<% content_for :header_addon do %>
|
||||
<%= render "shared/search_form_header",
|
||||
search_path: proposals_path(page: 1),
|
||||
i18n_namespace: "proposals.index.search_form" %>
|
||||
<% end %>
|
||||
|
||||
<section role="main">
|
||||
|
||||
<div class="wrap row">
|
||||
|
||||
@@ -164,6 +164,10 @@ en:
|
||||
filter_topic:
|
||||
one: " with the topic '%{topic}'"
|
||||
other: " with the topic '%{topic}'"
|
||||
search_form:
|
||||
title: Search
|
||||
button: Search
|
||||
placeholder: "Search proposals..."
|
||||
search_results:
|
||||
one: " containing '%{search_term}'"
|
||||
other: " containing '%{search_term}'"
|
||||
|
||||
@@ -164,6 +164,10 @@ es:
|
||||
filter_topic:
|
||||
one: " con el tema '%{topic}'"
|
||||
other: " con el tema '%{topic}'"
|
||||
search_form:
|
||||
title: Search
|
||||
button: Search
|
||||
placeholder: "Buscar propuestas ciudadanas..."
|
||||
search_results:
|
||||
one: " que contiene '%{search_term}'"
|
||||
other: " que contienen '%{search_term}'"
|
||||
|
||||
@@ -139,4 +139,27 @@ feature 'Proposals' do
|
||||
expect(current_url).to include('page=1')
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'proposal index search' do
|
||||
proposal1 = create(:proposal, title: "Show me what you got")
|
||||
proposal2 = create(:proposal, title: "Get Schwifty")
|
||||
proposal3 = create(:proposal)
|
||||
proposal4 = create(:proposal, description: "Schwifty in here")
|
||||
proposal5 = create(:proposal, question: "Schwifty in here")
|
||||
|
||||
visit proposals_path
|
||||
fill_in "search", with: "Schwifty"
|
||||
click_button "Search"
|
||||
|
||||
expect(current_path).to eq(proposals_path)
|
||||
|
||||
within("#proposals") do
|
||||
expect(page).to have_css('.proposal', count: 3)
|
||||
expect(page).to have_content(proposal2.title)
|
||||
expect(page).to have_content(proposal4.title)
|
||||
expect(page).to have_content(proposal5.title)
|
||||
expect(page).to_not have_content(proposal1.title)
|
||||
expect(page).to_not have_content(proposal3.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user