xeroizer 2.20.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +126 -185
  3. data/lib/xeroizer/connection.rb +49 -0
  4. data/lib/xeroizer/exceptions.rb +2 -0
  5. data/lib/xeroizer/generic_application.rb +8 -3
  6. data/lib/xeroizer/http.rb +5 -80
  7. data/lib/xeroizer/http_response.rb +154 -0
  8. data/lib/xeroizer/models/bank_transaction.rb +1 -0
  9. data/lib/xeroizer/models/batch_payment.rb +4 -1
  10. data/lib/xeroizer/models/contact.rb +10 -4
  11. data/lib/xeroizer/models/credit_note.rb +20 -20
  12. data/lib/xeroizer/models/history_record.rb +72 -0
  13. data/lib/xeroizer/models/invoice.rb +5 -1
  14. data/lib/xeroizer/models/line_item.rb +4 -2
  15. data/lib/xeroizer/models/manual_journal.rb +2 -1
  16. data/lib/xeroizer/models/option.rb +1 -1
  17. data/lib/xeroizer/models/payroll/address.rb +53 -0
  18. data/lib/xeroizer/models/payroll/bank_account.rb +18 -6
  19. data/lib/xeroizer/models/payroll/benefit_line.rb +26 -0
  20. data/lib/xeroizer/models/payroll/benefit_type.rb +45 -0
  21. data/lib/xeroizer/models/payroll/deduction_line.rb +32 -0
  22. data/lib/xeroizer/models/payroll/deduction_type.rb +49 -0
  23. data/lib/xeroizer/models/payroll/earnings_line.rb +39 -0
  24. data/lib/xeroizer/models/payroll/earnings_type.rb +53 -0
  25. data/lib/xeroizer/models/payroll/employee.rb +30 -8
  26. data/lib/xeroizer/models/payroll/leave_application.rb +27 -0
  27. data/lib/xeroizer/models/payroll/leave_line.rb +30 -0
  28. data/lib/xeroizer/models/payroll/leave_period.rb +15 -0
  29. data/lib/xeroizer/models/payroll/pay_items.rb +22 -0
  30. data/lib/xeroizer/models/payroll/pay_run.rb +33 -0
  31. data/lib/xeroizer/models/payroll/pay_schedule.rb +40 -0
  32. data/lib/xeroizer/models/payroll/pay_template.rb +24 -0
  33. data/lib/xeroizer/models/payroll/payment_method.rb +24 -0
  34. data/lib/xeroizer/models/payroll/paystub.rb +44 -0
  35. data/lib/xeroizer/models/payroll/reimbursement_line.rb +21 -0
  36. data/lib/xeroizer/models/payroll/reimbursement_type.rb +22 -0
  37. data/lib/xeroizer/models/payroll/salary_and_wage.rb +29 -0
  38. data/lib/xeroizer/models/payroll/super_line.rb +40 -0
  39. data/lib/xeroizer/models/payroll/tax_declaration.rb +50 -0
  40. data/lib/xeroizer/models/payroll/time_off_line.rb +20 -0
  41. data/lib/xeroizer/models/payroll/time_off_type.rb +32 -0
  42. data/lib/xeroizer/models/payroll/work_location.rb +25 -0
  43. data/lib/xeroizer/models/quote.rb +76 -0
  44. data/lib/xeroizer/models/tax_component.rb +1 -0
  45. data/lib/xeroizer/oauth.rb +12 -1
  46. data/lib/xeroizer/oauth2.rb +82 -0
  47. data/lib/xeroizer/oauth2_application.rb +49 -0
  48. data/lib/xeroizer/payroll_application.rb +8 -3
  49. data/lib/xeroizer/record/base_model.rb +1 -1
  50. data/lib/xeroizer/record/base_model_http_proxy.rb +1 -0
  51. data/lib/xeroizer/record/payroll_base.rb +4 -0
  52. data/lib/xeroizer/record/record_association_helper.rb +4 -4
  53. data/lib/xeroizer/record/validators/associated_validator.rb +1 -0
  54. data/lib/xeroizer/record/xml_helper.rb +16 -16
  55. data/lib/xeroizer/response.rb +22 -17
  56. data/lib/xeroizer/version.rb +1 -1
  57. data/lib/xeroizer.rb +31 -4
  58. data/test/acceptance/about_creating_bank_transactions_test.rb +80 -82
  59. data/test/acceptance/about_creating_prepayment_test.rb +25 -30
  60. data/test/acceptance/about_fetching_bank_transactions_test.rb +10 -10
  61. data/test/acceptance/about_online_invoice_test.rb +6 -10
  62. data/test/acceptance/acceptance_test.rb +28 -26
  63. data/test/acceptance/bank_transfer_test.rb +12 -17
  64. data/test/acceptance/bulk_operations_test.rb +18 -16
  65. data/test/acceptance/connections_test.rb +11 -0
  66. data/test/stub_responses/bad_request.json +6 -0
  67. data/test/stub_responses/connections.json +16 -0
  68. data/test/stub_responses/expired_oauth2_token.json +6 -0
  69. data/test/stub_responses/generic_response_error.json +6 -0
  70. data/test/stub_responses/invalid_oauth2_request_token.json +6 -0
  71. data/test/stub_responses/invalid_tenant_header.json +6 -0
  72. data/test/stub_responses/object_not_found.json +6 -0
  73. data/test/test_helper.rb +16 -11
  74. data/test/unit/generic_application_test.rb +21 -10
  75. data/test/unit/http_test.rb +281 -9
  76. data/test/unit/models/address_test.rb +2 -2
  77. data/test/unit/models/bank_transaction_model_parsing_test.rb +2 -2
  78. data/test/unit/models/bank_transaction_test.rb +1 -1
  79. data/test/unit/models/bank_transaction_validation_test.rb +1 -1
  80. data/test/unit/models/contact_test.rb +2 -2
  81. data/test/unit/models/credit_note_test.rb +8 -8
  82. data/test/unit/models/employee_test.rb +4 -4
  83. data/test/unit/models/invoice_test.rb +12 -12
  84. data/test/unit/models/journal_line_test.rb +6 -6
  85. data/test/unit/models/journal_test.rb +4 -4
  86. data/test/unit/models/line_item_sum_test.rb +1 -1
  87. data/test/unit/models/line_item_test.rb +19 -2
  88. data/test/unit/models/manual_journal_test.rb +3 -3
  89. data/test/unit/models/organisation_test.rb +2 -2
  90. data/test/unit/models/payment_service_test.rb +2 -2
  91. data/test/unit/models/phone_test.rb +7 -7
  92. data/test/unit/models/prepayment_test.rb +4 -4
  93. data/test/unit/models/repeating_invoice_test.rb +2 -2
  94. data/test/unit/models/tax_rate_test.rb +2 -2
  95. data/test/unit/oauth2_test.rb +171 -0
  96. data/test/unit/oauth_config_test.rb +1 -1
  97. data/test/unit/record/base_model_test.rb +13 -13
  98. data/test/unit/record/base_test.rb +5 -4
  99. data/test/unit/record/block_validator_test.rb +1 -1
  100. data/test/unit/record/connection_test.rb +60 -0
  101. data/test/unit/record/model_definition_test.rb +36 -36
  102. data/test/unit/record/parse_params_test.rb +2 -2
  103. data/test/unit/record/parse_where_hash_test.rb +13 -13
  104. data/test/unit/record/record_association_test.rb +14 -14
  105. data/test/unit/record/validators_test.rb +43 -43
  106. data/test/unit/record_definition_test.rb +7 -7
  107. data/test/unit/report_definition_test.rb +7 -7
  108. data/test/unit/report_test.rb +20 -20
  109. data/test/unit_test_helper.rb +16 -0
  110. metadata +106 -23
  111. data/lib/xeroizer/models/payroll/home_address.rb +0 -24
  112. data/lib/xeroizer/partner_application.rb +0 -51
  113. data/lib/xeroizer/private_application.rb +0 -25
  114. data/lib/xeroizer/public_application.rb +0 -21
  115. data/test/unit/http_tsl_12_upgrade_test.rb +0 -31
  116. data/test/unit/oauth_test.rb +0 -118
  117. data/test/unit/private_application_test.rb +0 -20
@@ -1,16 +1,16 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class CreditNoteTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api("CreditNotes")
9
9
  @credit_note = @client.CreditNote.first
10
10
  end
11
-
11
+
12
12
  context "credit note totals" do
13
-
13
+
14
14
  should "raise error when trying to set totals directly" do
15
15
  assert_raises Xeroizer::SettingTotalDirectlyNotSupported do
16
16
  @credit_note.sub_total = 500.0
@@ -22,7 +22,7 @@ class CreditNoteTest < Test::Unit::TestCase
22
22
  @credit_note.total = 550.0
23
23
  end
24
24
  end
25
-
25
+
26
26
  should "large-scale testing from API XML" do
27
27
  credit_notes = @client.CreditNote.all
28
28
  credit_notes.each do | credit_note |
@@ -31,7 +31,7 @@ class CreditNoteTest < Test::Unit::TestCase
31
31
  assert_equal(credit_note.attributes[:total], credit_note.total)
32
32
  end
33
33
  end
34
-
34
+
35
35
  end
36
-
36
+
37
37
  end
@@ -1,11 +1,11 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
1
+ require 'unit_test_helper'
2
2
 
3
3
  class EmployeeTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
  include Xeroizer::Record
6
-
6
+
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
  @employee = @client.Employee.build
10
10
 
11
11
  @employee.employee_id = 'GUID'
@@ -25,7 +25,7 @@ class EmployeeTest < Test::Unit::TestCase
25
25
  @employee.employee_group_name = "TEAM A"
26
26
  @doc = Nokogiri::XML(@employee.to_xml)
27
27
  end
28
-
28
+
29
29
  it "should render" do
30
30
  assert_equal "GUID", @doc.xpath("//EmployeeID").text
31
31
  assert_equal "ACTIVE", @doc.xpath("//Status").text
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class InvoiceTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api('Invoices')
9
9
  @invoice = @client.Invoice.first
10
10
  end
@@ -26,7 +26,7 @@ class InvoiceTest < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  context "invoice types" do
29
-
29
+
30
30
  should "have helpers to determine invoice type" do
31
31
  @invoice.type = 'ACCREC'
32
32
  assert_equal(true, @invoice.accounts_receivable?)
@@ -36,11 +36,11 @@ class InvoiceTest < Test::Unit::TestCase
36
36
  assert_equal(false, @invoice.accounts_receivable?)
37
37
  assert_equal(true, @invoice.accounts_payable?)
38
38
  end
39
-
39
+
40
40
  end
41
-
41
+
42
42
  context "invoice totals" do
43
-
43
+
44
44
  should "large-scale testing from API XML" do
45
45
  invoices = @client.Invoice.all
46
46
  invoices.each do | invoice |
@@ -51,7 +51,7 @@ class InvoiceTest < Test::Unit::TestCase
51
51
  end
52
52
 
53
53
  end
54
-
54
+
55
55
  context "invoice validations" do
56
56
 
57
57
  should "build an invalid invoice if there are no attributes" do
@@ -59,7 +59,7 @@ class InvoiceTest < Test::Unit::TestCase
59
59
  end
60
60
 
61
61
  should "build a valid DRAFT invoice with minimal attributes" do
62
- invoice = @client.Invoice.build :type => "ACCREC", :contact => { :name => "ABC Limited" }
62
+ invoice = @client.Invoice.build :type => "ACCREC", :date => Date.today, :contact => { :name => "ABC Limited" }
63
63
  assert_equal(true, invoice.valid?)
64
64
  end
65
65
 
@@ -105,7 +105,7 @@ class InvoiceTest < Test::Unit::TestCase
105
105
  end
106
106
 
107
107
  context "contact shortcuts" do
108
-
108
+
109
109
  should "have valid #contact_name and #contact_id without downloading full invoice" do
110
110
  invoices = @client.Invoice.all
111
111
  invoices.each do |invoice|
@@ -114,13 +114,13 @@ class InvoiceTest < Test::Unit::TestCase
114
114
  assert_equal(false, invoice.complete_record_downloaded?)
115
115
  end
116
116
  end
117
-
117
+
118
118
  end
119
119
 
120
120
  context "updated date" do
121
121
  should "get the updated date as utc" do
122
122
  invoices = @client.Invoice.all
123
-
123
+
124
124
  assert_equal(Time.parse("2008-9-16T10:28:51.5Z"), invoices[0].updated_date_utc)
125
125
 
126
126
  invoices.each do |invoice|
@@ -1,20 +1,20 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
1
+ require 'unit_test_helper'
2
2
 
3
3
  class JournalLineTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
  include Xeroizer::Record
6
-
6
+
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
  end
10
-
10
+
11
11
  it "journal_line tracking specified correctly" do
12
12
  journal = @client.Journal.build
13
13
  journal_line = journal.add_journal_line({})
14
-
14
+
15
15
  journal_line.add_tracking_category(:name => "Name 1", :option => "Option 1")
16
16
  journal_line.add_tracking_category(:name => "Name 2", :option => "Option 2")
17
-
17
+
18
18
  doc = Nokogiri::XML(journal_line.to_xml)
19
19
  assert_equal 2, doc.xpath("/JournalLine/TrackingCategories/TrackingCategory").size
20
20
  end
@@ -1,11 +1,11 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
1
+ require 'unit_test_helper'
2
2
 
3
3
  class JournalTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
  include Xeroizer::Record
6
-
6
+
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
 
10
10
  @journal = @client.Journal.build
11
11
  @journal.journal_id = "0d926df3-459f-4264-a3a3-49ac065eb0ed"
@@ -39,6 +39,6 @@ class JournalTest < Test::Unit::TestCase
39
39
  it "should render date" do
40
40
  assert_equal "2015-01-01", @doc.xpath("//JournalDate").text
41
41
  end
42
- end
42
+ end
43
43
 
44
44
  end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'unit_test_helper'
2
2
 
3
3
  class LineItemSumTest < Test::Unit::TestCase
4
4
  include Xeroizer::Record
@@ -1,11 +1,11 @@
1
- require "test_helper"
1
+ require 'unit_test_helper'
2
2
 
3
3
  class LineItemTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
  include Xeroizer::Record
6
6
 
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
  end
10
10
 
11
11
  it "line_item tracking specified correctly" do
@@ -56,4 +56,21 @@ class LineItemTest < Test::Unit::TestCase
56
56
  assert_equal 50, line_item.line_amount,
57
57
  "expected line amount to be calculated from coerced values"
58
58
  end
59
+
60
+ context "line_item validations" do
61
+
62
+ it "is an invalid line_item if there is no description" do
63
+ line_item = LineItem.new(nil)
64
+
65
+ assert_equal(false, line_item.valid?)
66
+ end
67
+
68
+ it "is a valid line_item with minimal attributes" do
69
+ line_item = LineItem.new(nil)
70
+ line_item.description = "Test Description"
71
+
72
+ assert_equal(true, line_item.valid?)
73
+ end
74
+
75
+ end
59
76
  end
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class ManualJournalTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api('ManualJournals')
9
9
  end
10
10
 
@@ -22,4 +22,4 @@ class ManualJournalTest < Test::Unit::TestCase
22
22
  end
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class OrganisationTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  end
9
9
 
10
10
  context "sales_tax_basis_validations" do
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class PaymentServiceTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  end
9
9
 
10
10
  context "response parsing" do
@@ -1,23 +1,23 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class PhoneTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  @contact = @client.Contact.build
9
9
 
10
10
  end
11
-
11
+
12
12
  context "validators" do
13
-
13
+
14
14
  should "not allow long phone numbers" do
15
15
  @phone = @contact.add_phone(phone_number: "1234567890123456789012345678901234567890123456789012345678901234567890")
16
16
  assert_equal(false, @phone.valid?)
17
17
  blank_error = @phone.errors_for(:phone_number).first
18
18
  assert_not_nil(blank_error)
19
19
  assert_equal("must be shorter than 50 characters", blank_error)
20
-
20
+
21
21
  end
22
22
 
23
23
  should "allow phone numbers" do
@@ -27,5 +27,5 @@ class PhoneTest < Test::Unit::TestCase
27
27
  assert_equal(0, @phone.errors.size)
28
28
  end
29
29
  end
30
-
30
+
31
31
  end
@@ -1,14 +1,14 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class PrepaymentTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api("Prepayments")
9
9
  @prepayment = @client.Prepayment.first
10
10
  end
11
-
11
+
12
12
  context "prepayment attributes" do
13
13
  should "large-scale testing from API XML" do
14
14
  prepayments = @client.Prepayment.all
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class RepeatingInvoiceTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api('RepeatingInvoices')
9
9
  end
10
10
 
@@ -1,11 +1,11 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
  require 'mocha/test_unit'
3
3
 
4
4
  class TaxRateTest < Test::Unit::TestCase
5
5
  include TestHelper
6
6
 
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
  end
10
10
 
11
11
  should "have a primary key value of :name" do
@@ -0,0 +1,171 @@
1
+ require 'unit_test_helper'
2
+
3
+ class OAuth2Test < UnitTestCase
4
+ include TestHelper
5
+
6
+ setup do
7
+ @client_id = 'client_id'
8
+ @client_secret = 'client_secret'
9
+ @access_token = 'access_token'
10
+ @site = 'https://example.com'
11
+ @content_type = 'application/xml'
12
+ @path = '/path'
13
+ @uri = "#{@site}#{@path}"
14
+ @response_body = '{"test": true}'
15
+ @status_code = 200
16
+ @additional_headers = {foo: 'bar'}
17
+ @request_body = "xml"
18
+ @request_headers = { 'Content-Type' => @content_type }
19
+ @tenant_id = "tenant"
20
+ end
21
+
22
+ def instance
23
+ Xeroizer::OAuth2.new(@client_id, @client_secret, {
24
+ site: @site
25
+ }).tap do |oauth2|
26
+ oauth2.authorize_from_access(@access_token)
27
+ end
28
+ end
29
+
30
+ context "get" do
31
+ setup do
32
+ stub_request(:get, @uri).
33
+ with(
34
+ headers: {
35
+ 'Authorization' => "Bearer #{@access_token}",
36
+ }
37
+ ).to_return(status: @status_code, body: @response_body, headers: {})
38
+ end
39
+
40
+ context "when tenant_id is not present" do
41
+ should "make a get request" do
42
+ result = instance.get(@path)
43
+ assert_equal(result.code, @status_code)
44
+ assert_equal(result.plain_body, @response_body)
45
+ assert_requested :get, @uri
46
+ assert_not_requested :get, @uri, headers: { "Xero-tenant-id" => @tenant_id }
47
+ end
48
+ end
49
+
50
+ context "when tenant_id is present" do
51
+ setup do
52
+ @client = instance
53
+ @client.tenant_id = @tenant_id
54
+ end
55
+
56
+ should "make a get request with the tenant_id" do
57
+ result = @client.get(@path)
58
+ assert_equal(result.code, @status_code)
59
+ assert_equal(result.plain_body, @response_body)
60
+ assert_requested :get, @uri, headers: { "Xero-tenant-id" => @tenant_id }
61
+ end
62
+ end
63
+ end
64
+
65
+ context "delete" do
66
+ setup do
67
+ stub_request(:delete, @uri).
68
+ with(
69
+ headers: {
70
+ 'Authorization' => "Bearer #{@access_token}",
71
+ }
72
+ ).to_return(status: @status_code, body: @response_body, headers: {})
73
+ end
74
+
75
+ context "when tenant_id is not present" do
76
+ should "make a delete request" do
77
+ result = instance.delete(@path)
78
+ assert_equal(result.code, @status_code)
79
+ assert_not_requested :delete, @uri, headers: { "Xero-tenant-id" => @tenant_id }
80
+ end
81
+ end
82
+
83
+
84
+ context "when tenant_id is present" do
85
+ setup do
86
+ @client = instance
87
+ @client.tenant_id = @tenant_id
88
+ end
89
+
90
+ should "make a delete request with the tenant_id" do
91
+ result = @client.delete(@path)
92
+ assert_equal(result.code, @status_code)
93
+ assert_equal(result.plain_body, @response_body)
94
+ assert_requested :delete, @uri, headers: { "Xero-tenant-id" => @tenant_id }
95
+ end
96
+ end
97
+ end
98
+
99
+ context "post" do
100
+ setup do
101
+ stub_request(:post, @uri).
102
+ with(
103
+ body: @request_body,
104
+ headers: {
105
+ 'Authorization' => "Bearer #{@access_token}",
106
+ 'Content-Type' => @content_type,
107
+ }).
108
+ to_return(status: @status_code, body: @response_body, headers: @request_headers)
109
+
110
+ end
111
+
112
+ context "when tenant_id is not present" do
113
+ should "make a post request" do
114
+ result = instance.post(@path, @request_body, @request_headers)
115
+ assert_equal(result.code, @status_code)
116
+ assert_equal(result.plain_body, @response_body)
117
+ assert_not_requested :post, @uri, headers: { "Xero-tenant-id" => @tenant_id }
118
+ end
119
+ end
120
+
121
+ context "when tenant_id is present" do
122
+ setup do
123
+ @client = instance
124
+ @client.tenant_id = @tenant_id
125
+ end
126
+
127
+ should "make a post request with the tenant_id" do
128
+ result = @client.post(@path, @request_body, @request_headers)
129
+ assert_equal(result.code, @status_code)
130
+ assert_equal(result.plain_body, @response_body)
131
+ assert_requested :post, @uri, headers: { "Xero-tenant-id" => @tenant_id }
132
+ end
133
+ end
134
+ end
135
+
136
+ context "put" do
137
+ setup do
138
+ stub_request(:put, @uri).
139
+ with(
140
+ body: @request_body,
141
+ headers: {
142
+ 'Authorization' => "Bearer #{@access_token}",
143
+ 'Content-Type' => @content_type,
144
+ }).
145
+ to_return(status: @status_code, body: @response_body, headers: @request_headers)
146
+ end
147
+
148
+ context "when tenant_id is not present" do
149
+ should "make a put request" do
150
+ result = instance.put(@path, @request_body, @request_headers)
151
+ assert_equal(result.code, @status_code)
152
+ assert_equal(result.plain_body, @response_body)
153
+ assert_not_requested :put, @uri, headers: { "Xero-tenant-id" => @tenant_id }
154
+ end
155
+ end
156
+
157
+ context "when tenant_id is present" do
158
+ setup do
159
+ @client = instance
160
+ @client.tenant_id = @tenant_id
161
+ end
162
+
163
+ should "make a put request" do
164
+ result = @client.put(@path, @request_body, @request_headers)
165
+ assert_equal(result.code, @status_code)
166
+ assert_equal(result.plain_body, @response_body)
167
+ assert_requested :put, @uri, headers: { "Xero-tenant-id" => @tenant_id }
168
+ end
169
+ end
170
+ end
171
+ end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'unit_test_helper'
2
2
 
3
3
  class OAuthConfigTest < Test::Unit::TestCase
4
4
  include Xeroizer
@@ -1,50 +1,50 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class RecordBaseModelTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  class AppleModel < Xeroizer::Record::BaseModel
7
7
  set_api_controller_name 'AppleController'
8
8
  set_permissions :read, :write
9
9
  end
10
-
10
+
11
11
  class PearModel < Xeroizer::Record::BaseModel
12
12
  set_api_controller_name 'PearController'
13
13
  set_permissions :read
14
14
  end
15
-
15
+
16
16
  class OrangeModel < Xeroizer::Record::BaseModel
17
17
  set_permissions :read, :write, :update
18
18
  end
19
-
19
+
20
20
  def setup
21
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
21
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
22
22
  @apple_model = AppleModel.new(@client, 'Apple')
23
23
  @pear_model = PearModel.new(@client, 'Pear')
24
24
  @orange_model = OrangeModel.new(@client, 'Orange')
25
25
  end
26
-
26
+
27
27
  context "RecordModel.api_controller_name" do
28
-
28
+
29
29
  should "api_controller_name should default to pluralized model name" do
30
30
  assert_equal('Oranges', @orange_model.api_controller_name)
31
31
  end
32
-
32
+
33
33
  should "set_api_controller_name should set the base controller name used by Xero" do
34
34
  assert_equal('AppleController', @apple_model.api_controller_name)
35
35
  assert_equal('PearController', @pear_model.api_controller_name)
36
36
  end
37
-
37
+
38
38
  end
39
-
39
+
40
40
  context "model permssions" do
41
-
41
+
42
42
  should "save permissions correctly" do
43
43
  assert_equal(%w(read write), @apple_model.class.permissions.keys.map(&:to_s).sort)
44
44
  assert_equal(%w(read), @pear_model.class.permissions.keys.map(&:to_s).sort)
45
45
  assert_equal(%w(read update write), @orange_model.class.permissions.keys.map(&:to_s).sort)
46
46
  end
47
-
47
+
48
48
  end
49
49
 
50
50
  context "InvalidPermissionError" do
@@ -1,10 +1,11 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class RecordBaseTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET, tenant_id: TENANT_ID)
8
+ @client.authorize_from_access(ACCESS_TOKEN)
8
9
  @contact = @client.Contact.build(:name => 'Test Contact Name ABC')
9
10
  end
10
11
 
@@ -26,14 +27,14 @@ class RecordBaseTest < Test::Unit::TestCase
26
27
  context "new_record? states" do
27
28
 
28
29
  should "new_record? should be false when loading data" do
29
- Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
30
+ Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
30
31
  contact = @client.Contact.find('TESTID')
31
32
  assert_kind_of(Xeroizer::Record::Contact, contact)
32
33
  assert_equal(false, contact.new_record?)
33
34
  end
34
35
 
35
36
  should "new_record? should be false after successfully creating a record" do
36
- Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
37
+ Xeroizer::OAuth2.any_instance.stubs(:put).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
37
38
  assert_equal(true, @contact.new_record?)
38
39
  assert_nil(@contact.contact_id)
39
40
  assert_equal(true, @contact.save, "Error saving contact: #{@contact.errors.inspect}")
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'unit_test_helper'
2
2
 
3
3
  class BlockValidatorTest < Test::Unit::TestCase
4
4
  def setup