require 'test_helper' require 'mocha/test_unit' class TaxRateTest < Test::Unit::TestCase include TestHelper def setup @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) end should "have a primary key value of :tax_type" do assert_equal :tax_type, Xeroizer::Record::TaxRate.primary_key_name end should "build and save a tax rate with components via PUT" do @client.expects(:http_put).with { |client, url, body, extra_params| url == "https://api.xero.com/api.xro/2.0/TaxRates" && body == expected_tax_rate_create_body }.returns(tax_rate_create_successful_response) tax_rate = @client.TaxRate.build(name: 'Test Tax Rate') tax_rate.add_tax_component(name: 'Tax Component', rate: '10.0') tax_rate.save assert_equal "Test Tax Rate", tax_rate.name assert_equal "ACTIVE", tax_rate.status assert tax_rate.tax_type.present? assert_equal 1, tax_rate.tax_components.size tax_component = tax_rate.tax_components.first assert_equal "Tax Component", tax_component.name assert_equal "10.0", tax_component.rate.to_s end def expected_tax_rate_create_body <<-EOS Test Tax Rate Tax Component 10.0 EOS end def tax_rate_create_successful_response <<-EOS d1ec84aa-189f-4e08-b78f-ad62cf4935f4 OK Xero API Previewer 2014-07-02T19:26:53.3217153Z Test Tax Rate TAX018 true true true true true 10.0000 10.0000 ACTIVE Tax Component 10.0000 false EOS end end