Merge pull request #2387 from wairbut-m2c/show_only_current_budget_tags_in_admin_budget

Show only current budget tags in admin budget
This commit is contained in:
Raimond Garcia
2018-01-29 20:14:10 +01:00
committed by GitHub
3 changed files with 28 additions and 10 deletions

View File

@@ -52,8 +52,8 @@ module BudgetsHelper
Budget::Ballot.where(user: current_user, budget: @budget).first Budget::Ballot.where(user: current_user, budget: @budget).first
end end
def investment_tags_select_options def investment_tags_select_options(budget)
Budget::Investment.tags_on(:valuation).order(:name).select(:name).distinct Budget::Investment.where(budget_id: budget).tags_on(:valuation).order(:name).select(:name).distinct
end end
def budget_published?(budget) def budget_published?(budget)

View File

@@ -27,14 +27,15 @@
class: "js-submit-on-change" } %> class: "js-submit-on-change" } %>
</div> </div>
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<%= select_tag :tag_name, <%= select_tag :tag_name,
options_for_select(investment_tags_select_options, params[:tag_name]), options_for_select(investment_tags_select_options(@budget), params[:tag_name]),
{ prompt: t("admin.budget_investments.index.tags_filter_all"), { prompt: t("admin.budget_investments.index.tags_filter_all"),
label: false, label: false,
class: "js-submit-on-change" } %> class: "js-submit-on-change" } %>
</div> </div>
<% end %> <% end %>
</div>
<%= render "advanced_filters", i18n_namespace: "admin.budget_investments.index" %> <%= render "advanced_filters", i18n_namespace: "admin.budget_investments.index" %>

View File

@@ -281,6 +281,23 @@ feature 'Admin budget investments' do
expect(page).to have_select("tag_name", options: ["All tags", "Hospitals", "Teachers"]) expect(page).to have_select("tag_name", options: ["All tags", "Hospitals", "Teachers"])
end end
scenario "Filtering by tag, display only valuation tags of the current budget" do
new_budget = create(:budget)
investment1 = create(:budget_investment, budget: @budget, tag_list: 'Roads')
investment2 = create(:budget_investment, budget: new_budget, tag_list: 'Accessibility')
investment1.set_tag_list_on(:valuation, 'Roads')
investment2.set_tag_list_on(:valuation, 'Accessibility')
investment1.save
investment2.save
visit admin_budget_budget_investments_path(budget_id: @budget.id)
expect(page).to have_select("tag_name", options: ["All tags", "Roads"])
expect(page).not_to have_select("tag_name", options: ["All tags", "Accessibility"])
end
scenario "Limiting by max number of investments per heading", :js do scenario "Limiting by max number of investments per heading", :js do
group_1 = create(:budget_group, budget: @budget) group_1 = create(:budget_group, budget: @budget)
group_2 = create(:budget_group, budget: @budget) group_2 = create(:budget_group, budget: @budget)