Allow printing investments from any budget in the management interface
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<% budgets.each do |budget| %>
|
||||||
<tr id="<%= dom_id(budget) %>">
|
<tr id="<%= dom_id(budget) %>">
|
||||||
<td><%= budget.name %></td>
|
<td><%= budget.name %></td>
|
||||||
<td><%= budget.current_phase.name %></td>
|
<td><%= budget.current_phase.name %></td>
|
||||||
@@ -15,5 +16,8 @@
|
|||||||
print_management_budget_investments_path(budget) %>
|
print_management_budget_investments_path(budget) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<%= paginate budgets %>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class Management::Budgets::PrintInvestments::TableComponent < ApplicationComponent
|
class Management::Budgets::PrintInvestments::TableComponent < ApplicationComponent
|
||||||
attr_reader :budget
|
attr_reader :budgets
|
||||||
|
delegate :paginate, to: :helpers
|
||||||
|
|
||||||
def initialize(budget)
|
def initialize(budgets)
|
||||||
@budget = budget
|
@budgets = budgets
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,10 +49,6 @@ class Management::BaseController < ActionController::Base
|
|||||||
I18n.with_locale(session[:locale], &action)
|
I18n.with_locale(session[:locale], &action)
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_budget
|
|
||||||
Budget.current
|
|
||||||
end
|
|
||||||
|
|
||||||
def clear_password
|
def clear_password
|
||||||
session[:new_password] = nil
|
session[:new_password] = nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Management::BudgetsController < Management::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def print_investments
|
def print_investments
|
||||||
@budget = current_budget
|
@budgets = Budget.published.order(created_at: :desc).page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
<h2><%= t("management.budgets.print_investments") %></h2>
|
<h2><%= t("management.budgets.print_investments") %></h2>
|
||||||
|
|
||||||
<%= render Management::Budgets::PrintInvestments::TableComponent.new(@budget) %>
|
<% if @budgets.any? %>
|
||||||
|
<%= render Management::Budgets::PrintInvestments::TableComponent.new(@budgets) %>
|
||||||
|
<% else %>
|
||||||
|
<div class="callout primary">
|
||||||
|
<%= t("management.budgets.no_budgets") %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|||||||
@@ -407,6 +407,51 @@ describe "Budget Investments" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "Printing" do
|
context "Printing" do
|
||||||
|
scenario "Shows all published budgets, last created first" do
|
||||||
|
finished_budget = create(:budget, :finished)
|
||||||
|
accepting_budget = create(:budget)
|
||||||
|
draft_budget = create(:budget, published: false)
|
||||||
|
login_as_manager(manager)
|
||||||
|
|
||||||
|
click_link "Print budget investments"
|
||||||
|
|
||||||
|
within "#budget_#{accepting_budget.id}" do
|
||||||
|
expect(page).to have_link("Print budget investments")
|
||||||
|
end
|
||||||
|
within "#budget_#{finished_budget.id}" do
|
||||||
|
expect(page).to have_link("Print budget investments")
|
||||||
|
end
|
||||||
|
expect(page).not_to have_content draft_budget.name
|
||||||
|
expect(accepting_budget.name).to appear_before(finished_budget.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Shows a message when there are no budgets to show" do
|
||||||
|
login_as_manager(manager)
|
||||||
|
|
||||||
|
click_link "Print budget investments"
|
||||||
|
|
||||||
|
expect(page).to have_content("There are no active participatory budgets.")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Show pagination when needed" do
|
||||||
|
allow(Budget).to receive(:default_per_page).and_return(1)
|
||||||
|
create(:budget, name: "Children")
|
||||||
|
create(:budget, name: "Sports")
|
||||||
|
login_as_manager(manager)
|
||||||
|
click_link "Print budget investments"
|
||||||
|
|
||||||
|
expect(page).to have_content("Sports")
|
||||||
|
|
||||||
|
within("ul.pagination") do
|
||||||
|
expect(page).to have_content("1")
|
||||||
|
expect(page).to have_link("2", href: print_investments_management_budgets_path(page: "2"))
|
||||||
|
expect(page).not_to have_content("3")
|
||||||
|
click_link "Next", exact: false
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content("Children")
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Printing budget investments" do
|
scenario "Printing budget investments" do
|
||||||
16.times { create(:budget_investment, heading: heading) }
|
16.times { create(:budget_investment, heading: heading) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user