Makes all tests pass in bi management
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
class Management::Budgets::InvestmentsController < Management::BaseController
|
class Management::Budgets::InvestmentsController < Management::BaseController
|
||||||
|
|
||||||
load_and_authorize_resource :budget
|
load_resource :budget
|
||||||
load_and_authorize_resource :investment, through: :budget, class: 'Budget::Investment'
|
load_resource :investment, through: :budget, class: 'Budget::Investment'
|
||||||
|
|
||||||
before_action :only_verified_users, except: :print
|
before_action :only_verified_users, except: :print
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def print
|
def print
|
||||||
params[:geozone] ||= 'all'
|
|
||||||
@investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).for_render.limit(15)
|
@investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).for_render.limit(15)
|
||||||
|
set_investment_votes(@investments)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -45,31 +45,19 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
|||||||
@investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {}
|
@investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_budget
|
|
||||||
@budget = Budget.find(params[:budget_id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def investment_params
|
def investment_params
|
||||||
params.require(:budget_investment).permit(:title, :description, :external_url, :geozone_id, :heading_id)
|
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def only_verified_users
|
def only_verified_users
|
||||||
check_verified_user t("management.budget_investments.alert.unverified_user")
|
check_verified_user t("management.budget_investments.alert.unverified_user")
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_geozone_name
|
|
||||||
if params[:geozone] == 'all'
|
|
||||||
@geozone_name = t('geozones.none')
|
|
||||||
else
|
|
||||||
@geozone_name = Geozone.find(params[:geozone]).name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def apply_filters_and_search(investments)
|
def apply_filters_and_search(investments)
|
||||||
investments = params[:unfeasible].present? ? investments.unfeasible : investments.not_unfeasible
|
investments = params[:unfeasible].present? ? investments.unfeasible : investments.not_unfeasible
|
||||||
if params[:geozone].present?
|
if params[:heading_id].present?
|
||||||
investments = investments.by_geozone(params[:geozone])
|
investments = investments.by_heading(params[:heading_id])
|
||||||
set_geozone_name
|
@heading = Budget::Heading.find(params[:heading_id])
|
||||||
end
|
end
|
||||||
investments = investments.search(params[:search]) if params[:search].present?
|
investments = investments.search(params[:search]) if params[:search].present?
|
||||||
investments
|
investments
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
module BudgetHeadingsHelper
|
module BudgetHeadingsHelper
|
||||||
|
|
||||||
def budget_heading_select_options(budget)
|
def budget_heading_select_options(budget)
|
||||||
budget.headings.includes(:group).order('budget_groups.name', 'budget_headings.name').map do |heading|
|
budget.headings.order_by_group_name.map do |heading|
|
||||||
["#{heading.group.name}: #{heading.name}", heading.id]
|
[heading.name_scoped_by_group, heading.id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ class Budget
|
|||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :price, presence: true
|
validates :price, presence: true
|
||||||
|
|
||||||
|
scope :order_by_group_name, -> { includes(:group).order('budget_groups.name', 'budget_headings.name') }
|
||||||
|
|
||||||
def budget
|
def budget
|
||||||
group.budget
|
group.budget
|
||||||
end
|
end
|
||||||
@@ -17,5 +19,9 @@ class Budget
|
|||||||
group.budget = resource
|
group.budget = resource
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def name_scoped_by_group
|
||||||
|
"#{group.name}: #{name}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
<%= form_for(Budget::Investment.new, url: url, as: :budget_investment, method: :get) do |f| %>
|
<%= form_for(Budget::Investment.new, url: url, as: :budget_investment, method: :get) do |f| %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<%= text_field_tag :search, "", placeholder: t("admin.shared.budget_investment_search.placeholder") %>
|
<%= text_field_tag :search, "" %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<%= select_tag :heading_id,
|
||||||
|
options_for_select(budget_heading_select_options(@budget),
|
||||||
|
params[:heading_id]),
|
||||||
|
include_blank: true
|
||||||
|
%>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<%= check_box_tag :unfeasible, "1", params[:unfeasible].present? %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
<div class="form-inline small-12 medium-3 column end">
|
<div class="form-inline small-12 medium-3 column end">
|
||||||
<%= f.submit t("shared.search"), class: "button" %>
|
<%= f.submit t("shared.search"), class: "button" %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,29 +1,35 @@
|
|||||||
<main>
|
<main>
|
||||||
<div class="row">
|
<span class="not-print">
|
||||||
|
<%= render 'admin/shared/budget_investment_search', url: print_management_budget_investments_path(@budget) %>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div class="wrap row">
|
||||||
<div id="budget-investments" class="budget-investments-list small-12 column">
|
<div id="budget-investments" class="budget-investments-list small-12 column">
|
||||||
|
|
||||||
<div class="not-print">
|
<div class="not-print">
|
||||||
<%= form_tag print_management_budget_investments_path, method: :get, enforce_utf8: false do %>
|
|
||||||
<div class="small-12 medium-4 column float-left">
|
|
||||||
<%= select_tag :geozone,
|
|
||||||
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone]),
|
|
||||||
{ label: false,
|
|
||||||
class: "js-submit-on-change" } %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<a id="print_link" href="javascript:window.print();" class="button warning float-right">
|
<a id="print_link" href="javascript:window.print();" class="button warning float-right">
|
||||||
<%= t('management.budget_investments.print.print_button') %>
|
<%= t('management.budget_investments.print.print_button') %>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 search-results">
|
<div class="small-12 search-results">
|
||||||
<%= content_tag(:h2, t("management.budget_investments.filters.unfeasible"), class: "inline-block") if params[:unfeasible].present? %>
|
<% if params[:unfeasible].present? %>
|
||||||
<%= content_tag(:h2, t("management.budget_investments.filters.by_geozone", geozone: @geozone_name), class: "inline-block") if @geozone_name.present? %>
|
<h2 class="inline-block"><%= t("management.budget_investments.filters.unfeasible") %></h2>
|
||||||
<%= content_tag(:h2, t("management.budget_investments.search_results", count: @budget_investments.size, search_term: params[:search]), class: "inline-block") if params[:search].present? %>
|
<% end %>
|
||||||
|
<% if @heading.present? %>
|
||||||
|
<h2 class="inline-block"><%= t("management.budget_investments.filters.heading", heading_name: @heading.name) %></h2>
|
||||||
|
<% end %>
|
||||||
|
<h2 class="inline-block"><%= t("management.budget_investments.search_results", count: @investments.count, search_term: params[:search]) %></h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render @budget_investments %>
|
<% @investments.each do |investment| %>
|
||||||
|
<%= render partial: '/budgets/investments/investment', locals: {
|
||||||
|
investment: investment,
|
||||||
|
investment_ids: @investment_ids,
|
||||||
|
investment_votes: @investment_votes,
|
||||||
|
investment_ballots: @investment_ballots
|
||||||
|
} %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="for-print-only">
|
<div class="for-print-only">
|
||||||
<p><strong><%= t("management.print.budget_investments_info") %></strong><br>
|
<p><strong><%= t("management.print.budget_investments_info") %></strong><br>
|
||||||
|
|||||||
@@ -435,6 +435,7 @@ es:
|
|||||||
flag: Denunciar como inapropiado
|
flag: Denunciar como inapropiado
|
||||||
print:
|
print:
|
||||||
print_button: Imprimir esta información
|
print_button: Imprimir esta información
|
||||||
|
search: Buscar
|
||||||
show: Mostrar
|
show: Mostrar
|
||||||
suggest:
|
suggest:
|
||||||
debate:
|
debate:
|
||||||
|
|||||||
@@ -202,45 +202,41 @@ feature 'Budget Investments' do
|
|||||||
scenario 'Printing budget investments' do
|
scenario 'Printing budget investments' do
|
||||||
16.times { create(:budget_investment, budget: @budget) }
|
16.times { create(:budget_investment, budget: @budget) }
|
||||||
|
|
||||||
click_link "Print budget investments"
|
click_link "Print Budget Investments"
|
||||||
expect(page).to have_content(@budget.name)
|
expect(page).to have_content(@budget.name)
|
||||||
within "#budget_#{@budget.id}" do
|
within "#budget_#{@budget.id}" do
|
||||||
click_link "Support Budget Investments"
|
click_link "Print Budget Investments"
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_css('.budget-investment', count: 15)
|
expect(page).to have_css('.budget-investment', count: 15)
|
||||||
expect(page).to have_css("a[href='javascript:window.print();']", text: 'Print')
|
expect(page).to have_css("a[href='javascript:window.print();']", text: 'Print')
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Filtering budget investments by geozone to be printed", :js do
|
scenario "Filtering budget investments by heading to be printed", :js do
|
||||||
district_9 = create(:budget_heading, group: @group, name: "District Nine")
|
district_9 = create(:budget_heading, group: @group, name: "District Nine")
|
||||||
create(:budget_investment, budget: @budget, title: 'Change district 9', heading: district_9, cached_votes_up: 10)
|
create(:budget_investment, budget: @budget, title: 'Change district 9', heading: district_9, cached_votes_up: 10)
|
||||||
create(:budget_investment, budget: @budget, title: 'Destroy district 9', heading: district_9, cached_votes_up: 100)
|
create(:budget_investment, budget: @budget, title: 'Destroy district 9', heading: district_9, cached_votes_up: 100)
|
||||||
create(:budget_investment, budget: @budget, title: 'Nuke district 9', heading: district_9, cached_votes_up: 1)
|
create(:budget_investment, budget: @budget, title: 'Nuke district 9', heading: district_9, cached_votes_up: 1)
|
||||||
create(:budget_investment, budget: @budget, title: 'Add new districts to the city', heading: @heading)
|
create(:budget_investment, budget: @budget, title: 'Add new districts to the city')
|
||||||
|
|
||||||
user = create(:user, :level_two)
|
user = create(:user, :level_two)
|
||||||
login_managed_user(user)
|
login_managed_user(user)
|
||||||
|
|
||||||
click_link "Print budget investments"
|
click_link "Print Budget Investments"
|
||||||
expect(page).to have_content(@budget.name)
|
expect(page).to have_content(@budget.name)
|
||||||
within "#budget_#{@budget.id}" do
|
within "#budget_#{@budget.id}" do
|
||||||
click_link "Support Budget Investments"
|
click_link "Print Budget Investments"
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_content "Budget investments with scope: All city"
|
|
||||||
|
|
||||||
within '#budget-investments' do
|
within '#budget-investments' do
|
||||||
expect(page).to have_content('Add new districts to the city')
|
expect(page).to have_content('Add new districts to the city')
|
||||||
expect(page).to_not have_content('Change district 9')
|
expect(page).to have_content('Change district 9')
|
||||||
expect(page).to_not have_content('Destroy district 9')
|
expect(page).to have_content('Destroy district 9')
|
||||||
expect(page).to_not have_content('Nuke district 9')
|
expect(page).to have_content('Nuke district 9')
|
||||||
end
|
end
|
||||||
|
|
||||||
select 'District Nine', from: 'geozone'
|
select 'Whole city: District Nine', from: 'heading_id'
|
||||||
|
click_button("Search")
|
||||||
expect(page).to have_content "Investment projects with scope: District Nine"
|
|
||||||
expect(current_url).to include("geozone=#{district_9.id}")
|
|
||||||
|
|
||||||
within '#budget-investments' do
|
within '#budget-investments' do
|
||||||
expect(page).to_not have_content('Add new districts to the city')
|
expect(page).to_not have_content('Add new districts to the city')
|
||||||
|
|||||||
Reference in New Issue
Block a user