Adds sanitized descriptions for all phases to budget model
This commit is contained in:
@@ -27,6 +27,10 @@ class Budget < ActiveRecord::Base
|
|||||||
|
|
||||||
scope :current, -> { where.not(phase: "finished") }
|
scope :current, -> { where.not(phase: "finished") }
|
||||||
|
|
||||||
|
def description
|
||||||
|
self.send("description_#{self.phase}").try(:html_safe)
|
||||||
|
end
|
||||||
|
|
||||||
def accepting?
|
def accepting?
|
||||||
phase == "accepting"
|
phase == "accepting"
|
||||||
end
|
end
|
||||||
|
|||||||
12
db/migrate/20161230174744_change_budget_description.rb
Normal file
12
db/migrate/20161230174744_change_budget_description.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class ChangeBudgetDescription < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
remove_column :budgets, :description, :text
|
||||||
|
add_column :budgets, :description_accepting, :text
|
||||||
|
add_column :budgets, :description_reviewing, :text
|
||||||
|
add_column :budgets, :description_selecting, :text
|
||||||
|
add_column :budgets, :description_valuating, :text
|
||||||
|
add_column :budgets, :description_balloting, :text
|
||||||
|
add_column :budgets, :description_reviewing_ballots, :text
|
||||||
|
add_column :budgets, :description_finished, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
20
db/schema.rb
20
db/schema.rb
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20161230172816) do
|
ActiveRecord::Schema.define(version: 20161230174744) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -160,12 +160,18 @@ ActiveRecord::Schema.define(version: 20161230172816) do
|
|||||||
add_index "budget_valuator_assignments", ["investment_id"], name: "index_budget_valuator_assignments_on_investment_id", using: :btree
|
add_index "budget_valuator_assignments", ["investment_id"], name: "index_budget_valuator_assignments_on_investment_id", using: :btree
|
||||||
|
|
||||||
create_table "budgets", force: :cascade do |t|
|
create_table "budgets", force: :cascade do |t|
|
||||||
t.string "name", limit: 30
|
t.string "name", limit: 30
|
||||||
t.text "description"
|
t.string "currency_symbol", limit: 10
|
||||||
t.string "currency_symbol", limit: 10
|
t.string "phase", limit: 15, default: "on_hold"
|
||||||
t.string "phase", limit: 15, default: "on_hold"
|
t.datetime "created_at", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.text "description_accepting"
|
||||||
|
t.text "description_reviewing"
|
||||||
|
t.text "description_selecting"
|
||||||
|
t.text "description_valuating"
|
||||||
|
t.text "description_balloting"
|
||||||
|
t.text "description_reviewing_ballots"
|
||||||
|
t.text "description_finished"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "campaigns", force: :cascade do |t|
|
create_table "campaigns", force: :cascade do |t|
|
||||||
|
|||||||
@@ -196,6 +196,13 @@ FactoryGirl.define do
|
|||||||
sequence(:name) { |n| "Budget #{n}" }
|
sequence(:name) { |n| "Budget #{n}" }
|
||||||
currency_symbol "€"
|
currency_symbol "€"
|
||||||
phase 'accepting'
|
phase 'accepting'
|
||||||
|
description_accepting "This budget is accepting"
|
||||||
|
description_reviewing "This budget is reviewing"
|
||||||
|
description_selecting "This budget is selecting"
|
||||||
|
description_valuating "This budget is valuating"
|
||||||
|
description_balloting "This budget is balloting"
|
||||||
|
description_reviewing_ballots "This budget is reviewing ballots"
|
||||||
|
description_finished "This budget is finished"
|
||||||
|
|
||||||
trait :accepting do
|
trait :accepting do
|
||||||
phase 'accepting'
|
phase 'accepting'
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Budget do
|
describe Budget do
|
||||||
|
|
||||||
|
describe "description" do
|
||||||
|
it "changes depending on the phase" do
|
||||||
|
budget = create(:budget)
|
||||||
|
|
||||||
|
Budget::VALID_PHASES.each do |phase|
|
||||||
|
budget.phase = phase
|
||||||
|
expect(budget.description).to eq(budget.send("description_#{phase}"))
|
||||||
|
expect(budget.description).to be_html_safe
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "phase" do
|
describe "phase" do
|
||||||
let(:budget) { create(:budget) }
|
let(:budget) { create(:budget) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user