diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 293f4797a..ca2bf7dc4 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -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) diff --git a/app/models/budget.rb b/app/models/budget.rb index a79746615..3f4bed9a1 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -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 - - diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 1b0f7f31f..9b1dc7d56 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -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" }