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:
@@ -3,8 +3,11 @@ class Budget < ActiveRecord::Base
|
||||
include Measurable
|
||||
include Sluggable
|
||||
|
||||
PHASES = %w(drafting accepting reviewing selecting valuating balloting
|
||||
reviewing_ballots finished).freeze
|
||||
PHASES = %w(drafting accepting reviewing selecting valuating publishing_prices
|
||||
balloting reviewing_ballots finished).freeze
|
||||
ON_HOLD_PHASES = %w(reviewing valuating publishing_prices reviewing_ballots).freeze
|
||||
PUBLISHED_PRICES_PHASES = %w(publishing_prices balloting reviewing_ballots finished).freeze
|
||||
|
||||
CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze
|
||||
|
||||
validates :name, presence: true, uniqueness: true
|
||||
@@ -19,12 +22,13 @@ class Budget < ActiveRecord::Base
|
||||
|
||||
before_validation :sanitize_descriptions
|
||||
|
||||
scope :on_hold, -> { where(phase: %w(reviewing valuating reviewing_ballots")) }
|
||||
scope :on_hold, -> { where(phase: ON_HOLD_PHASES) }
|
||||
scope :drafting, -> { where(phase: "drafting") }
|
||||
scope :accepting, -> { where(phase: "accepting") }
|
||||
scope :reviewing, -> { where(phase: "reviewing") }
|
||||
scope :selecting, -> { where(phase: "selecting") }
|
||||
scope :valuating, -> { where(phase: "valuating") }
|
||||
scope :publishing_prices, -> { where(phase: "publishing_prices") }
|
||||
scope :balloting, -> { where(phase: "balloting") }
|
||||
scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") }
|
||||
scope :finished, -> { where(phase: "finished") }
|
||||
@@ -63,6 +67,10 @@ class Budget < ActiveRecord::Base
|
||||
phase == "valuating"
|
||||
end
|
||||
|
||||
def publishing_prices?
|
||||
phase == "publishing_prices"
|
||||
end
|
||||
|
||||
def balloting?
|
||||
phase == "balloting"
|
||||
end
|
||||
@@ -75,6 +83,10 @@ class Budget < ActiveRecord::Base
|
||||
phase == "finished"
|
||||
end
|
||||
|
||||
def published_prices?
|
||||
PUBLISHED_PRICES_PHASES.include?(phase)
|
||||
end
|
||||
|
||||
def balloting_process?
|
||||
balloting? || reviewing_ballots?
|
||||
end
|
||||
@@ -84,7 +96,7 @@ class Budget < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def on_hold?
|
||||
reviewing? || valuating? || reviewing_ballots?
|
||||
ON_HOLD_PHASES.include?(phase)
|
||||
end
|
||||
|
||||
def current?
|
||||
@@ -118,7 +130,7 @@ class Budget < ActiveRecord::Base
|
||||
case phase
|
||||
when 'accepting', 'reviewing'
|
||||
%w{random}
|
||||
when 'balloting', 'reviewing_ballots'
|
||||
when 'publishing_prices', 'balloting', 'reviewing_ballots'
|
||||
%w{random price}
|
||||
else
|
||||
%w{random confidence_score}
|
||||
|
||||
@@ -240,15 +240,11 @@ class Budget
|
||||
end
|
||||
|
||||
def should_show_price?
|
||||
feasible? &&
|
||||
selected? &&
|
||||
(budget.reviewing_ballots? || budget.finished?)
|
||||
selected? && price.present? && budget.published_prices?
|
||||
end
|
||||
|
||||
def should_show_price_info?
|
||||
feasible? &&
|
||||
price_explanation.present? &&
|
||||
(budget.balloting? || budget.reviewing_ballots? || budget.finished?)
|
||||
def should_show_price_explanation?
|
||||
should_show_price? && price_explanation.present?
|
||||
end
|
||||
|
||||
def formatted_price
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
<p><%= investment.unfeasibility_explanation %></p>
|
||||
<% end %>
|
||||
|
||||
<% if investment.should_show_price_info? %>
|
||||
<% if investment.should_show_price_explanation? %>
|
||||
<h2><%= t('budgets.investments.show.price_explanation') %></h2>
|
||||
<p><%= investment.price_explanation %></p>
|
||||
<% end %>
|
||||
|
||||
@@ -34,6 +34,7 @@ en:
|
||||
reviewing: Reviewing projects
|
||||
selecting: Selecting projects
|
||||
valuating: Valuating projects
|
||||
publishing_prices: Publishing projects prices
|
||||
balloting: Balloting projects
|
||||
reviewing_ballots: Reviewing Ballots
|
||||
finished: Finished budget
|
||||
|
||||
@@ -34,6 +34,7 @@ es:
|
||||
reviewing: Revisión interna de proyectos
|
||||
selecting: Fase de apoyos
|
||||
valuating: Evaluación de proyectos
|
||||
publishing_prices: Publicación de precios
|
||||
balloting: Votación final
|
||||
reviewing_ballots: Votación finalizada
|
||||
finished: Resultados
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddPublishingPricesPhaseToBudget < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :budgets, :description_publishing_prices, :text
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20180108182839) do
|
||||
ActiveRecord::Schema.define(version: 20180109175851) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -202,6 +202,7 @@ ActiveRecord::Schema.define(version: 20180108182839) do
|
||||
t.text "description_finished"
|
||||
t.string "slug"
|
||||
t.text "description_drafting"
|
||||
t.text "description_publishing_prices"
|
||||
end
|
||||
|
||||
create_table "campaigns", force: :cascade do |t|
|
||||
|
||||
@@ -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