adds budget result specs
This commit is contained in:
48
spec/features/budgets/results_spec.rb
Normal file
48
spec/features/budgets/results_spec.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Results' do
|
||||
|
||||
let(:budget) { create(:budget, phase: "finished") }
|
||||
let(:group) { create(:budget_group, budget: budget) }
|
||||
let(:heading) { create(:budget_heading, group: group, price: 1000) }
|
||||
|
||||
let!(:investment1) { create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900) }
|
||||
let!(:investment2) { create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800) }
|
||||
let!(:investment3) { create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 700) }
|
||||
let!(:investment4) { create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 600) }
|
||||
|
||||
let!(:results) { Budget::Result.new(budget, heading).calculate_winners }
|
||||
|
||||
scenario "Diplays winner investments", :focus do
|
||||
visit budget_path(budget)
|
||||
click_link "Results"
|
||||
|
||||
within("#budget-investments-results") do
|
||||
expect(page).to have_content investment1.title
|
||||
expect(page).to have_content investment2.title
|
||||
expect(page).to have_content investment3.title
|
||||
expect(page).to_not have_content investment4.title
|
||||
|
||||
expect(investment1.title).to appear_before(investment2.title)
|
||||
expect(investment2.title).to appear_before(investment3.title)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Displays non winner investments", :js, :focus do
|
||||
visit budget_path(budget)
|
||||
click_link "Results"
|
||||
click_link "Show all"
|
||||
|
||||
within("#budget-investments-results") do
|
||||
expect(page).to have_content investment1.title
|
||||
expect(page).to have_content investment2.title
|
||||
expect(page).to have_content investment3.title
|
||||
expect(page).to have_content investment4.title
|
||||
|
||||
expect(investment1.title).to appear_before(investment2.title)
|
||||
expect(investment2.title).to appear_before(investment3.title)
|
||||
expect(investment3.title).to appear_before(investment4.title)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
35
spec/models/budget/result_spec.rb
Normal file
35
spec/models/budget/result_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Budget::Result, :focus do
|
||||
|
||||
describe "calculate_winners" do
|
||||
let(:budget) { create(:budget) }
|
||||
let(:group) { create(:budget_group, budget: budget) }
|
||||
let(:heading) { create(:budget_heading, group: group, price: 1000) }
|
||||
|
||||
it "calculates a budget's winner investments" do
|
||||
investment1 = create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900)
|
||||
investment2 = create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800)
|
||||
investment3 = create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 700)
|
||||
investment4 = create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 600)
|
||||
|
||||
result = Budget::Result.new(budget, heading)
|
||||
result.calculate_winners
|
||||
|
||||
expect(result.winners).to eq([investment1, investment2, investment3])
|
||||
end
|
||||
|
||||
it "resets winners before recalculating" do
|
||||
investment1 = create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900, winner: true)
|
||||
investment2 = create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800, winner: true)
|
||||
investment3 = create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 700, winner: true)
|
||||
investment4 = create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 600, winner: true)
|
||||
|
||||
result = Budget::Result.new(budget, heading)
|
||||
result.calculate_winners
|
||||
|
||||
expect(result.winners).to eq([investment1, investment2, investment3])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user