Permalink
Browse files

added support for updating a bank transaction; added test for creatin…

…g a bank transaction
  • Loading branch information...
1 parent c493f7e commit 28db29956f6ebf8bcb32eac042a7a56a8794c0c5 @alto committed Feb 27, 2012
@@ -377,6 +377,20 @@ def create_bank_transaction(bank_transaction)
save_bank_transaction(bank_transaction)
end
+ #
+ # Updates an existing Xero bank transaction
+ #
+ # Usage :
+ #
+ # bank_transaction = xero_gateway.get_bank_transaction(some_bank_transaction_id)
+ # bank_transaction.due_date = Date.today
+ #
+ # xero_gateway.update_bank_transaction(bank_transaction)
+ def update_bank_transaction(bank_transaction)
+ raise "bank_transaction_id is required for updating bank transactions" if bank_transaction.bank_transaction_id.nil?
+ save_bank_transaction(bank_transaction)
+ end
+
# Retrieves all bank transactions from Xero
#
# Usage : get_bank_transactions
@@ -0,0 +1,38 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class CreateBankTransactionTest < Test::Unit::TestCase
+ include TestHelper
+
+ def setup
+ @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
+
+ if STUB_XERO_CALLS
+ @gateway.xero_url = "DUMMY_URL"
+
+ @gateway.stubs(:http_put).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("create_bank_transaction.xml"))
+ @gateway.stubs(:http_post).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("bank_transaction.xml"))
+ end
+ end
+
+ def test_create_bank_transaction
+ example_bank_transaction = create_test_bank_transaction.dup
+
+ result = @gateway.create_bank_transaction(example_bank_transaction)
+ assert_kind_of XeroGateway::Response, result
+ assert result.success?
+ assert !result.request_xml.nil?
+ assert !result.response_xml.nil?
+ assert !result.bank_transaction.bank_transaction_id.nil?
+ assert example_bank_transaction.bank_transaction_id =~ GUID_REGEX
+ end
+
+ def test_create_bank_transaction_valid
+ example_bank_transaction = create_test_bank_transaction.dup
+ assert_equal true, example_bank_transaction.valid?,
+ "bank_transaction is invalid - errors:\n\t#{example_bank_transaction.errors.map { | error | "#{error[0]} #{error[1]}"}.join("\n\t")}"
+ end
+
+ private
+
+
+end
@@ -0,0 +1,31 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class UpdateBankTransactionTest < Test::Unit::TestCase
+ include TestHelper
+
+ def setup
+ @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
+
+ if STUB_XERO_CALLS
+ @gateway.xero_url = "DUMMY_URL"
+
+ @gateway.stubs(:http_put).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("create_bank_transaction.xml"))
+ @gateway.stubs(:http_post).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("bank_transaction.xml"))
+ end
+ end
+
+ def test_update_bank_transaction
+ bank_transaction = @gateway.create_bank_transaction(create_test_bank_transaction).bank_transaction
+
+ today = Date.today
+ bank_transaction.date = today
+
+ result = @gateway.update_bank_transaction(bank_transaction)
+
+ assert result.success?
+ assert !result.request_xml.nil?
+ assert !result.response_xml.nil?
+ assert_equal bank_transaction.bank_transaction_id, result.bank_transaction.bank_transaction_id
+ assert_equal today, result.bank_transaction.date if !STUB_XERO_CALLS
+ end
+end

0 comments on commit 28db299

Please sign in to comment.