From 282b8f869705bbac14a439d74d5664e18c9c3c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= <15726+Senen@users.noreply.github.com> Date: Wed, 4 Jan 2023 13:09:58 +0100 Subject: [PATCH] Load all the published budgets in the valuation interface As now multiple budget can coexist at the same time it has sense to be able to browse all the published budgets in the valuation budgets index page. --- .../budgets/index_component.html.erb | 4 ++-- .../valuation/budgets/index_component.rb | 6 +++--- .../valuation/budgets/row_component.rb | 3 ++- .../valuation/budgets_controller.rb | 2 +- app/views/valuation/budgets/index.html.erb | 2 +- spec/system/valuation/budgets_spec.rb | 19 +++++-------------- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/app/components/valuation/budgets/index_component.html.erb b/app/components/valuation/budgets/index_component.html.erb index d4ecb28d5..81e82f745 100644 --- a/app/components/valuation/budgets/index_component.html.erb +++ b/app/components/valuation/budgets/index_component.html.erb @@ -1,6 +1,6 @@

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

-<% if budget.present? %> +<% if budgets.any? %> @@ -11,7 +11,7 @@ - <%= render Valuation::Budgets::RowComponent.new(budget) %> + <%= render Valuation::Budgets::RowComponent.with_collection(budgets) %>
<% else %> diff --git a/app/components/valuation/budgets/index_component.rb b/app/components/valuation/budgets/index_component.rb index 40138ac88..e8afdfce6 100644 --- a/app/components/valuation/budgets/index_component.rb +++ b/app/components/valuation/budgets/index_component.rb @@ -1,7 +1,7 @@ class Valuation::Budgets::IndexComponent < ApplicationComponent - attr_reader :budget + attr_reader :budgets - def initialize(budget) - @budget = budget + def initialize(budgets) + @budgets = budgets end end diff --git a/app/components/valuation/budgets/row_component.rb b/app/components/valuation/budgets/row_component.rb index 46fff464a..da8e3f107 100644 --- a/app/components/valuation/budgets/row_component.rb +++ b/app/components/valuation/budgets/row_component.rb @@ -1,9 +1,10 @@ class Valuation::Budgets::RowComponent < ApplicationComponent attr_reader :budget + with_collection_parameter :budget delegate :current_user, to: :helpers - def initialize(budget) + def initialize(budget:) @budget = budget end diff --git a/app/controllers/valuation/budgets_controller.rb b/app/controllers/valuation/budgets_controller.rb index a30ccc55e..729c39112 100644 --- a/app/controllers/valuation/budgets_controller.rb +++ b/app/controllers/valuation/budgets_controller.rb @@ -5,6 +5,6 @@ class Valuation::BudgetsController < Valuation::BaseController load_and_authorize_resource def index - @budget = current_budget + @budgets = @budgets.published.order(created_at: :desc) end end diff --git a/app/views/valuation/budgets/index.html.erb b/app/views/valuation/budgets/index.html.erb index 5f2db605c..e435d1276 100644 --- a/app/views/valuation/budgets/index.html.erb +++ b/app/views/valuation/budgets/index.html.erb @@ -1 +1 @@ -<%= render Valuation::Budgets::IndexComponent.new(@budget) %> +<%= render Valuation::Budgets::IndexComponent.new(@budgets) %> diff --git a/spec/system/valuation/budgets_spec.rb b/spec/system/valuation/budgets_spec.rb index c6683268d..88b6f52e2 100644 --- a/spec/system/valuation/budgets_spec.rb +++ b/spec/system/valuation/budgets_spec.rb @@ -7,23 +7,14 @@ describe "Valuation budgets" do end context "Index" do - scenario "Displaying budgets" do - budget = create(:budget) - visit valuation_budgets_path - - expect(page).to have_content(budget.name) - end - - scenario "Filters by phase" do - budget1 = create(:budget, :finished) - budget2 = create(:budget, :finished) - budget3 = create(:budget, :accepting) + scenario "Displays published budgets" do + create(:budget, name: "Sports") + create(:budget, name: "Draft", published: false) visit valuation_budgets_path - expect(page).not_to have_content(budget1.name) - expect(page).not_to have_content(budget2.name) - expect(page).to have_content(budget3.name) + expect(page).to have_content("Sports") + expect(page).not_to have_content("Draft") end scenario "With no budgets" do