diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index c26fa0a69..b47fd4e49 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -11,8 +11,6 @@ class Admin::BudgetInvestmentsController < Admin::BaseController before_action :load_ballot, only: [:show, :index] before_action :load_investments, only: [:index, :toggle_selection] - - def index end @@ -26,6 +24,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController end def update + set_valuation_tags if @investment.update(budget_investment_params) redirect_to admin_budget_budget_investment_path(@budget, @investment, Budget::Investment.filter_params(params)), notice: t("flash.actions.update.budget_investment") @@ -52,7 +51,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController def budget_investment_params params.require(:budget_investment) - .permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, valuator_ids: []) + .permit(:title, :description, :external_url, :heading_id, :administrator_id, :valuation_tag_list, valuator_ids: []) end def load_budget @@ -72,11 +71,16 @@ class Admin::BudgetInvestmentsController < Admin::BaseController end def load_tags - @tags = ActsAsTaggableOn::Tag.budget_investment_tags + @tags = Budget::Investment.tags_on(:valuation).order(:name).uniq end def load_ballot query = Budget::Ballot.where(user: current_user, budget: @budget) @ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize end + + def set_valuation_tags + @investment.set_tag_list_on(:valuation, budget_investment_params[:valuation_tag_list]) + params[:budget_investment] = params[:budget_investment].except(:valuation_tag_list) + end end diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index e98483772..17dd88665 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -45,7 +45,8 @@ <%= tag.name %> <% end %> - <%= f.text_field :tag_list, value: @investment.tag_list.to_s, + <%= f.text_field :valuation_tag_list, + value: @investment.tag_list_on(:valuation).sort.join(','), label: false, placeholder: t("admin.budget_investments.edit.tags_placeholder"), class: 'js-tag-list' %> diff --git a/app/views/admin/budget_investments/show.html.erb b/app/views/admin/budget_investments/show.html.erb index 3ebfd4940..a58110c94 100644 --- a/app/views/admin/budget_investments/show.html.erb +++ b/app/views/admin/budget_investments/show.html.erb @@ -19,7 +19,7 @@
diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index dc144023c..847a8c993 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -42,10 +42,6 @@ module ActsAsTaggableOn ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings).order(:name).uniq end - def self.budget_investment_tags - ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'Budget::Investment').includes(:taggings).order(:name).uniq - end - private def custom_counter_field_name_for(taggable_type) "#{taggable_type.underscore.pluralize}_count" diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 285f392f3..ede09ec4f 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -343,12 +343,14 @@ feature 'Admin budget investments' do end end - scenario "Adds existing tags", :js do - create(:budget_investment, tag_list: 'Education, Health') + scenario "Adds existing valuation tags", :js do + budget_investment1 = create(:budget_investment) + budget_investment1.set_tag_list_on(:valuation, 'Education, Health') + budget_investment1.save - budget_investment = create(:budget_investment) + budget_investment2 = create(:budget_investment) - visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment) + visit admin_budget_budget_investment_path(budget_investment2.budget, budget_investment2) click_link 'Edit classification' find('.js-add-tag-link', text: 'Education').click @@ -365,13 +367,13 @@ feature 'Admin budget investments' do end end - scenario "Adds non existent tags" do + scenario "Adds non existent valuation tags" do budget_investment = create(:budget_investment) visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment) click_link 'Edit classification' - fill_in 'budget_investment_tag_list', with: 'Refugees, Solidarity' + fill_in 'budget_investment_valuation_tag_list', with: 'Refugees, Solidarity' click_button 'Update' expect(page).to have_content 'Investment project updated succesfully.' @@ -382,6 +384,39 @@ feature 'Admin budget investments' do end end + scenario "Only displays valuation tags" do + budget_investment = create(:budget_investment, tag_list: 'Park') + budget_investment.set_tag_list_on(:valuation, 'Education') + budget_investment.save + + visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment) + + expect(page).to have_content "Education" + expect(page).to_not have_content "Park" + + click_link 'Edit classification' + + expect(page).to have_content "Education" + expect(page).to_not have_content "Park" + end + + scenario "Maintains user tags" do + budget_investment = create(:budget_investment, tag_list: 'Park') + + visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment) + + click_link 'Edit classification' + + fill_in 'budget_investment_valuation_tag_list', with: 'Refugees, Solidarity' + click_button 'Update' + + expect(page).to have_content 'Investment project updated succesfully.' + + visit budget_investment_path(budget_investment.budget, budget_investment) + expect(page).to have_content "Park" + expect(page).to_not have_content "Refugees, Solidarity" + end + scenario "Errors on update" do budget_investment = create(:budget_investment) diff --git a/spec/features/tags/budget_investments_spec.rb b/spec/features/tags/budget_investments_spec.rb index 606bd4868..2a2c3e950 100644 --- a/spec/features/tags/budget_investments_spec.rb +++ b/spec/features/tags/budget_investments_spec.rb @@ -232,4 +232,34 @@ feature 'Tags' do expect(page).to_not have_content investment3.title end end + + context "Valuation" do + + scenario "Users do not see valuator tags" do + investment = create(:budget_investment, heading: heading, tag_list: 'Park') + investment.set_tag_list_on(:valuation, 'Education') + investment.save + + visit budget_investment_path(budget, investment) + + expect(page).to have_content 'Park' + expect(page).to_not have_content 'Education' + end + + scenario "Valuators do not see user tags" do + investment = create(:budget_investment, heading: heading, tag_list: 'Park') + investment.set_tag_list_on(:valuation, 'Education') + investment.save + + admin = create(:administrator) + login_as(admin.user) + + visit admin_budget_budget_investment_path(budget, investment) + click_link 'Edit classification' + + expect(page).to have_content 'Education' + expect(page).to_not have_content 'Park' + end + + end end \ No newline at end of file