Merge pull request #2296 from consul/feature/2278#budget_price_show_phase
New Budget's phase to publish investment prices
This commit is contained in:
@@ -228,6 +228,7 @@ FactoryBot.define do
|
||||
description_reviewing "This budget is reviewing"
|
||||
description_selecting "This budget is selecting"
|
||||
description_valuating "This budget is valuating"
|
||||
description_publishing_prices "This budget is publishing prices"
|
||||
description_balloting "This budget is balloting"
|
||||
description_reviewing_ballots "This budget is reviewing ballots"
|
||||
description_finished "This budget is finished"
|
||||
@@ -252,6 +253,10 @@ FactoryBot.define do
|
||||
phase 'valuating'
|
||||
end
|
||||
|
||||
trait :publishing_prices do
|
||||
phase 'publishing_prices'
|
||||
end
|
||||
|
||||
trait :balloting do
|
||||
phase 'balloting'
|
||||
end
|
||||
@@ -313,7 +318,6 @@ FactoryBot.define do
|
||||
selected true
|
||||
feasibility "feasible"
|
||||
valuation_finished true
|
||||
|
||||
end
|
||||
|
||||
trait :winner do
|
||||
@@ -326,6 +330,12 @@ FactoryBot.define do
|
||||
incompatible true
|
||||
end
|
||||
|
||||
trait :selected_with_price do
|
||||
selected
|
||||
price 1000
|
||||
price_explanation 'Because of reasons'
|
||||
end
|
||||
|
||||
trait :unselected do
|
||||
selected false
|
||||
feasibility "feasible"
|
||||
|
||||
@@ -418,6 +418,64 @@ feature 'Budget Investments' do
|
||||
end
|
||||
end
|
||||
|
||||
context "Show Investment's price & cost explanation" do
|
||||
|
||||
let(:investment) { create(:budget_investment, :selected_with_price, heading: heading) }
|
||||
|
||||
context "When investment with price is selected" do
|
||||
|
||||
scenario "Price & explanation is shown when Budget is on published prices phase" do
|
||||
Budget::PUBLISHED_PRICES_PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
visit budget_investment_path(budget_id: budget.id, id: investment.id)
|
||||
|
||||
expect(page).to have_content(investment.formatted_price)
|
||||
expect(page).to have_content(investment.price_explanation)
|
||||
|
||||
visit budget_investments_path(budget)
|
||||
|
||||
expect(page).to have_content(investment.formatted_price)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Price & explanation isn't shown when Budget is not on published prices phase" do
|
||||
(Budget::PHASES - Budget::PUBLISHED_PRICES_PHASES).each do |phase|
|
||||
budget.update(phase: phase)
|
||||
visit budget_investment_path(budget_id: budget.id, id: investment.id)
|
||||
|
||||
expect(page).not_to have_content(investment.formatted_price)
|
||||
expect(page).not_to have_content(investment.price_explanation)
|
||||
|
||||
visit budget_investments_path(budget)
|
||||
|
||||
expect(page).not_to have_content(investment.formatted_price)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "When investment with price is unselected" do
|
||||
|
||||
background do
|
||||
investment.update(selected: false)
|
||||
end
|
||||
|
||||
scenario "Price & explanation isn't shown for any Budget's phase" do
|
||||
Budget::PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
visit budget_investment_path(budget_id: budget.id, id: investment.id)
|
||||
|
||||
expect(page).not_to have_content(investment.formatted_price)
|
||||
expect(page).not_to have_content(investment.price_explanation)
|
||||
|
||||
visit budget_investments_path(budget)
|
||||
|
||||
expect(page).not_to have_content(investment.formatted_price)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
scenario 'Can access the community' do
|
||||
Setting['feature.community'] = true
|
||||
|
||||
@@ -477,13 +535,6 @@ feature 'Budget Investments' do
|
||||
expect(page).not_to have_content(investment.price_explanation)
|
||||
end
|
||||
|
||||
scenario "Budget in balloting phase" do
|
||||
budget.update(phase: "balloting")
|
||||
visit budget_investment_path(budget_id: budget.id, id: investment.id)
|
||||
|
||||
expect(page).to have_content("Price explanation")
|
||||
expect(page).to have_content(investment.price_explanation)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Show (unfeasible budget investment)" do
|
||||
|
||||
@@ -193,37 +193,73 @@ describe Budget::Investment do
|
||||
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
|
||||
|
||||
expect(investment.should_show_price_info?).to eq(true)
|
||||
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?).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_info?).to eq(false)
|
||||
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_explanation?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -55,6 +55,9 @@ describe Budget do
|
||||
budget.phase = "valuating"
|
||||
expect(budget).to be_valuating
|
||||
|
||||
budget.phase = "publishing_prices"
|
||||
expect(budget).to be_publishing_prices
|
||||
|
||||
budget.phase = "balloting"
|
||||
expect(budget).to be_balloting
|
||||
|
||||
@@ -81,6 +84,9 @@ describe Budget do
|
||||
budget.phase = "valuating"
|
||||
expect(budget).to be_on_hold
|
||||
|
||||
budget.phase = "publishing_prices"
|
||||
expect(budget).to be_on_hold
|
||||
|
||||
budget.phase = "balloting"
|
||||
expect(budget).not_to be_on_hold
|
||||
|
||||
@@ -107,6 +113,9 @@ describe Budget do
|
||||
budget.phase = "valuating"
|
||||
expect(budget).not_to be_balloting_or_later
|
||||
|
||||
budget.phase = "publishing_prices"
|
||||
expect(budget).not_to be_balloting_or_later
|
||||
|
||||
budget.phase = "balloting"
|
||||
expect(budget).to be_balloting_or_later
|
||||
|
||||
@@ -142,6 +151,8 @@ describe Budget do
|
||||
expect(budget.investments_orders).to eq(['random'])
|
||||
end
|
||||
it "is random and price when ballotting and reviewing ballots" do
|
||||
budget.phase = 'publishing_prices'
|
||||
expect(budget.investments_orders).to eq(['random', 'price'])
|
||||
budget.phase = 'balloting'
|
||||
expect(budget.investments_orders).to eq(['random', 'price'])
|
||||
budget.phase = 'reviewing_ballots'
|
||||
|
||||
Reference in New Issue
Block a user