rspec Transaction; store transaction descriptions
This commit is contained in:
parent
aafe662acb
commit
c749b17904
@ -28,10 +28,11 @@ module Gnucash
|
||||
prefix + name
|
||||
end
|
||||
|
||||
def add_transaction(txn, value)
|
||||
def add_transaction(txn, value, description)
|
||||
@transactions << {
|
||||
txn: txn,
|
||||
value: value,
|
||||
description: description,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -3,12 +3,14 @@ module Gnucash
|
||||
attr_accessor :date
|
||||
attr_accessor :value
|
||||
attr_accessor :id
|
||||
attr_accessor :description
|
||||
|
||||
def initialize(book, node)
|
||||
@book = book
|
||||
@node = node
|
||||
@id = node.xpath('trn:id').text
|
||||
@date = node.xpath('trn:date-posted/ts:date').text.split(' ').first
|
||||
@description = node.xpath('trn:description').text
|
||||
@splits = node.xpath('trn:splits/trn:split').map do |split_node|
|
||||
value = Value.new(split_node.xpath('split:value').text)
|
||||
account_id = split_node.xpath('split:account').text
|
||||
@ -16,7 +18,7 @@ module Gnucash
|
||||
unless account
|
||||
raise "Could not find account with ID #{account_id} for transaction #{@id}"
|
||||
end
|
||||
account.add_transaction(self, value)
|
||||
account.add_transaction(self, value, description)
|
||||
{
|
||||
account_id: account_id,
|
||||
value: value,
|
||||
|
38
spec/gnucash/transaction_spec.rb
Normal file
38
spec/gnucash/transaction_spec.rb
Normal file
@ -0,0 +1,38 @@
|
||||
module Gnucash
|
||||
describe Transaction do
|
||||
context "with errors" do
|
||||
it "raises an error for unexpected XML" do
|
||||
book = "book"
|
||||
node = "node"
|
||||
text = "text"
|
||||
split_node = "split_node"
|
||||
value_text = "value_text"
|
||||
account_text = "account_text"
|
||||
|
||||
node.should_receive(:xpath).with('trn:id').and_return(text)
|
||||
text.stub(:text) {"hi there"}
|
||||
node.should_receive(:xpath).with('trn:date-posted/ts:date').and_return(text)
|
||||
value_text.should_receive(:text).and_return("1177/100")
|
||||
account_text.should_receive(:text).and_return("a1s2d3f4")
|
||||
split_node.should_receive(:xpath).with("split:value").and_return(value_text)
|
||||
split_node.should_receive(:xpath).with("split:account").and_return(account_text)
|
||||
node.should_receive(:xpath).with('trn:description').and_return(text)
|
||||
node.should_receive(:xpath).with('trn:splits/trn:split').and_return([split_node])
|
||||
book.should_receive(:find_account_by_id).and_return(nil)
|
||||
|
||||
expect { Transaction.new(book, node) }.to raise_error /Could not find account/
|
||||
end
|
||||
end
|
||||
|
||||
context "without errors" do
|
||||
before(:all) do
|
||||
@book = Gnucash.open("spec/books/sample.gnucash")
|
||||
@txn = @book.find_account_by_full_name("Assets::Current Assets::Cash in Wallet").transactions.first[:txn]
|
||||
end
|
||||
|
||||
it "keeps track of the transaction description" do
|
||||
@txn.description.should == "Opening Balance"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user