diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 4c73f52da..7b48cad1a 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -1,5 +1,9 @@ module BudgetsHelper + def show_links_to_budget_investments(budget) + ['balloting', 'reviewing_ballots', 'finished'].include? budget.phase + end + def heading_name_and_price_html(heading, budget) content_tag :div do concat(heading.name + ' ') diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index 810c505ae..dffa56e1d 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -89,14 +89,19 @@

- <%= link_to budget_investments_path(current_budget.id) do %> - <%= t("budgets.index.investment_proyects") %> - <% end %>
+ <% show_links = show_links_to_budget_investments(current_budget) %> + <% if show_links %> + <%= link_to budget_investments_path(current_budget.id) do %> + <%= t("budgets.index.investment_proyects") %> + <% end %>
+ <% end %> <%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unfeasible') do %> <%= t("budgets.index.unfeasible_investment_proyects") %> <% end %>
- <%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unselected') do %> - <%= t("budgets.index.not_selected_investment_proyects") %> + <% if show_links %> + <%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unselected') do %> + <%= t("budgets.index.not_selected_investment_proyects") %> + <% end %> <% end %>

<% end %> diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index 71ae6805a..d391dc9be 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -4,6 +4,7 @@ feature 'Budgets' do let(:budget) { create(:budget) } let(:level_two_user) { create(:user, :level_two) } + let(:allowed_phase_list) { ['balloting', 'reviewing_ballots', 'finished'] } context 'Index' do @@ -77,6 +78,45 @@ feature 'Budgets' do expect(page).not_to have_css('div#map') end end + + scenario 'Show investment links only on balloting or later' do + + budget = create(:budget) + group = create(:budget_group, budget: budget) + heading = create(:budget_heading, group: group) + + allowed_phase_list.each do |phase| + budget.update(phase: phase) + + visit budgets_path + + expect(page).to have_content(I18n.t("budgets.index.investment_proyects")) + expect(page).to have_content(I18n.t("budgets.index.unfeasible_investment_proyects")) + expect(page).to have_content(I18n.t("budgets.index.not_selected_investment_proyects")) + end + end + + scenario 'Not show investment links earlier of balloting ' do + + budget = create(:budget) + group = create(:budget_group, budget: budget) + heading = create(:budget_heading, group: group) + phases_without_links = ['drafting','informing'] + not_allowed_phase_list = Budget::Phase::PHASE_KINDS - + phases_without_links - + allowed_phase_list + + not_allowed_phase_list.each do |phase| + budget.update(phase: phase) + + visit budgets_path + + expect(page).not_to have_content(I18n.t("budgets.index.investment_proyects")) + expect(page).to have_content(I18n.t("budgets.index.unfeasible_investment_proyects")) + expect(page).not_to have_content(I18n.t("budgets.index.not_selected_investment_proyects")) + end + end + end scenario 'Index shows only published phases' do