Last active
January 9, 2020 17:14
-
-
Save joegaudet/eda373c314079b49ee3a69118309e0ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: accounting_ledger_items | |
# | |
# id :integer not null, primary key | |
# sender_type :string | |
# sender_id :integer | |
# recipient_type :string | |
# recipient_id :integer | |
# type :string | |
# issue_date :datetime | |
# currency :string(3) not null | |
# total_amount :decimal(20, 4) | |
# tax_amount :decimal(20, 4) | |
# status :string(20) not null | |
# identifier :string(50) | |
# description :string | |
# period_start :datetime | |
# period_end :datetime | |
# uuid :uuid | |
# due_date :datetime | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# xero_id :uuid | |
# parent_id :integer | |
# | |
class Accounting::LedgerItem < ApplicationRecord | |
has_many :children, as: :parent, class_name: 'Accounting::LedgerItem' | |
belongs_to :parent, polymorphic: true | |
end | |
ledger = Accounting::LedgerItem.new( | |
recipient: build(:vancouver_client), | |
currency: 'cad', | |
identifier: '1234', | |
due_date: Date.current + 7.days, | |
) | |
it "aggregates ledger items" do | |
ledger.save(validate: false) | |
ledger2 = ledger.dup | |
ledger2.save(validate: false) | |
ledger2.children << ledger | |
# this tries to set parent_type for some unknown reason. | |
# Minitest::UnexpectedError: ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column accounting_ledger_items.parent_type does not exist | |
# LINE 1: ...RE "accounting_ledger_items"."parent_id" = 27 AND "accountin... | |
# ^ | |
#: SELECT 1 AS one FROM "accounting_ledger_items" LEFT OUTER JOIN "accounting_line_items" ON "accounting_line_items"."ledger_item_id" = "accounting_ledger_items"."id" WHERE "accounting_ledger_items"."parent_id" = 27 AND "accounting_ledger_items"."parent_type" = 'Accounting::LedgerItem' AND "accounting_ledger_items"."id" = 28 LIMIT 1 | |
# test/models/accounting/ledger_item_test.rb:46:in `block (2 levels) in <main>' | |
#test/models/accounting/ledger_item_test.rb:46:in `block (2 levels) in <main>' | |
assert ledger2.parent == ledger | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment