Merge pull request #1492 from consul/price-info
Price explanation only visible when budget phase is balloting and later
This commit is contained in:
@@ -245,6 +245,12 @@ class Budget
|
||||
budget.balloting?
|
||||
end
|
||||
|
||||
def should_show_price_info?
|
||||
feasible? &&
|
||||
price_explanation.present? &&
|
||||
(budget.balloting? || budget.reviewing_ballots? || budget.finished?)
|
||||
end
|
||||
|
||||
def formatted_price
|
||||
budget.formatted_amount(price)
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<p><%= investment.unfeasibility_explanation %></p>
|
||||
<% end %>
|
||||
|
||||
<% if investment.feasible? && investment.price_explanation.present? %>
|
||||
<% if investment.should_show_price_info? %>
|
||||
<h2><%= t('budgets.investments.show.price_explanation') %></h2>
|
||||
<p><%= investment.price_explanation %></p>
|
||||
<% end %>
|
||||
|
||||
@@ -188,7 +188,7 @@ feature 'Budget Investments' do
|
||||
expect(current_path).to eq(budget_investments_path(budget_id: budget.id))
|
||||
end
|
||||
|
||||
scenario 'Create spending proposal too fast' do
|
||||
scenario 'Create budget investment too fast' do
|
||||
allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(Float::INFINITY)
|
||||
|
||||
login_as(author)
|
||||
@@ -263,26 +263,40 @@ feature 'Budget Investments' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Show (feasible spending proposal)" do
|
||||
user = create(:user)
|
||||
login_as(user)
|
||||
context "Show (feasible budget investment)" do
|
||||
let(:investment) { create(:budget_investment,
|
||||
:feasible,
|
||||
:finished,
|
||||
budget: budget,
|
||||
group: group,
|
||||
heading: heading,
|
||||
price: 16,
|
||||
price_explanation: 'Every wheel is 4 euros, so total is 16')}
|
||||
|
||||
investment = create(:budget_investment,
|
||||
:feasible,
|
||||
:finished,
|
||||
budget: budget,
|
||||
group: group,
|
||||
heading: heading,
|
||||
price: 16,
|
||||
price_explanation: 'Every wheel is 4 euros, so total is 16')
|
||||
background do
|
||||
user = create(:user)
|
||||
login_as(user)
|
||||
end
|
||||
|
||||
visit budget_investment_path(budget_id: budget.id, id: investment.id)
|
||||
scenario "Budget in selecting phase" do
|
||||
budget.update(phase: "selecting")
|
||||
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)
|
||||
expect(page).to_not have_content("Unfeasibility explanation")
|
||||
expect(page).to_not have_content("Price explanation")
|
||||
expect(page).to_not 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 spending proposal)" do
|
||||
scenario "Show (unfeasible budget investment)" do
|
||||
user = create(:user)
|
||||
login_as(user)
|
||||
|
||||
@@ -302,7 +316,7 @@ feature 'Budget Investments' do
|
||||
|
||||
context "Destroy" do
|
||||
|
||||
scenario "Admin cannot destroy spending proposals" do
|
||||
scenario "Admin cannot destroy budget investments" do
|
||||
admin = create(:administrator)
|
||||
user = create(:user, :level_two)
|
||||
investment = create(:budget_investment, heading: heading, author: user)
|
||||
|
||||
@@ -144,6 +144,76 @@ describe Budget::Investment do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#should_show_vote_count?" do
|
||||
it "returns true in valuating phase" do
|
||||
budget = create(:budget, phase: "valuating")
|
||||
investment = create(:budget_investment, budget: budget)
|
||||
|
||||
expect(investment.should_show_vote_count?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false in any other phase" do
|
||||
Budget::PHASES.reject {|phase| phase == "valuating"}.each do |phase|
|
||||
budget = create(:budget, phase: phase)
|
||||
investment = create(:budget_investment, budget: budget)
|
||||
|
||||
expect(investment.should_show_vote_count?).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#should_show_ballots?" do
|
||||
it "returns true in balloting phase" do
|
||||
budget = create(:budget, phase: "balloting")
|
||||
investment = create(:budget_investment, budget: budget)
|
||||
|
||||
expect(investment.should_show_ballots?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false in any other phase" do
|
||||
Budget::PHASES.reject {|phase| phase == "balloting"}.each do |phase|
|
||||
budget = create(:budget, phase: phase)
|
||||
investment = create(:budget_investment, budget: budget)
|
||||
|
||||
expect(investment.should_show_ballots?).to eq(false)
|
||||
end
|
||||
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")
|
||||
|
||||
expect(investment.should_show_price_info?).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")
|
||||
|
||||
expect(investment.should_show_price_info?).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")
|
||||
|
||||
expect(investment.should_show_price_info?).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: "")
|
||||
|
||||
expect(investment.should_show_price_info?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "by_admin" do
|
||||
it "should return investments assigned to specific administrator" do
|
||||
investment1 = create(:budget_investment, administrator_id: 33)
|
||||
|
||||
Reference in New Issue
Block a user