From 541a5fa89f4a61f947964339d4e8cdd22c02fa29 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 13 Aug 2021 10:16:00 +0700 Subject: [PATCH] Avoid error when combining investments advanced search with filters --- app/controllers/concerns/search.rb | 3 +++ spec/system/budgets/investments_spec.rb | 33 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/app/controllers/concerns/search.rb b/app/controllers/concerns/search.rb index d29f5b044..1dd5074f5 100644 --- a/app/controllers/concerns/search.rb +++ b/app/controllers/concerns/search.rb @@ -12,6 +12,9 @@ module Search end def parse_advanced_search_terms + if params[:advanced_search].is_a? String + params[:advanced_search] = JSON.parse(params[:advanced_search].gsub("=>", ":")) + end @advanced_search_terms = params[:advanced_search] if params[:advanced_search].present? parse_search_date end diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index c07c0c1e4..f8bc93ac8 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -194,6 +194,39 @@ describe "Budget Investments" do expect(page).not_to have_content(investment3.title) end end + + scenario "Advanced search combined with filter by status" do + create(:budget_investment, :feasible, heading: heading, title: "Feasible environment") + create(:budget_investment, :feasible, heading: heading, title: "Feasible health") + create(:budget_investment, :unfeasible, heading: heading, title: "Unfeasible environment") + create(:budget_investment, :unfeasible, heading: heading, title: "Unfeasible health") + + visit budget_investments_path(budget, heading: heading) + + click_on "Advanced search" + + within(".advanced-search-form") do + fill_in "With the text", with: "environment" + select "Last 24 hours", from: "By date" + click_button "Filter" + end + + expect(page).to have_content "There is 1 investment containing the term 'environment'" + expect(page).to have_css ".budget-investment", count: 1 + expect(page).to have_content "Feasible environment" + expect(page).not_to have_content "Feasible health" + expect(page).not_to have_content "Unfeasible environment" + expect(page).not_to have_content "Unfeasible health" + + select "Unfeasible", from: "Filtering projects by" + + expect(page).not_to have_content "Feasible environment" + expect(page).to have_content "There is 1 investment containing the term 'environment'" + expect(page).to have_css ".budget-investment", count: 1 + expect(page).to have_content "Unfeasible environment" + expect(page).not_to have_content "Feasible health" + expect(page).not_to have_content "Unfeasible health" + end end context("Filters") do