diff --git a/app/controllers/admin/spending_proposals_controller.rb b/app/controllers/admin/spending_proposals_controller.rb index 3ae4872db..afa24f54c 100644 --- a/app/controllers/admin/spending_proposals_controller.rb +++ b/app/controllers/admin/spending_proposals_controller.rb @@ -21,7 +21,10 @@ class Admin::SpendingProposalsController < Admin::BaseController def update if @spending_proposal.update(spending_proposal_params) - redirect_to admin_spending_proposal_path(@spending_proposal, anchor: 'classification'), notice: t("flash.actions.update.spending_proposal") + path = admin_spending_proposal_path( @spending_proposal, + { anchor: 'classification' }.merge(SpendingProposal.filter_params(params))) + + redirect_to path, notice: t("flash.actions.update.spending_proposal") else render :edit end diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 27842fa91..237da73f7 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -35,6 +35,10 @@ class SpendingProposal < ActiveRecord::Base super.try :html_safe end + def self.filter_params(params) + params.select{|x,_| %w{geozone_id administrator_id tag_name valuator_id}.include? x.to_s } + end + def self.search(params, current_filter) results = self results = results.by_geozone(params[:geozone_id]) if params[:geozone_id].present? diff --git a/app/views/admin/spending_proposals/edit.html.erb b/app/views/admin/spending_proposals/edit.html.erb index 22510765a..67160b926 100644 --- a/app/views/admin/spending_proposals/edit.html.erb +++ b/app/views/admin/spending_proposals/edit.html.erb @@ -1,4 +1,4 @@ -<%= link_to admin_spending_proposals_path(@spending_proposal), class: 'back' do %> +<%= link_to admin_spending_proposal_path(@spending_proposal, SpendingProposal.filter_params(params)), class: 'back' do %> <%= t("admin.spending_proposals.show.back") %> <% end %> @@ -6,7 +6,12 @@
<%= f.submit(class: "button", value: t("admin.spending_proposals.edit.submit_button")) %> @@ -41,4 +42,4 @@ <% end %>
<%= link_to t("admin.spending_proposals.show.edit_classification"), - edit_admin_spending_proposal_path(@spending_proposal, anchor: "form") %> + edit_admin_spending_proposal_path(@spending_proposal, + {anchor: 'form'}.merge(SpendingProposal.filter_params(params))) %>
<%= t("admin.spending_proposals.show.assigned_admin") %>: diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 14af135da..ac4695d0f 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -252,6 +252,8 @@ end puts "Creating Spending Proposals" +tags = Faker::Lorem.words(10) + (1..30).each do |i| geozone = Geozone.reorder("RANDOM()").first author = User.reorder("RANDOM()").first @@ -262,6 +264,7 @@ puts "Creating Spending Proposals" description: description, created_at: rand((Time.now - 1.week) .. Time.now), geozone: [geozone, nil].sample, + tag_list: tags.sample(3).join(','), terms_of_service: "1") puts " #{spending_proposal.title}" end @@ -295,4 +298,4 @@ puts "Confirming hiding in debates, comments & proposals" Comment.only_hidden.flagged.reorder("RANDOM()").limit(10).each(&:confirm_hide) Debate.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide) -Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide) \ No newline at end of file +Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide) diff --git a/spec/features/admin/spending_proposals_spec.rb b/spec/features/admin/spending_proposals_spec.rb index 6530400c1..fcfec8638 100644 --- a/spec/features/admin/spending_proposals_spec.rb +++ b/spec/features/admin/spending_proposals_spec.rb @@ -66,11 +66,6 @@ feature 'Admin spending proposals' do expect(page).to have_link("Realocate visitors") expect(page).to have_link("Destroy the city") - select "District 9", from: "geozone_id" - - expect(page).to have_link("Realocate visitors") - expect(page).to_not have_link("Destroy the city") - select "All city", from: "geozone_id" expect(page).to have_link("Destroy the city") @@ -79,6 +74,28 @@ feature 'Admin spending proposals' do select "All zones", from: "geozone_id" expect(page).to have_link("Realocate visitors") expect(page).to have_link("Destroy the city") + + select "District 9", from: "geozone_id" + + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + click_link("Realocate visitors") + click_link("Back") + + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + click_link("Realocate visitors") + click_on("Edit classification") + expect(page).to have_button("Update") + click_on("Back") + expect(page).to_not have_button("Update") + click_on("Back") + + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + end scenario "Filtering by admin", :js do @@ -94,13 +111,36 @@ feature 'Admin spending proposals' do select "Admin 1", from: "administrator_id" - expect(page).to have_link("Realocate visitors") + expect(page).to have_content('There is 1 spending proposal') expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") select "All administrators", from: "administrator_id" + expect(page).to have_content('There are 2 spending proposals') expect(page).to have_link("Destroy the city") expect(page).to have_link("Realocate visitors") + + select "Admin 1", from: "administrator_id" + expect(page).to have_content('There is 1 spending proposal') + click_link("Realocate visitors") + click_link("Back") + + expect(page).to have_content('There is 1 spending proposal') + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + click_link("Realocate visitors") + click_on("Edit classification") + expect(page).to have_button("Update") + click_on("Back") + expect(page).to_not have_button("Update") + click_on("Back") + + expect(page).to have_content('There is 1 spending proposal') + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + end scenario "Current filter is properly highlighted" do @@ -183,10 +223,28 @@ feature 'Admin spending proposals' do visit admin_spending_proposals_path(tag_name: 'Education') + expect(page).to_not have_content("More hospitals") expect(page).to have_css(".spending_proposal", count: 2) expect(page).to have_content("Educate the children") expect(page).to have_content("More schools") + + click_link("Educate the children") + click_link("Back") + expect(page).to_not have_content("More hospitals") + expect(page).to have_content("Educate the children") + expect(page).to have_content("More schools") + + click_link("Educate the children") + click_on("Edit classification") + expect(page).to have_button("Update") + click_on("Back") + expect(page).to_not have_button("Update") + click_on("Back") + + expect(page).to_not have_content("More hospitals") + expect(page).to have_content("Educate the children") + expect(page).to have_content("More schools") end end