adds valuator tags
This commit is contained in:
@@ -11,8 +11,6 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
|||||||
before_action :load_ballot, only: [:show, :index]
|
before_action :load_ballot, only: [:show, :index]
|
||||||
before_action :load_investments, only: [:index, :toggle_selection]
|
before_action :load_investments, only: [:index, :toggle_selection]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -26,6 +24,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
set_valuation_tags
|
||||||
if @investment.update(budget_investment_params)
|
if @investment.update(budget_investment_params)
|
||||||
redirect_to admin_budget_budget_investment_path(@budget, @investment, Budget::Investment.filter_params(params)),
|
redirect_to admin_budget_budget_investment_path(@budget, @investment, Budget::Investment.filter_params(params)),
|
||||||
notice: t("flash.actions.update.budget_investment")
|
notice: t("flash.actions.update.budget_investment")
|
||||||
@@ -52,7 +51,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
|||||||
|
|
||||||
def budget_investment_params
|
def budget_investment_params
|
||||||
params.require(:budget_investment)
|
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
|
end
|
||||||
|
|
||||||
def load_budget
|
def load_budget
|
||||||
@@ -72,11 +71,16 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_tags
|
def load_tags
|
||||||
@tags = ActsAsTaggableOn::Tag.budget_investment_tags
|
@tags = Budget::Investment.tags_on(:valuation).order(:name).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_ballot
|
def load_ballot
|
||||||
query = Budget::Ballot.where(user: current_user, budget: @budget)
|
query = Budget::Ballot.where(user: current_user, budget: @budget)
|
||||||
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
|
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -45,7 +45,8 @@
|
|||||||
<a class="js-add-tag-link"><%= tag.name %></a>
|
<a class="js-add-tag-link"><%= tag.name %></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<%= 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,
|
label: false,
|
||||||
placeholder: t("admin.budget_investments.edit.tags_placeholder"),
|
placeholder: t("admin.budget_investments.edit.tags_placeholder"),
|
||||||
class: 'js-tag-list' %>
|
class: 'js-tag-list' %>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<p id="tags">
|
<p id="tags">
|
||||||
<strong><%= t("admin.budget_investments.show.tags") %>:</strong>
|
<strong><%= t("admin.budget_investments.show.tags") %>:</strong>
|
||||||
|
|
||||||
<%= @investment.tags.pluck(:name).join(', ') %>
|
<%= @investment.tags_on(:valuation).pluck(:name).join(', ') %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p id="assigned_valuators">
|
<p id="assigned_valuators">
|
||||||
|
|||||||
@@ -42,10 +42,6 @@ module ActsAsTaggableOn
|
|||||||
ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings).order(:name).uniq
|
ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings).order(:name).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.budget_investment_tags
|
|
||||||
ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'Budget::Investment').includes(:taggings).order(:name).uniq
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def custom_counter_field_name_for(taggable_type)
|
def custom_counter_field_name_for(taggable_type)
|
||||||
"#{taggable_type.underscore.pluralize}_count"
|
"#{taggable_type.underscore.pluralize}_count"
|
||||||
|
|||||||
@@ -343,12 +343,14 @@ feature 'Admin budget investments' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Adds existing tags", :js do
|
scenario "Adds existing valuation tags", :js do
|
||||||
create(:budget_investment, tag_list: 'Education, Health')
|
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'
|
click_link 'Edit classification'
|
||||||
|
|
||||||
find('.js-add-tag-link', text: 'Education').click
|
find('.js-add-tag-link', text: 'Education').click
|
||||||
@@ -365,13 +367,13 @@ feature 'Admin budget investments' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Adds non existent tags" do
|
scenario "Adds non existent valuation tags" do
|
||||||
budget_investment = create(:budget_investment)
|
budget_investment = create(:budget_investment)
|
||||||
|
|
||||||
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
|
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
|
||||||
click_link 'Edit classification'
|
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'
|
click_button 'Update'
|
||||||
|
|
||||||
expect(page).to have_content 'Investment project updated succesfully.'
|
expect(page).to have_content 'Investment project updated succesfully.'
|
||||||
@@ -382,6 +384,39 @@ feature 'Admin budget investments' do
|
|||||||
end
|
end
|
||||||
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
|
scenario "Errors on update" do
|
||||||
budget_investment = create(:budget_investment)
|
budget_investment = create(:budget_investment)
|
||||||
|
|
||||||
|
|||||||
@@ -232,4 +232,34 @@ feature 'Tags' do
|
|||||||
expect(page).to_not have_content investment3.title
|
expect(page).to_not have_content investment3.title
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
Reference in New Issue
Block a user