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.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<h2 class="inline-block"><%= t("valuation.budgets.index.title") %></h2>
|
||||
|
||||
<% if budget.present? %>
|
||||
<% if budgets.any? %>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -11,7 +11,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= render Valuation::Budgets::RowComponent.new(budget) %>
|
||||
<%= render Valuation::Budgets::RowComponent.with_collection(budgets) %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1 +1 @@
|
||||
<%= render Valuation::Budgets::IndexComponent.new(@budget) %>
|
||||
<%= render Valuation::Budgets::IndexComponent.new(@budgets) %>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user