Merge pull request #2782 from wairbut-m2c/backport-show-only-winner-investments-for-finished-budget
Backport #1571: Add logic to show only winner investments if budget is finished
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -869,6 +883,10 @@ feature 'Budget Investments' do
|
||||
expect(page).to have_content(investment.formatted_price)
|
||||
expect(page).to have_content(investment.price_explanation)
|
||||
|
||||
if budget.finished?
|
||||
investment.update(winner: true)
|
||||
end
|
||||
|
||||
visit budget_investments_path(budget)
|
||||
|
||||
expect(page).to have_content(investment.formatted_price)
|
||||
@@ -1116,6 +1134,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" }
|
||||
|
||||
@@ -299,6 +299,12 @@ feature 'Tags' do
|
||||
investment.update(selected: true, feasibility: "feasible")
|
||||
end
|
||||
|
||||
if budget.finished?
|
||||
[investment1, investment2, investment3].each do |investment|
|
||||
investment.update(selected: true, feasibility: "feasible", winner: true)
|
||||
end
|
||||
end
|
||||
|
||||
login_as(admin) if budget.drafting?
|
||||
visit budget_path(budget)
|
||||
click_link group.name
|
||||
|
||||
Reference in New Issue
Block a user