New Checkpoint model. Update factories. Model specs.

This commit is contained in:
taitus
2017-06-20 15:37:03 +02:00
parent b5da0dfc9a
commit beeb5412d7
7 changed files with 63 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ class Budget
has_many :valuator_assignments, dependent: :destroy has_many :valuator_assignments, dependent: :destroy
has_many :valuators, through: :valuator_assignments has_many :valuators, through: :valuator_assignments
has_many :comments, as: :commentable has_many :comments, as: :commentable
has_many :checkpoints
validates :title, presence: true validates :title, presence: true
validates :author, presence: true validates :author, presence: true

View File

@@ -0,0 +1,10 @@
class Budget
class Investment
class Checkpoint < ActiveRecord::Base
belongs_to :investment
validates :title, presence: true
validates :investment, presence: true
end
end
end

View File

@@ -0,0 +1,11 @@
class CreateBudgetInvestmentCheckpoints < ActiveRecord::Migration
def change
create_table :budget_investment_checkpoints do |t|
t.integer :investment_id
t.string "title", limit: 80
t.text "description"
t.timestamps null: false
end
end
end

View File

@@ -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: 20170613203256) do ActiveRecord::Schema.define(version: 20170620132731) 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"
@@ -114,6 +114,14 @@ ActiveRecord::Schema.define(version: 20170613203256) do
add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree
create_table "budget_investment_checkpoints", force: :cascade do |t|
t.integer "investment_id"
t.string "title", limit: 80
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "budget_investments", force: :cascade do |t| create_table "budget_investments", force: :cascade do |t|
t.integer "author_id" t.integer "author_id"
t.integer "administrator_id" t.integer "administrator_id"
@@ -413,8 +421,8 @@ ActiveRecord::Schema.define(version: 20170613203256) do
t.date "allegations_end_date" t.date "allegations_end_date"
t.date "result_publication_date" t.date "result_publication_date"
t.datetime "hidden_at" t.datetime "hidden_at"
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 "summary" t.text "summary"
t.boolean "debate_phase_enabled", default: false t.boolean "debate_phase_enabled", default: false
t.boolean "allegations_phase_enabled", default: false t.boolean "allegations_phase_enabled", default: false
@@ -924,7 +932,7 @@ ActiveRecord::Schema.define(version: 20170613203256) do
t.boolean "email_digest", default: true t.boolean "email_digest", default: true
t.boolean "email_on_direct_message", default: true t.boolean "email_on_direct_message", default: true
t.boolean "official_position_badge", default: false t.boolean "official_position_badge", default: false
t.datetime "password_changed_at", default: '2016-12-21 17:55:08', null: false t.datetime "password_changed_at", default: '2017-06-20 13:30:34', null: false
t.boolean "created_from_signature", default: false t.boolean "created_from_signature", default: false
t.integer "failed_email_digests_count", default: 0 t.integer "failed_email_digests_count", default: 0
t.text "former_users_data_log", default: "" t.text "former_users_data_log", default: ""

View File

@@ -322,6 +322,12 @@ FactoryGirl.define do
reason "unfeasible" reason "unfeasible"
end end
factory :budget_investment_checkpoint, class: 'Budget::Investment::Checkpoint' do
association :investment, factory: :budget_investment
sequence(:title) { |n| "Budget Investment Checkpoint #{n} title" }
description 'Checkpoint description'
end
factory :vote do factory :vote do
association :votable, factory: :debate association :votable, factory: :debate
association :voter, factory: :user association :voter, factory: :user

View File

@@ -0,0 +1,23 @@
require 'rails_helper'
describe "Budget::Investment::Checkpoint" do
describe "Validations" do
let(:checkpoint) { build(:budget_investment_checkpoint) }
it "should be valid" do
expect(checkpoint).to be_valid
end
it "should not be valid without a title" do
checkpoint.title = nil
expect(checkpoint).to_not be_valid
end
it "should not be valid without an investment" do
checkpoint.investment_id = nil
expect(checkpoint).to_not be_valid
end
end
end

View File

@@ -486,7 +486,6 @@ describe Budget::Investment do
end end
describe 'Permissions' do describe 'Permissions' do
let(:budget) { create(:budget) } let(:budget) { create(:budget) }
let(:group) { create(:budget_group, budget: budget) } let(:group) { create(:budget_group, budget: budget) }