Skip to content

Commit

Permalink
Merge 02f530c into 00a98af
Browse files Browse the repository at this point in the history
  • Loading branch information
chrp committed Jan 10, 2019
2 parents 00a98af + 02f530c commit 8f5166e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 13 deletions.
6 changes: 6 additions & 0 deletions app/models/plutus/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class Account < ActiveRecord::Base
include Plutus::NoTenancy
end

if ActiveRecord::VERSION::MAJOR > 4
belongs_to :commercial_entity, :polymorphic => true, optional: true
else
belongs_to :commercial_entity, :polymorphic => true
end

# The balance of the account. This instance method is intended for use only
# on instances of account subclasses.
#
Expand Down
2 changes: 1 addition & 1 deletion fixture_rails_root/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem "plutus", path: "~/repos/plutus"
gem "plutus", path: "../"
22 changes: 11 additions & 11 deletions fixture_rails_root/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
plutus (0.12.2)
plutus (0.13)
jquery-rails (>= 3.0)
jquery-ui-rails (>= 4.2.2)
kaminari (~> 1.0)
Expand Down Expand Up @@ -74,18 +74,18 @@ GEM
thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
kaminari (1.0.1)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.0.1)
kaminari-activerecord (= 1.0.1)
kaminari-core (= 1.0.1)
kaminari-actionview (1.0.1)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.0.1)
kaminari-activerecord (1.0.1)
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.0.1)
kaminari-core (1.0.1)
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -195,4 +195,4 @@ DEPENDENCIES
web-console (>= 3.3.0)

BUNDLED WITH
1.15.1
1.16.6
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddCommercialEntityToPlutusAccounts < ActiveRecord::Migration[4.2]
def change
add_column :plutus_accounts, :commercial_entity_id, :integer
add_column :plutus_accounts, :commercial_entity_type, :string
add_index :plutus_accounts, [:commercial_entity_type, :commercial_entity_id], :name => "index_accounts_on_commercial_entity"
end
end
5 changes: 4 additions & 1 deletion fixture_rails_root/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170710174915) do
ActiveRecord::Schema.define(version: 20190110100325) do

create_table "plutus_accounts", force: :cascade do |t|
t.string "name"
Expand All @@ -19,6 +19,9 @@
t.datetime "created_at"
t.datetime "updated_at"
t.integer "tenant_id"
t.integer "commercial_entity_id"
t.string "commercial_entity_type"
t.index ["commercial_entity_type", "commercial_entity_id"], name: "index_accounts_on_commercial_entity"
t.index ["name", "type"], name: "index_plutus_accounts_on_name_and_type"
end

Expand Down
11 changes: 11 additions & 0 deletions lib/generators/plutus/add_commercial_entity_upgrade_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'rails/generators'
require 'rails/generators/migration'
require_relative 'base_generator'

module Plutus
class AddCommercialEntityUpgradeGenerator < BaseGenerator
def create_migration_file
migration_template 'add_commercial_entity_migration.rb', 'db/migrate/add_commercial_entity_to_plutus_accounts.rb'
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddCommercialEntityToPlutusAccounts < ActiveRecord::Migration[4.2]
def change
add_column :plutus_accounts, :commercial_entity_id, :integer
add_column :plutus_accounts, :commercial_entity_type, :string
add_index :plutus_accounts, [:commercial_entity_type, :commercial_entity_id], :name => "index_accounts_on_commercial_entity"
end
end
3 changes: 3 additions & 0 deletions lib/generators/plutus/templates/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ def self.up
t.string :name
t.string :type
t.boolean :contra, default: false
t.integer :commercial_entity_id
t.string :commercial_entity_type

t.timestamps
end
add_index :plutus_accounts, [:name, :type]
add_index :plutus_accounts, [:commercial_entity_type, :commercial_entity_id], :name => "index_accounts_on_commercial_entity"

create_table :plutus_entries do |t|
t.string :description
Expand Down
8 changes: 8 additions & 0 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,13 @@ module Plutus
end
end

it "should have a polymorphic commercial entity associations" do
mock_entity = FactoryGirl.create(:asset) # one would never do this, but it allows us to not require a migration for the test
entry = FactoryGirl.build(:liability, commercial_entity: mock_entity)
entry.save!
saved_account = Account.find(entry.id)
expect(saved_account.commercial_entity).to eq(mock_entity)
end

end
end

0 comments on commit 8f5166e

Please sign in to comment.