Add logic to show only winner investments if budget is finished
Backported from AyuntamientoMadrid/consul
This commit is contained in:
@@ -32,7 +32,11 @@ module Budgets
|
|||||||
respond_to :html, :js
|
respond_to :html, :js
|
||||||
|
|
||||||
def index
|
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)
|
@investment_ids = @investments.pluck(:id)
|
||||||
load_investment_votes(@investments)
|
load_investment_votes(@investments)
|
||||||
|
|||||||
@@ -146,6 +146,8 @@ class Budget < ActiveRecord::Base
|
|||||||
%w{random}
|
%w{random}
|
||||||
when 'publishing_prices', 'balloting', 'reviewing_ballots'
|
when 'publishing_prices', 'balloting', 'reviewing_ballots'
|
||||||
%w{random price}
|
%w{random price}
|
||||||
|
when 'finished'
|
||||||
|
%w{random}
|
||||||
else
|
else
|
||||||
%w{random confidence_score}
|
%w{random confidence_score}
|
||||||
end
|
end
|
||||||
@@ -193,5 +195,3 @@ class Budget < ActiveRecord::Base
|
|||||||
slug.nil? || drafting?
|
slug.nil? || drafting?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -681,6 +681,20 @@ feature 'Budget Investments' do
|
|||||||
end
|
end
|
||||||
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
|
def investments_order
|
||||||
all(".budget-investment h3").collect {|i| i.text }
|
all(".budget-investment h3").collect {|i| i.text }
|
||||||
end
|
end
|
||||||
@@ -1116,6 +1130,20 @@ feature 'Budget Investments' do
|
|||||||
end
|
end
|
||||||
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 "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" }
|
it_behaves_like "imageable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" }
|
||||||
|
|||||||
Reference in New Issue
Block a user