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>
|
<h2 class="inline-block"><%= t("valuation.budgets.index.title") %></h2>
|
||||||
|
|
||||||
<% if budget.present? %>
|
<% if budgets.any? %>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<%= render Valuation::Budgets::RowComponent.new(budget) %>
|
<%= render Valuation::Budgets::RowComponent.with_collection(budgets) %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class Valuation::Budgets::IndexComponent < ApplicationComponent
|
class Valuation::Budgets::IndexComponent < ApplicationComponent
|
||||||
attr_reader :budget
|
attr_reader :budgets
|
||||||
|
|
||||||
def initialize(budget)
|
def initialize(budgets)
|
||||||
@budget = budget
|
@budgets = budgets
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
class Valuation::Budgets::RowComponent < ApplicationComponent
|
class Valuation::Budgets::RowComponent < ApplicationComponent
|
||||||
attr_reader :budget
|
attr_reader :budget
|
||||||
|
with_collection_parameter :budget
|
||||||
|
|
||||||
delegate :current_user, to: :helpers
|
delegate :current_user, to: :helpers
|
||||||
|
|
||||||
def initialize(budget)
|
def initialize(budget:)
|
||||||
@budget = budget
|
@budget = budget
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ class Valuation::BudgetsController < Valuation::BaseController
|
|||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@budget = current_budget
|
@budgets = @budgets.published.order(created_at: :desc)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
context "Index" do
|
context "Index" do
|
||||||
scenario "Displaying budgets" do
|
scenario "Displays published budgets" do
|
||||||
budget = create(:budget)
|
create(:budget, name: "Sports")
|
||||||
visit valuation_budgets_path
|
create(:budget, name: "Draft", published: false)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
visit valuation_budgets_path
|
visit valuation_budgets_path
|
||||||
|
|
||||||
expect(page).not_to have_content(budget1.name)
|
expect(page).to have_content("Sports")
|
||||||
expect(page).not_to have_content(budget2.name)
|
expect(page).not_to have_content("Draft")
|
||||||
expect(page).to have_content(budget3.name)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "With no budgets" do
|
scenario "With no budgets" do
|
||||||
|
|||||||
Reference in New Issue
Block a user