From 5086314bee20ec0a61065c498c7fe8b3855a2d52 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 15 Jan 2018 20:29:49 +0100 Subject: [PATCH] Display only current budget for Valuators Before we could have multiple current budgets, as we now only have one current_budget, some specs broke. As there is no need to display multiple budgets to Valuators, only the current budget is necessary, we can remove arrays and assume that only a single budget, the current budget, is displayed to Valuators --- .../valuation/budgets_controller.rb | 8 ++-- app/views/valuation/budgets/index.html.erb | 38 ++++++++----------- spec/features/valuation/budgets_spec.rb | 15 +++----- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/app/controllers/valuation/budgets_controller.rb b/app/controllers/valuation/budgets_controller.rb index 744b0d4bf..cf99f95e3 100644 --- a/app/controllers/valuation/budgets_controller.rb +++ b/app/controllers/valuation/budgets_controller.rb @@ -5,10 +5,10 @@ class Valuation::BudgetsController < Valuation::BaseController load_and_authorize_resource def index - @budgets = @budgets.current.order(created_at: :desc).page(params[:page]) - @investments_with_valuation_open = {} - @budgets.each do |b| - @investments_with_valuation_open[b.id] = b.investments + @budget = Budget.current + if @budget.present? + @investments_with_valuation_open = {} + @investments_with_valuation_open = @budget.investments .by_valuator(current_user.valuator.try(:id)) .valuation_open .count diff --git a/app/views/valuation/budgets/index.html.erb b/app/views/valuation/budgets/index.html.erb index 6d65f9ee6..f1fd302b6 100644 --- a/app/views/valuation/budgets/index.html.erb +++ b/app/views/valuation/budgets/index.html.erb @@ -1,7 +1,5 @@

<%= t("valuation.budgets.index.title") %>

-

<%= page_entries_info @budgets %>

- @@ -12,25 +10,21 @@ - <% @budgets.each do |budget| %> - - - - - - - <% end %> + + + + + +
- <%= budget.name %> - - <%= t("budgets.phase.#{budget.phase}") %> - - <%= @investments_with_valuation_open[budget.id] %> - - <%= link_to t("valuation.budgets.index.evaluate"), - valuation_budget_budget_investments_path(budget_id: budget.id), - class: "button hollow expanded" %> -
+ <%= @budget.name %> + + <%= t("budgets.phase.#{@budget.phase}") %> + + <%= @investments_with_valuation_open %> + + <%= link_to t("valuation.budgets.index.evaluate"), + valuation_budget_budget_investments_path(budget_id: @budget.id), + class: "button hollow expanded" %> +
- -<%= paginate @budgets %> diff --git a/spec/features/valuation/budgets_spec.rb b/spec/features/valuation/budgets_spec.rb index ec3b780ab..4fd821c7e 100644 --- a/spec/features/valuation/budgets_spec.rb +++ b/spec/features/valuation/budgets_spec.rb @@ -24,18 +24,15 @@ feature 'Valuation budgets' do end scenario 'Filters by phase' do - budget1 = create(:budget) - budget2 = create(:budget, :accepting) - budget3 = create(:budget, :selecting) - budget4 = create(:budget, :balloting) - budget5 = create(:budget, :finished) + budget1 = create(:budget, :finished) + budget2 = create(:budget, :finished) + budget3 = create(:budget, :accepting) visit valuation_budgets_path - expect(page).to have_content(budget1.name) - expect(page).to have_content(budget2.name) + + expect(page).to_not have_content(budget1.name) + expect(page).to_not have_content(budget2.name) expect(page).to have_content(budget3.name) - expect(page).to have_content(budget4.name) - expect(page).not_to have_content(budget5.name) end end