Skip to content

Commit

Permalink
Fix metaData not copied when creating TransactionPosting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nef10 committed May 23, 2020
1 parent 8f1dc4a commit 39c5dca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SwiftBeanCountModel/TransactionPosting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class TransactionPosting: Posting {
/// - transaction: the `Transaction` the posting is in - an *unowned* reference will be stored
init(posting: Posting, transaction: Transaction) {
self.transaction = transaction
super.init(accountName: posting.accountName, amount: posting.amount, price: posting.price, cost: posting.cost)
super.init(accountName: posting.accountName, amount: posting.amount, price: posting.price, cost: posting.cost, metaData: posting.metaData)
}

}
Expand Down
10 changes: 10 additions & 0 deletions SwiftBeanCountModelTests/TransactionPostingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ class TransactionPostingTests: XCTestCase {
posting1 = Posting(accountName: accountName1, amount: amount1!)
}

func testInitTransactionPosting() {
let transaction = Transaction(metaData: TransactionMetaData(date: Date(timeIntervalSince1970: 1_496_991_600), payee: "", narration: "", flag: .complete, tags: []))
let posting = Posting(accountName: accountName1, amount: amount1!, metaData: ["A": "B"])
let transactionPosting = TransactionPosting(posting: posting, transaction: transaction)
XCTAssertEqual(posting.accountName, transactionPosting.accountName)
XCTAssertEqual(posting.amount, transactionPosting.amount)
XCTAssertEqual(posting.metaData, transactionPosting.metaData)
XCTAssertEqual(transaction, transactionPosting.transaction)
}

func testDescription() {
let amount = Amount(number: Decimal(1), commodity: Commodity(symbol: "💵"))
let posting = Posting(accountName: accountName2, amount: amount)
Expand Down

0 comments on commit 39c5dca

Please sign in to comment.