@@ -49,6 +49,8 @@
<% end %>
+ <%= render("shared/advanced_search", search_path: budget_investments_url(@budget)) %>
+
<%= render('shared/order_links', i18n_namespace: "budgets.investments.index") unless @current_filter == "unfeasible" %>
<% @investments.each do |investment| %>
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index bd31f9cf3..205db683c 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -542,8 +542,6 @@ en:
"no": "No"
search_results: "Search results"
advanced_search:
- phase: "By budget's phase"
- phase_blank: 'Select a phase'
author_type: 'By author category'
author_type_blank: 'Select a category'
date: 'By date'
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index d52b8798c..36d8644cf 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -542,8 +542,6 @@ es:
"no": "No"
search_results: "Resultados de la búsqueda"
advanced_search:
- phase: 'Por estado del proyecto'
- phase_blank: 'Elige una estado'
author_type: 'Por categoría de autor'
author_type_blank: 'Elige una categoría'
date: 'Por fecha'
diff --git a/config/locales/fr/general.yml b/config/locales/fr/general.yml
index 1862a4cc1..cf1488375 100644
--- a/config/locales/fr/general.yml
+++ b/config/locales/fr/general.yml
@@ -1354,8 +1354,6 @@ fr:
proposition
shared:
advanced_search:
- phase: Par statut du projet
- phase_blank: Sélectionner une statut
author_type: Par catégorie d'auteur
author_type_blank: Sélectionner une catégorie
date: Par date
diff --git a/config/locales/it/general.yml b/config/locales/it/general.yml
index 387d2d037..c0309e872 100644
--- a/config/locales/it/general.yml
+++ b/config/locales/it/general.yml
@@ -506,8 +506,6 @@ it:
"no": ""
search_results: ""
advanced_search:
- phase: ''
- phase_blank: ''
author_type: ''
author_type_blank: ''
date: ''
diff --git a/config/locales/nl/general.yml b/config/locales/nl/general.yml
index b5567294d..62221c280 100644
--- a/config/locales/nl/general.yml
+++ b/config/locales/nl/general.yml
@@ -473,8 +473,6 @@ nl:
"yes": "Ja"
"no": "Nee"
advanced_search:
- phase: 'Op projectstatus'
- phase_blank: 'Selecteer een staat'
author_type: 'Op auteur categorie'
author_type_blank: 'Selecteer een categorie'
date: 'Op datum'
diff --git a/config/locales/pt-BR/general.yml b/config/locales/pt-BR/general.yml
index 63068825b..bfe4124f7 100644
--- a/config/locales/pt-BR/general.yml
+++ b/config/locales/pt-BR/general.yml
@@ -1370,8 +1370,6 @@ pt-BR:
votes_for_proposal_success: Número de votos necessários para aprovar uma Proposta
shared:
advanced_search:
- phase: Por status do projeto
- phase_blank: Selecione um status
author_type: Por categoria de autor
author_type_blank: Selecione um categoria
date: Por data
diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb
index 66f94da1b..468827b61 100644
--- a/spec/features/budgets/budgets_spec.rb
+++ b/spec/features/budgets/budgets_spec.rb
@@ -110,176 +110,21 @@ feature 'Budgets' do
expect(page).to have_css(".phase.active", count: 1)
end
- context "Advanced search" do
-
- context "Search by phase type" do
-
- scenario "Accepting Budget", :js do
- budget = create(:budget, :accepting)
- budget2 = create(:budget, :reviewing)
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Accepting projects', from: 'advanced_search_budget_phase')
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
-
- scenario "Reviewing Budget", :js do
- budget = create(:budget, :reviewing)
- budget2 = create(:budget, :accepting)
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Reviewing projects', from: 'advanced_search_budget_phase')
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
-
- scenario "Selecting Budget", :js do
- budget = create(:budget, :selecting)
- budget2 = create(:budget, :reviewing)
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Selecting projects', from: 'advanced_search_budget_phase')
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
-
- scenario "Valuating Budget", :js do
- budget = create(:budget, :valuating)
- budget2 = create(:budget, :reviewing)
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Valuating projects', from: 'advanced_search_budget_phase')
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
-
- scenario "Balloting Budget", :js do
- budget = create(:budget, :balloting)
- budget2 = create(:budget, :reviewing)
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Balloting projects', from: 'advanced_search_budget_phase')
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
-
- scenario "Reviewing Ballots", :js do
- budget = create(:budget, :reviewing_ballots)
- budget2 = create(:budget, :reviewing)
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Reviewing Ballots', from: 'advanced_search_budget_phase')
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
-
- scenario "Finished Ballots", :js do
- budget = create(:budget, :finished)
- budget2 = create(:budget, :reviewing)
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Finished budget', from: 'advanced_search_budget_phase')
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
- end
- end
-
- context "Search by date" do
-
- context "Predefined date ranges" do
-
- scenario "Last day", :js do
- budget = create(:budget, :accepting, created_at: 1.day.ago)
- budget2 = create(:budget, :reviewing, created_at: 2.days.ago)
- visit budgets_path
- click_link "js-advanced-search-title"
- select "Last 24 hours", from: "js-advanced-search-date-min"
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
-
- scenario "Search by multiple filters", :js do
- budget = create(:budget, :accepting, created_at: 1.day.ago)
- budget2 = create(:budget, :selecting, created_at: 2.days.ago)
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Accepting projects', from: 'advanced_search_budget_phase')
- select "Last 24 hours", from: "js-advanced-search-date-min"
- click_button "Filter"
- within "#budgets" do
- expect(page).to have_content(budget.translated_phase)
- expect(page).to_not have_content(budget2.translated_phase)
- end
- end
-
- scenario "Maintain advanced search criteria", :js do
- visit budgets_path
- click_link "js-advanced-search-title"
- select('Accepting projects', from: 'advanced_search_budget_phase')
- select "Last 24 hours", from: "js-advanced-search-date-min"
- click_button "Filter"
- within "#js-advanced-search" do
- expect(page).to have_select('advanced_search[budget_phase]', selected: 'Accepting projects')
- expect(page).to have_select('advanced_search[date_min]', selected: 'Last 24 hours')
- end
- end
-
- scenario "Maintain custom date search criteria", :js do
- visit budgets_path
- click_link "js-advanced-search-title"
- select "Customized", from: "js-advanced-search-date-min"
- fill_in "advanced_search_date_min", with: 7.days.ago
- fill_in "advanced_search_date_max", with: 1.day.ago
- click_button "Filter"
- within "#js-advanced-search" do
- expect(page).to have_select('advanced_search[date_min]', selected: 'Customized')
- expect(page).to have_selector("input[name='advanced_search[date_min]'][value*='#{7.days.ago.strftime('%Y-%m-%d')}']")
- expect(page).to have_selector("input[name='advanced_search[date_max]'][value*='#{1.day.ago.strftime('%Y-%m-%d')}']")
- end
- end
-
- end
- end
-
-
context 'Show' do
scenario "List all groups" do
group1 = create(:budget_group, budget: budget)
group2 = create(:budget_group, budget: budget)
+
visit budget_path(budget)
+
budget.groups.each {|group| expect(page).to have_link(group.name)}
end
scenario "Links to unfeasible and selected if balloting or later" do
budget = create(:budget, :selecting)
group = create(:budget_group, budget: budget)
+
visit budget_path(budget)
expect(page).not_to have_link "See unfeasible investments"
@@ -291,17 +136,26 @@ feature 'Budgets' do
expect(page).not_to have_link "See investments not selected for balloting phase"
budget.update(phase: :balloting)
+
visit budget_path(budget)
+
expect(page).to have_link "See unfeasible investments"
expect(page).to have_link "See investments not selected for balloting phase"
+
click_link group.name
+
expect(page).to have_link "See unfeasible investments"
expect(page).to have_link "See investments not selected for balloting phase"
+
budget.update(phase: :finished)
+
visit budget_path(budget)
+
expect(page).to have_link "See unfeasible investments"
expect(page).to have_link "See investments not selected for balloting phase"
+
click_link group.name
+
expect(page).to have_link "See unfeasible investments"
expect(page).to have_link "See investments not selected for balloting phase"
end
@@ -380,14 +234,18 @@ feature 'Budgets' do
scenario "Unverified user" do
user = create(:user)
login_as(user)
+
visit budget_path(budget)
+
expect(page).to have_content "To create a new budget investment verify your account."
end
scenario "user not logged in" do
visit budget_path(budget)
+
expect(page).to have_content "To create a new budget investment you must sign in or sign up."
end
+
end
end
end
diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb
index f9598c773..9bd9ae458 100644
--- a/spec/features/budgets/investments_spec.rb
+++ b/spec/features/budgets/investments_spec.rb
@@ -81,6 +81,341 @@ feature 'Budget Investments' do
end
end
+ context "Advanced search" do
+
+ scenario "Search by text", :js do
+ bdgt_invest1 = create(:budget_investment, heading: heading,title: "Get Schwifty")
+ bdgt_invest2 = create(:budget_investment, heading: heading,title: "Schwifty Hello")
+ bdgt_invest3 = create(:budget_investment, heading: heading,title: "Do not show me")
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ fill_in "Write the text", with: "Schwifty"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ context "Search by author type" do
+
+ scenario "Public employee", :js do
+ ana = create :user, official_level: 1
+ john = create :user, official_level: 2
+
+ bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest3 = create(:budget_investment, heading: heading, author: john)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select Setting['official_level_1_name'], from: "advanced_search_official_level"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "Municipal Organization", :js do
+ ana = create :user, official_level: 2
+ john = create :user, official_level: 3
+
+ bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest3 = create(:budget_investment, heading: heading, author: john)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select Setting['official_level_2_name'], from: "advanced_search_official_level"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "General director", :js do
+ ana = create :user, official_level: 3
+ john = create :user, official_level: 4
+
+ bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest3 = create(:budget_investment, heading: heading, author: john)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select Setting['official_level_3_name'], from: "advanced_search_official_level"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "City councillor", :js do
+ ana = create :user, official_level: 4
+ john = create :user, official_level: 5
+
+ bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest3 = create(:budget_investment, heading: heading, author: john)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select Setting['official_level_4_name'], from: "advanced_search_official_level"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "Mayoress", :js do
+ ana = create :user, official_level: 5
+ john = create :user, official_level: 4
+
+ bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
+ bdgt_invest3 = create(:budget_investment, heading: heading, author: john)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select Setting['official_level_5_name'], from: "advanced_search_official_level"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ end
+
+ context "Search by date" do
+
+ context "Predefined date ranges" do
+
+ scenario "Last day", :js do
+ bdgt_invest1 = create(:budget_investment, heading: heading,created_at: 1.minute.ago)
+ bdgt_invest2 = create(:budget_investment, heading: heading,created_at: 1.hour.ago)
+ bdgt_invest3 = create(:budget_investment, heading: heading,created_at: 2.days.ago)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select "Last 24 hours", from: "js-advanced-search-date-min"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "Last week", :js do
+ bdgt_invest1 = create(:budget_investment, heading: heading,created_at: 1.day.ago)
+ bdgt_invest2 = create(:budget_investment, heading: heading,created_at: 5.days.ago)
+ bdgt_invest3 = create(:budget_investment, heading: heading,created_at: 8.days.ago)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select "Last week", from: "js-advanced-search-date-min"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "Last month", :js do
+ bdgt_invest1 = create(:budget_investment, heading: heading,created_at: 10.days.ago)
+ bdgt_invest2 = create(:budget_investment, heading: heading,created_at: 20.days.ago)
+ bdgt_invest3 = create(:budget_investment, heading: heading,created_at: 33.days.ago)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select "Last month", from: "js-advanced-search-date-min"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "Last year", :js do
+ bdgt_invest1 = create(:budget_investment, heading: heading,created_at: 300.days.ago)
+ bdgt_invest2 = create(:budget_investment, heading: heading,created_at: 350.days.ago)
+ bdgt_invest3 = create(:budget_investment, heading: heading,created_at: 370.days.ago)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select "Last year", from: "js-advanced-search-date-min"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ end
+
+ scenario "Search by custom date range", :js do
+ bdgt_invest1 = create(:budget_investment, heading: heading,created_at: 2.days.ago)
+ bdgt_invest2 = create(:budget_investment, heading: heading,created_at: 3.days.ago)
+ bdgt_invest3 = create(:budget_investment, heading: heading,created_at: 9.days.ago)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select "Customized", from: "js-advanced-search-date-min"
+ fill_in "advanced_search_date_min", with: 7.days.ago
+ fill_in "advanced_search_date_max", with: 1.day.ago
+ click_button "Filter"
+
+ expect(page).to have_content("There are 2 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).not_to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "Search by custom invalid date range", :js do
+ bdgt_invest1 = create(:budget_investment, heading: heading,created_at: 2.days.ago)
+ bdgt_invest2 = create(:budget_investment, heading: heading,created_at: 3.days.ago)
+ bdgt_invest3 = create(:budget_investment, heading: heading,created_at: 9.days.ago)
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ select "Customized", from: "js-advanced-search-date-min"
+ fill_in "advanced_search_date_min", with: 4000.years.ago
+ fill_in "advanced_search_date_max", with: "wrong date"
+ click_button "Filter"
+
+ expect(page).to have_content("There are 3 investments")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ expect(page).to have_content(bdgt_invest2.title)
+ expect(page).to have_content(bdgt_invest3.title)
+ end
+ end
+
+ scenario "Search by multiple filters", :js do
+ ana = create :user, official_level: 1
+ john = create :user, official_level: 1
+
+ bdgt_invest1 = create(:budget_investment, heading: heading,title: "Get Schwifty", author: ana, created_at: 1.minute.ago)
+ bdgt_invest2 = create(:budget_investment, heading: heading,title: "Hello Schwifty", author: john, created_at: 2.days.ago)
+ bdgt_invest3 = create(:budget_investment, heading: heading,title: "Save the forest")
+
+ visit budget_investments_path(budget)
+
+ click_link "Advanced search"
+ fill_in "Write the text", with: "Schwifty"
+ select Setting['official_level_1_name'], from: "advanced_search_official_level"
+ select "Last 24 hours", from: "js-advanced-search-date-min"
+
+ click_button "Filter"
+
+ expect(page).to have_content("There is 1 investment")
+
+ within("#budget-investments") do
+ expect(page).to have_content(bdgt_invest1.title)
+ end
+ end
+
+ scenario "Maintain advanced search criteria", :js do
+ visit budget_investments_path(budget)
+ click_link "Advanced search"
+
+ fill_in "Write the text", with: "Schwifty"
+ select Setting['official_level_1_name'], from: "advanced_search_official_level"
+ select "Last 24 hours", from: "js-advanced-search-date-min"
+
+ click_button "Filter"
+
+ expect(page).to have_content("investments cannot be found")
+
+ within "#js-advanced-search" do
+ expect(page).to have_selector("input[name='search'][value='Schwifty']")
+ expect(page).to have_select('advanced_search[official_level]', selected: Setting['official_level_1_name'])
+ expect(page).to have_select('advanced_search[date_min]', selected: 'Last 24 hours')
+ end
+ end
+
+ scenario "Maintain custom date search criteria", :js do
+ visit budget_investments_path(budget)
+ click_link "Advanced search"
+
+ select "Customized", from: "js-advanced-search-date-min"
+ fill_in "advanced_search_date_min", with: 7.days.ago.to_date
+ fill_in "advanced_search_date_max", with: 1.day.ago.to_date
+ click_button "Filter"
+
+ expect(page).to have_content("investments cannot be found")
+
+ within "#js-advanced-search" do
+ expect(page).to have_select('advanced_search[date_min]', selected: 'Customized')
+ expect(page).to have_selector("input[name='advanced_search[date_min]'][value*='#{7.days.ago.strftime('%Y-%m-%d')}']")
+ expect(page).to have_selector("input[name='advanced_search[date_max]'][value*='#{1.day.ago.strftime('%Y-%m-%d')}']")
+ end
+ end
+
+ end
+ end
end
context("Filters") do
diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb
index 7fbb46039..4c8ade0f5 100644
--- a/spec/models/budget/investment_spec.rb
+++ b/spec/models/budget/investment_spec.rb
@@ -514,6 +514,23 @@ describe Budget::Investment do
describe "search" do
+ context "attributes" do
+
+ it "searches by title" do
+ budget_investment = create(:budget_investment, title: 'save the world')
+ results = described_class.search('save the world')
+ expect(results).to eq([budget_investment])
+ end
+
+ it "searches by author name" do
+ author = create(:user, username: 'Danny Trejo')
+ budget_investment = create(:budget_investment, author: author)
+ results = described_class.search('Danny')
+ expect(results).to eq([budget_investment])
+ end
+
+ end
+
context "tags" do
it "searches by tags" do
investment = create(:budget_investment, tag_list: 'Latina')