adds denormalization to budget::ballot::lines
This commit is contained in:
@@ -2,7 +2,12 @@ class Budget
|
||||
class Ballot
|
||||
class Line < ActiveRecord::Base
|
||||
belongs_to :ballot
|
||||
belongs_to :budget
|
||||
belongs_to :group
|
||||
belongs_to :heading
|
||||
belongs_to :investment
|
||||
|
||||
validates :ballot_id, :budget_id, :group_id, :heading_id, :investment_id, presence: true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
7
db/migrate/20160610094658_desnormalize_ballot_line.rb
Normal file
7
db/migrate/20160610094658_desnormalize_ballot_line.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class DesnormalizeBallotLine < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :budget_ballot_lines, :budget_id, :integer, index: true
|
||||
add_column :budget_ballot_lines, :group_id, :integer, index: true
|
||||
add_column :budget_ballot_lines, :heading_id, :integer, index: true
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160609152026) do
|
||||
ActiveRecord::Schema.define(version: 20160610094658) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -83,6 +83,9 @@ ActiveRecord::Schema.define(version: 20160609152026) do
|
||||
t.integer "investment_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "budget_id"
|
||||
t.integer "group_id"
|
||||
t.integer "heading_id"
|
||||
end
|
||||
|
||||
add_index "budget_ballot_lines", ["ballot_id"], name: "index_budget_ballot_lines_on_ballot_id", using: :btree
|
||||
|
||||
@@ -222,6 +222,7 @@ FactoryGirl.define do
|
||||
association :heading, factory: :budget_heading
|
||||
association :author, factory: :user
|
||||
description 'Spend money on this'
|
||||
price 10
|
||||
unfeasibility_explanation ''
|
||||
external_url 'http://external_documention.org'
|
||||
terms_of_service '1'
|
||||
@@ -249,8 +250,11 @@ FactoryGirl.define do
|
||||
end
|
||||
|
||||
factory :budget_ballot_line, class: 'Budget::Ballot::Line' do
|
||||
association :ballot, factory: :budget_ballot
|
||||
investment { FactoryGirl.build(:budget_investment, :feasible) }
|
||||
budget
|
||||
ballot { create :budget_ballot, budget: budget }
|
||||
group { create :budget_group, budget: budget }
|
||||
heading { create :budget_heading, group: group }
|
||||
investment { create :budget_investment, :feasible, heading: heading }
|
||||
end
|
||||
|
||||
factory :vote do
|
||||
|
||||
40
spec/models/budget/ballot/line_spec.rb
Normal file
40
spec/models/budget/ballot/line_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe "Budget::Ballot::Line" do
|
||||
|
||||
let(:ballot_line) { build(:budget_ballot_line) }
|
||||
|
||||
describe 'Validations' do
|
||||
|
||||
it "should be valid" do
|
||||
expect(ballot_line).to be_valid
|
||||
end
|
||||
|
||||
it "should be invalid if missing id from ballot|budget|group|heading|investment" do
|
||||
budget = create(:budget)
|
||||
group = create(:budget_group, budget: budget)
|
||||
heading = create(:budget_heading, group: group, price: 10000000)
|
||||
investment = create(:budget_investment, :feasible, price: 5000000, heading: heading)
|
||||
ballot = create(:budget_ballot, budget: budget)
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: investment)
|
||||
expect(ballot_line).to be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: nil, budget: budget, group: group, heading: heading, investment: investment)
|
||||
expect(ballot_line).to_not be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: nil, group: group, heading: heading, investment: investment)
|
||||
expect(ballot_line).to_not be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: nil, heading: heading, investment: investment)
|
||||
expect(ballot_line).to_not be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: nil, investment: investment)
|
||||
expect(ballot_line).to_not be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: nil)
|
||||
expect(ballot_line).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user