Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show only current budget tags in admin budget #2387

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/helpers/budgets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def current_ballot
Budget::Ballot.where(user: current_user, budget: @budget).first
end

def investment_tags_select_options
Budget::Investment.tags_on(:valuation).order(:name).select(:name).distinct
def investment_tags_select_options(budget)
Budget::Investment.where(budget_id: budget).tags_on(:valuation).order(:name).select(:name).distinct
end

def budget_published?(budget)
Expand Down
17 changes: 9 additions & 8 deletions app/views/admin/budget_investments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
class: "js-submit-on-change" } %>
</div>

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

<%= render "advanced_filters", i18n_namespace: "admin.budget_investments.index" %>

Expand Down
17 changes: 17 additions & 0 deletions spec/features/admin/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,23 @@
expect(page).to have_select("tag_name", options: ["All tags", "Hospitals", "Teachers"])
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
group_1 = create(:budget_group, budget: @budget)
group_2 = create(:budget_group, budget: @budget)
Expand Down