Add logic to show only winner investments if budget is finished

Backported from AyuntamientoMadrid/consul
This commit is contained in:
María Checa
2018-07-17 12:53:07 +02:00
committed by Marko Lovic
parent ff9888d6fe
commit 8c69871cfa
3 changed files with 35 additions and 3 deletions

View File

@@ -32,7 +32,11 @@ module Budgets
respond_to :html, :js
def index
@investments = investments.page(params[:page]).per(10).for_render
if @budget.finished?
@investments = investments.winners.page(params[:page]).per(10).for_render
else
@investments = investments.page(params[:page]).per(10).for_render
end
@investment_ids = @investments.pluck(:id)
load_investment_votes(@investments)

View File

@@ -146,6 +146,8 @@ class Budget < ActiveRecord::Base
%w{random}
when 'publishing_prices', 'balloting', 'reviewing_ballots'
%w{random price}
when 'finished'
%w{random}
else
%w{random confidence_score}
end
@@ -193,5 +195,3 @@ class Budget < ActiveRecord::Base
slug.nil? || drafting?
end
end

View File

@@ -681,6 +681,20 @@ feature 'Budget Investments' do
end
end
scenario 'Order is random if budget is finished' do
10.times { create(:budget_investment) }
budget.update(phase: 'finished')
visit budget_investments_path(budget, heading_id: heading.id)
order = all(".budget-investment h3").collect {|i| i.text }
visit budget_investments_path(budget, heading_id: heading.id)
new_order = eq(all(".budget-investment h3").collect {|i| i.text })
expect(order).not_to eq(new_order)
end
def investments_order
all(".budget-investment h3").collect {|i| i.text }
end
@@ -1116,6 +1130,20 @@ feature 'Budget Investments' do
end
end
scenario "Only winner investments are show when budget is finished" do
3.times { create(:budget_investment, heading: heading) }
Budget::Investment.first.update(feasibility: 'feasible', selected: true, winner: true)
Budget::Investment.second.update(feasibility: 'feasible', selected: true, winner: true)
budget.update(phase: 'finished')
visit budget_investments_path(budget, heading_id: heading.id)
expect(page).to have_content("#{Budget::Investment.first.title}")
expect(page).to have_content("#{Budget::Investment.second.title}")
expect(page).not_to have_content("#{Budget::Investment.third.title}")
end
it_behaves_like "followable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" }
it_behaves_like "imageable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" }