Skip to content

Commit

Permalink
Increase Budget Investment model spec for should_show_price & explant…
Browse files Browse the repository at this point in the history
…ion methods
  • Loading branch information
bertocq committed Jan 10, 2018
1 parent f3a7de5 commit 3563b87
Showing 1 changed file with 54 additions and 18 deletions.
72 changes: 54 additions & 18 deletions spec/models/budget/investment_spec.rb
Expand Up @@ -193,37 +193,73 @@
end
end

describe "#should_show_price_info?" do
it "returns true for feasibles if phase is balloting or later and price_explanation is present" do
["balloting", "reviewing_ballots", "finished"].each do |phase|
budget = create(:budget, phase: phase)
investment = create(:budget_investment, :feasible, budget: budget, price_explanation: "price explanation")
describe "#should_show_price?" do
let(:budget) { create(:budget, :publishing_prices) }
let(:investment) do
create(:budget_investment, :selected, budget: budget)
end

it "returns true for selected investments which budget's phase is publishing_prices or later" do
Budget::PUBLISHED_PRICES_PHASES.each do |phase|
budget.update(phase: phase)

expect(investment.should_show_price_info?).to eq(true)
expect(investment.should_show_price?).to eq(true)
end
end

it "returns false in any other phase" do
(Budget::PHASES - ["balloting", "reviewing_ballots", "finished"]).each do |phase|
budget = create(:budget, phase: phase)
investment = create(:budget_investment, :feasible, budget: budget, price_explanation: "price explanation")
(Budget::PHASES - Budget::PUBLISHED_PRICES_PHASES).each do |phase|
budget.update(phase: phase)

expect(investment.should_show_price_info?).to eq(false)
expect(investment.should_show_price?).to eq(false)
end
end

it "returns false if investment is unfeasible" do
budget = create(:budget, phase: "balloting")
investment = create(:budget_investment, :unfeasible, budget: budget, price_explanation: "price explanation")
it "returns false if investment is not selected" do
investment.selected = false

expect(investment.should_show_price_info?).to eq(false)
expect(investment.should_show_price?).to eq(false)
end

it "returns false if price_explanation is blank" do
budget = create(:budget, phase: "balloting")
investment = create(:budget_investment, :unfeasible, budget: budget, price_explanation: "")
it "returns false if price is not present" do
investment.price = nil

expect(investment.should_show_price?).to eq(false)
end
end

describe "#should_show_price_explanation?" do
let(:budget) { create(:budget, :publishing_prices) }
let(:investment) do
create(:budget_investment, :selected, budget: budget, price_explanation: "because of reasons")
end

it "returns true for selected with price_explanation & budget in publishing_prices or later" do
Budget::PUBLISHED_PRICES_PHASES.each do |phase|
budget.update(phase: phase)

expect(investment.should_show_price_explanation?).to eq(true)
end
end

it "returns false in any other phase" do
(Budget::PHASES - Budget::PUBLISHED_PRICES_PHASES).each do |phase|
budget.update(phase: phase)

expect(investment.should_show_price_explanation?).to eq(false)
end
end

it "returns false if investment is not selected" do
investment.selected = false

expect(investment.should_show_price_explanation?).to eq(false)
end

it "returns false if price_explanation is not present" do
investment.price_explanation = ""

expect(investment.should_show_price_info?).to eq(false)
expect(investment.should_show_price_explanation?).to eq(false)
end
end

Expand Down

0 comments on commit 3563b87

Please sign in to comment.