xeroizer 2.20.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +126 -185
- data/lib/xeroizer/connection.rb +49 -0
- data/lib/xeroizer/exceptions.rb +2 -0
- data/lib/xeroizer/generic_application.rb +8 -3
- data/lib/xeroizer/http.rb +5 -80
- data/lib/xeroizer/http_response.rb +154 -0
- data/lib/xeroizer/models/bank_transaction.rb +1 -0
- data/lib/xeroizer/models/batch_payment.rb +4 -1
- data/lib/xeroizer/models/contact.rb +10 -4
- data/lib/xeroizer/models/credit_note.rb +20 -20
- data/lib/xeroizer/models/history_record.rb +72 -0
- data/lib/xeroizer/models/invoice.rb +5 -1
- data/lib/xeroizer/models/line_item.rb +4 -2
- data/lib/xeroizer/models/manual_journal.rb +2 -1
- data/lib/xeroizer/models/option.rb +1 -1
- data/lib/xeroizer/models/payroll/address.rb +53 -0
- data/lib/xeroizer/models/payroll/bank_account.rb +18 -6
- data/lib/xeroizer/models/payroll/benefit_line.rb +26 -0
- data/lib/xeroizer/models/payroll/benefit_type.rb +45 -0
- data/lib/xeroizer/models/payroll/deduction_line.rb +32 -0
- data/lib/xeroizer/models/payroll/deduction_type.rb +49 -0
- data/lib/xeroizer/models/payroll/earnings_line.rb +39 -0
- data/lib/xeroizer/models/payroll/earnings_type.rb +53 -0
- data/lib/xeroizer/models/payroll/employee.rb +30 -8
- data/lib/xeroizer/models/payroll/leave_application.rb +27 -0
- data/lib/xeroizer/models/payroll/leave_line.rb +30 -0
- data/lib/xeroizer/models/payroll/leave_period.rb +15 -0
- data/lib/xeroizer/models/payroll/pay_items.rb +22 -0
- data/lib/xeroizer/models/payroll/pay_run.rb +33 -0
- data/lib/xeroizer/models/payroll/pay_schedule.rb +40 -0
- data/lib/xeroizer/models/payroll/pay_template.rb +24 -0
- data/lib/xeroizer/models/payroll/payment_method.rb +24 -0
- data/lib/xeroizer/models/payroll/paystub.rb +44 -0
- data/lib/xeroizer/models/payroll/reimbursement_line.rb +21 -0
- data/lib/xeroizer/models/payroll/reimbursement_type.rb +22 -0
- data/lib/xeroizer/models/payroll/salary_and_wage.rb +29 -0
- data/lib/xeroizer/models/payroll/super_line.rb +40 -0
- data/lib/xeroizer/models/payroll/tax_declaration.rb +50 -0
- data/lib/xeroizer/models/payroll/time_off_line.rb +20 -0
- data/lib/xeroizer/models/payroll/time_off_type.rb +32 -0
- data/lib/xeroizer/models/payroll/work_location.rb +25 -0
- data/lib/xeroizer/models/quote.rb +76 -0
- data/lib/xeroizer/models/tax_component.rb +1 -0
- data/lib/xeroizer/oauth.rb +12 -1
- data/lib/xeroizer/oauth2.rb +82 -0
- data/lib/xeroizer/oauth2_application.rb +49 -0
- data/lib/xeroizer/payroll_application.rb +8 -3
- data/lib/xeroizer/record/base_model.rb +1 -1
- data/lib/xeroizer/record/base_model_http_proxy.rb +1 -0
- data/lib/xeroizer/record/payroll_base.rb +4 -0
- data/lib/xeroizer/record/record_association_helper.rb +4 -4
- data/lib/xeroizer/record/validators/associated_validator.rb +1 -0
- data/lib/xeroizer/record/xml_helper.rb +16 -16
- data/lib/xeroizer/response.rb +22 -17
- data/lib/xeroizer/version.rb +1 -1
- data/lib/xeroizer.rb +31 -4
- data/test/acceptance/about_creating_bank_transactions_test.rb +80 -82
- data/test/acceptance/about_creating_prepayment_test.rb +25 -30
- data/test/acceptance/about_fetching_bank_transactions_test.rb +10 -10
- data/test/acceptance/about_online_invoice_test.rb +6 -10
- data/test/acceptance/acceptance_test.rb +28 -26
- data/test/acceptance/bank_transfer_test.rb +12 -17
- data/test/acceptance/bulk_operations_test.rb +18 -16
- data/test/acceptance/connections_test.rb +11 -0
- data/test/stub_responses/bad_request.json +6 -0
- data/test/stub_responses/connections.json +16 -0
- data/test/stub_responses/expired_oauth2_token.json +6 -0
- data/test/stub_responses/generic_response_error.json +6 -0
- data/test/stub_responses/invalid_oauth2_request_token.json +6 -0
- data/test/stub_responses/invalid_tenant_header.json +6 -0
- data/test/stub_responses/object_not_found.json +6 -0
- data/test/test_helper.rb +16 -11
- data/test/unit/generic_application_test.rb +21 -10
- data/test/unit/http_test.rb +281 -9
- data/test/unit/models/address_test.rb +2 -2
- data/test/unit/models/bank_transaction_model_parsing_test.rb +2 -2
- data/test/unit/models/bank_transaction_test.rb +1 -1
- data/test/unit/models/bank_transaction_validation_test.rb +1 -1
- data/test/unit/models/contact_test.rb +2 -2
- data/test/unit/models/credit_note_test.rb +8 -8
- data/test/unit/models/employee_test.rb +4 -4
- data/test/unit/models/invoice_test.rb +12 -12
- data/test/unit/models/journal_line_test.rb +6 -6
- data/test/unit/models/journal_test.rb +4 -4
- data/test/unit/models/line_item_sum_test.rb +1 -1
- data/test/unit/models/line_item_test.rb +19 -2
- data/test/unit/models/manual_journal_test.rb +3 -3
- data/test/unit/models/organisation_test.rb +2 -2
- data/test/unit/models/payment_service_test.rb +2 -2
- data/test/unit/models/phone_test.rb +7 -7
- data/test/unit/models/prepayment_test.rb +4 -4
- data/test/unit/models/repeating_invoice_test.rb +2 -2
- data/test/unit/models/tax_rate_test.rb +2 -2
- data/test/unit/oauth2_test.rb +171 -0
- data/test/unit/oauth_config_test.rb +1 -1
- data/test/unit/record/base_model_test.rb +13 -13
- data/test/unit/record/base_test.rb +5 -4
- data/test/unit/record/block_validator_test.rb +1 -1
- data/test/unit/record/connection_test.rb +60 -0
- data/test/unit/record/model_definition_test.rb +36 -36
- data/test/unit/record/parse_params_test.rb +2 -2
- data/test/unit/record/parse_where_hash_test.rb +13 -13
- data/test/unit/record/record_association_test.rb +14 -14
- data/test/unit/record/validators_test.rb +43 -43
- data/test/unit/record_definition_test.rb +7 -7
- data/test/unit/report_definition_test.rb +7 -7
- data/test/unit/report_test.rb +20 -20
- data/test/unit_test_helper.rb +16 -0
- metadata +106 -23
- data/lib/xeroizer/models/payroll/home_address.rb +0 -24
- data/lib/xeroizer/partner_application.rb +0 -51
- data/lib/xeroizer/private_application.rb +0 -25
- data/lib/xeroizer/public_application.rb +0 -21
- data/test/unit/http_tsl_12_upgrade_test.rb +0 -31
- data/test/unit/oauth_test.rb +0 -118
- data/test/unit/private_application_test.rb +0 -20
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'unit_test_helper'
|
2
|
+
|
3
|
+
class ConnectionTest < UnitTestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@client = Xeroizer::OAuth2Application.new("client id", "client secret", access_token: "access token")
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when the request succeeds" do
|
11
|
+
setup do
|
12
|
+
stub_request(:get, "https://api.xero.com/connections").to_return(
|
13
|
+
body: [
|
14
|
+
{
|
15
|
+
id: "fe4cd81c-624a-4506-ab18-11c656742436",
|
16
|
+
tenantId: "c84e0419-ade8-4296-9794-289876d4bc22",
|
17
|
+
tenantType: "ORGANISATION",
|
18
|
+
createdDateUtc: "2019-12-13T18:10:43.3063640",
|
19
|
+
updatedDateUtc: "2019-12-13T18:10:43.3084790"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
id: "fe4cd81c-624a-4506-ab18-11c656742436",
|
23
|
+
tenantId: "c84e0419-ade8-4296-9794-289876d4bc22",
|
24
|
+
tenantType: "ORGANISATION",
|
25
|
+
createdDateUtc: "2019-12-13T18:10:43.3063640",
|
26
|
+
updatedDateUtc: "2019-12-13T18:10:43.3084790"
|
27
|
+
}
|
28
|
+
].to_json
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns connections using the passed client' do
|
33
|
+
result = Xeroizer::Connection.current_connections(@client.client)
|
34
|
+
assert_equal 2, result.count
|
35
|
+
assert_equal "c84e0419-ade8-4296-9794-289876d4bc22", result.first.tenant_id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when the request fails' do
|
40
|
+
setup do
|
41
|
+
@body = {
|
42
|
+
title: "Unauthorized",
|
43
|
+
status: 401,
|
44
|
+
detail: "AuthenticationUnsuccessful",
|
45
|
+
instance: "e1d2cb91-82bf-41a5-84dd-fe6a5c6f070c"
|
46
|
+
}.to_json
|
47
|
+
|
48
|
+
stub_request(:get, "https://api.xero.com/connections").to_return(
|
49
|
+
status: 401,
|
50
|
+
body: @body
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'raises token_invalid error' do
|
55
|
+
assert_raises(Xeroizer::OAuth::TokenInvalid, @body) {
|
56
|
+
Xeroizer::Connection.current_connections(@client.client)
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class ModelDefinitionsTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
|
-
|
5
|
+
|
6
6
|
class FirstRecord < Xeroizer::Record::Base
|
7
|
-
|
7
|
+
|
8
8
|
set_primary_key :primary_key_id
|
9
|
-
|
9
|
+
|
10
10
|
guid :primary_key_id
|
11
11
|
string :string1
|
12
12
|
boolean :boolean1
|
@@ -14,14 +14,14 @@ class ModelDefinitionsTest < Test::Unit::TestCase
|
|
14
14
|
decimal :decimal1
|
15
15
|
date :date1
|
16
16
|
datetime :datetime1
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
19
|
class Xeroizer::Record::FirstRecordModel < Xeroizer::Record::BaseModel; end
|
20
|
-
|
20
|
+
|
21
21
|
class SecondRecord < Xeroizer::Record::Base
|
22
22
|
|
23
23
|
set_primary_key :primary_key_id
|
24
|
-
|
24
|
+
|
25
25
|
guid :primary_key_id
|
26
26
|
string :string2
|
27
27
|
boolean :boolean2
|
@@ -32,63 +32,63 @@ class ModelDefinitionsTest < Test::Unit::TestCase
|
|
32
32
|
|
33
33
|
end
|
34
34
|
class Xeroizer::Record::SecondRecordModel < Xeroizer::Record::BaseModel; end
|
35
|
-
|
35
|
+
|
36
36
|
class TestRecord < Xeroizer::Record::Base
|
37
|
-
|
37
|
+
|
38
38
|
string :xml_name, :api_name => 'ApiNameHere', :internal_name => :internal_name_here
|
39
39
|
string :name
|
40
|
-
|
40
|
+
|
41
41
|
end
|
42
42
|
class Xeroizer::Record::TestRecordModel < Xeroizer::Record::BaseModel; end
|
43
|
-
|
43
|
+
|
44
44
|
class SummaryOnlyRecord < Xeroizer::Record::Base
|
45
45
|
class Xeroizer::Record::SummaryOnlyRecordModel < Xeroizer::Record::BaseModel; end
|
46
|
-
|
46
|
+
|
47
47
|
list_contains_summary_only true
|
48
48
|
set_possible_primary_keys :primary_key_id
|
49
49
|
set_primary_key :primary_key_id
|
50
|
-
|
50
|
+
|
51
51
|
string :primary_key_id
|
52
52
|
string :name
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
class SummaryOnlyOffRecord < Xeroizer::Record::Base
|
56
56
|
class Xeroizer::Record::SummaryOnlyOffRecordModel < Xeroizer::Record::BaseModel; end
|
57
|
-
|
57
|
+
|
58
58
|
set_possible_primary_keys :primary_key_id
|
59
59
|
set_primary_key :primary_key_id
|
60
|
-
|
60
|
+
|
61
61
|
string :primary_key_id
|
62
62
|
string :name
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def setup
|
66
|
-
@client = Xeroizer::
|
66
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
67
67
|
parent = stub(:application => @client, :mark_dirty => nil)
|
68
68
|
@first = FirstRecord.new(parent)
|
69
69
|
@second = SecondRecord.new(parent)
|
70
70
|
@record = TestRecord.build({}, @client.Contact)
|
71
71
|
@contact = @client.Contact.build
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
context "list contains summary only test" do
|
75
|
-
|
75
|
+
|
76
76
|
should "show download complete if not summary record and id set" do
|
77
77
|
record = SummaryOnlyRecord.build({}, @client.Contact)
|
78
78
|
record.id = "NOTBLANK"
|
79
79
|
assert_equal(false, record.new_record?)
|
80
80
|
assert_equal(false, record.complete_record_downloaded?)
|
81
|
-
|
81
|
+
|
82
82
|
record = SummaryOnlyOffRecord.build({}, @client.Contact)
|
83
83
|
record.id = "NOTBLANK"
|
84
84
|
assert_equal(false, record.new_record?)
|
85
85
|
assert_equal(true, record.complete_record_downloaded?)
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
context "record field definition" do
|
91
|
-
|
91
|
+
|
92
92
|
should "define primary key with real name" do
|
93
93
|
assert_nil(@first.id)
|
94
94
|
value = "PRIMARY KEY VALUE"
|
@@ -96,7 +96,7 @@ class ModelDefinitionsTest < Test::Unit::TestCase
|
|
96
96
|
assert_equal(value, @first.primary_key_id)
|
97
97
|
assert_equal(value, @first.id)
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
should "define primary key with shortcut #id method" do
|
101
101
|
assert_nil(@first.id)
|
102
102
|
value = "PRIMARY KEY VALUE"
|
@@ -104,7 +104,7 @@ class ModelDefinitionsTest < Test::Unit::TestCase
|
|
104
104
|
assert_equal(value, @first.id)
|
105
105
|
assert_equal(value, @first.primary_key_id)
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
should "only have proper fields" do
|
109
109
|
fieldset = [:primary_key_id, :string1, :boolean1, :integer1, :decimal1, :date1, :datetime1]
|
110
110
|
fieldset.each do | field |
|
@@ -116,16 +116,16 @@ class ModelDefinitionsTest < Test::Unit::TestCase
|
|
116
116
|
fieldset.each do | field |
|
117
117
|
assert(@second.class.fields.keys.include?(field), "#{field} not in SecondRecord.fields")
|
118
118
|
end
|
119
|
-
assert_equal(fieldset.size, @second.class.fields.size)
|
119
|
+
assert_equal(fieldset.size, @second.class.fields.size)
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
should "have correct names" do
|
123
123
|
assert(@record.respond_to?(:internal_name_here), "Internal name should be internal_name_here")
|
124
124
|
assert(@record.class.fields.keys.include?(:xml_name), "Field key name should be xml_name")
|
125
125
|
assert_equal('ApiNameHere', @record.class.fields[:xml_name][:api_name])
|
126
126
|
end
|
127
|
-
|
128
|
-
should "have shortcut reader/writer" do
|
127
|
+
|
128
|
+
should "have shortcut reader/writer" do
|
129
129
|
assert_nil(@first.string1)
|
130
130
|
value = 'TEST VALUE'
|
131
131
|
@first.string1 = value
|
@@ -136,30 +136,30 @@ class ModelDefinitionsTest < Test::Unit::TestCase
|
|
136
136
|
@first[:string1] = value
|
137
137
|
assert_equal(value, @first.attributes[:string1])
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
should "define reader/writer methods" do
|
141
141
|
assert(@record.respond_to?(:name), "FirstRecord#name should exist.")
|
142
142
|
assert(@record.respond_to?(:name=), "FirstRecord#name= should exist.")
|
143
|
-
|
143
|
+
|
144
144
|
value = "TEST NAME"
|
145
145
|
@record.attributes[:name] = value
|
146
146
|
assert_equal(value, @record.attributes[:name])
|
147
147
|
assert_equal(value, @record[:name])
|
148
148
|
assert_equal(value, @record.name)
|
149
|
-
|
149
|
+
|
150
150
|
value = "TEST DIFFERENT"
|
151
151
|
@record.name = value
|
152
152
|
assert_equal(value, @record.attributes[:name])
|
153
153
|
assert_equal(value, @record[:name])
|
154
154
|
assert_equal(value, @record.name)
|
155
|
-
|
155
|
+
|
156
156
|
value = "TEST DIFFERENT AGAIN"
|
157
157
|
@record[:name] = value
|
158
158
|
assert_equal(value, @record.attributes[:name])
|
159
159
|
assert_equal(value, @record[:name])
|
160
160
|
assert_equal(value, @record.name)
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
module Xeroizer
|
4
4
|
module Record
|
@@ -27,7 +27,7 @@ class ParseParamsTest < Test::Unit::TestCase
|
|
27
27
|
include TestHelper
|
28
28
|
|
29
29
|
def setup
|
30
|
-
@client = Xeroizer::
|
30
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
31
31
|
@model = Xeroizer::Record::ParseParamTestModel.new(@client, "ParseParamTest")
|
32
32
|
end
|
33
33
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
module Xeroizer
|
4
4
|
module Record
|
5
|
-
|
5
|
+
|
6
6
|
class WhereHashTestModel < BaseModel
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
class WhereHashTest < Base
|
10
10
|
|
11
11
|
set_primary_key :primary_key_id
|
@@ -19,32 +19,32 @@ module Xeroizer
|
|
19
19
|
datetime :datetime1
|
20
20
|
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
25
25
|
|
26
26
|
class ParseWhereHashTest < Test::Unit::TestCase
|
27
27
|
include TestHelper
|
28
|
-
|
28
|
+
|
29
29
|
def setup
|
30
|
-
@client = Xeroizer::
|
30
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
31
31
|
@model = Xeroizer::Record::WhereHashTestModel.new(@client, "WhereHashTest")
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
context "where hash" do
|
35
|
-
|
35
|
+
|
36
36
|
should "parse valid hash" do
|
37
37
|
@model.send(:parse_where_hash, {
|
38
|
-
:primary_key_id => 'f7eca431-5c97-4d24-93fd-004bb8a6c644',
|
39
|
-
:string1 => 'test',
|
40
|
-
:boolean1 => true,
|
38
|
+
:primary_key_id => 'f7eca431-5c97-4d24-93fd-004bb8a6c644',
|
39
|
+
:string1 => 'test',
|
40
|
+
:boolean1 => true,
|
41
41
|
:integer1 => 10,
|
42
42
|
:decimal1 => 123.45,
|
43
43
|
:date1 => Date.parse("2010-01-05"),
|
44
44
|
:datetime1 => Time.parse("2010-02-30 09:10:20")
|
45
45
|
})
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
should 'have valid expression components' do
|
49
49
|
assert_equal('String1=="abc"', CGI.unescape(@model.send(:parse_where_hash, {:string1 => 'abc'})))
|
50
50
|
assert_equal('String1<>"abc"', CGI.unescape(@model.send(:parse_where_hash, {:string1_is_not => 'abc'})))
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class RecordAssociationTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@client = Xeroizer::
|
7
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
8
8
|
mock_api('Invoices')
|
9
9
|
@client.stubs(:http_put).returns(get_record_xml(:invoice, "762aa45d-4632-45b5-8087-b4f47690665e"))
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
context "belongs_to association" do
|
13
|
-
|
13
|
+
|
14
14
|
should "auto-load complete record if summary" do
|
15
15
|
invoice = @client.Invoice.first
|
16
16
|
assert_nil(invoice.attributes[:contact].contact_status)
|
@@ -18,11 +18,11 @@ class RecordAssociationTest < Test::Unit::TestCase
|
|
18
18
|
assert_not_nil(invoice.contact.contact_status)
|
19
19
|
assert_equal(true, invoice.complete_record_downloaded?)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
context "has_many association" do
|
25
|
-
|
25
|
+
|
26
26
|
should "auto-load complete records if summary" do
|
27
27
|
invoice = @client.Invoice.first
|
28
28
|
assert_nil(invoice.attributes[:line_items])
|
@@ -30,7 +30,7 @@ class RecordAssociationTest < Test::Unit::TestCase
|
|
30
30
|
assert(invoice.line_items.size > 0, "There should be one or more line items.")
|
31
31
|
assert_equal(true, invoice.complete_record_downloaded?)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
should "auto-build belongs_to item when passed hash" do
|
35
35
|
invoice = @client.Invoice.build
|
36
36
|
assert_nil(invoice.contact)
|
@@ -38,7 +38,7 @@ class RecordAssociationTest < Test::Unit::TestCase
|
|
38
38
|
assert_kind_of(Xeroizer::Record::Contact, invoice.contact)
|
39
39
|
assert_equal("Test Contact", invoice.contact.name)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
should "auto-build has_many items when passed hash" do
|
43
43
|
contact = @client.Contact.build
|
44
44
|
assert_equal([], contact.phones)
|
@@ -46,11 +46,11 @@ class RecordAssociationTest < Test::Unit::TestCase
|
|
46
46
|
assert_kind_of(Xeroizer::Record::Phone, contact.phones.first)
|
47
47
|
assert_equal("1234", contact.phones.first.number)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
should "auto-build has_many items when passed array" do
|
51
51
|
contact = @client.Contact.build
|
52
52
|
assert_equal([], contact.phones)
|
53
|
-
|
53
|
+
|
54
54
|
data = [
|
55
55
|
{:type => "DEFAULT", :number => "1111"},
|
56
56
|
{:type => "FAX", :number => "2222"}
|
@@ -58,12 +58,12 @@ class RecordAssociationTest < Test::Unit::TestCase
|
|
58
58
|
contact.phones = data.dup
|
59
59
|
|
60
60
|
assert_equal(2, contact.phones.size)
|
61
|
-
contact.phones.each_with_index do | phone, index |
|
61
|
+
contact.phones.each_with_index do | phone, index |
|
62
62
|
assert_kind_of(Xeroizer::Record::Phone, phone)
|
63
63
|
assert_equal(data[index][:number], phone.number)
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
should "retain unsaved items after create" do
|
68
68
|
invoice = @client.Invoice.build :type => "ACCREC", :contact => { :name => "A" }
|
69
69
|
invoice.save
|
@@ -89,5 +89,5 @@ class RecordAssociationTest < Test::Unit::TestCase
|
|
89
89
|
assert_equal(1, invoice.line_items.size, "There should be one line item.")
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class ValidatorsTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
|
-
|
5
|
+
|
6
6
|
class Xeroizer::Record::TestModel < Xeroizer::Record::BaseModel
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
class Xeroizer::Record::Test < Xeroizer::Record::Base
|
10
|
-
|
10
|
+
|
11
11
|
string :name
|
12
12
|
string :name_conditional_if
|
13
13
|
string :name_conditional_unless
|
@@ -16,7 +16,7 @@ class ValidatorsTest < Test::Unit::TestCase
|
|
16
16
|
string :type
|
17
17
|
string :type_blank
|
18
18
|
integer :value
|
19
|
-
|
19
|
+
|
20
20
|
belongs_to :contact
|
21
21
|
has_many :addresses
|
22
22
|
|
@@ -29,81 +29,81 @@ class ValidatorsTest < Test::Unit::TestCase
|
|
29
29
|
validates_inclusion_of :type_blank, :in => %w(phone fax mobile), :message => "not_included_blank", :allow_blanks => true
|
30
30
|
validates_associated :contact, :message => "association_invalid"
|
31
31
|
validates_associated :addresses, :message => "association_invalid_blank", :allow_blanks => true
|
32
|
-
|
32
|
+
|
33
33
|
def value_equals_ten?
|
34
34
|
value == 10
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def value_equals_twenty?
|
38
38
|
value == 20
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def setup
|
43
|
-
@client = Xeroizer::
|
43
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
44
44
|
@record = Xeroizer::Record::TestModel.new(@client, 'Test').build
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
context "associated validator" do
|
48
|
-
|
48
|
+
|
49
49
|
should "exist and be valid" do
|
50
50
|
# Nil contact
|
51
51
|
assert_equal(false, @record.valid?)
|
52
52
|
error = @record.errors_for(:contact).first
|
53
53
|
assert_not_nil(error)
|
54
54
|
assert_equal('association_invalid', error)
|
55
|
-
|
55
|
+
|
56
56
|
# Valid contact
|
57
57
|
@record.build_contact({:name => 'VALID NAME'})
|
58
58
|
@record.valid?
|
59
59
|
error = @record.errors_for(:contact).first
|
60
60
|
assert_nil(error)
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
should "exist and be valid unless allowed to be blank" do
|
64
64
|
# Nil address
|
65
65
|
assert_equal(false, @record.valid?)
|
66
66
|
error = @record.errors_for(:addresses).first
|
67
67
|
assert_nil(error)
|
68
|
-
|
68
|
+
|
69
69
|
# Valid address
|
70
70
|
@record.add_address(:type => 'STREET')
|
71
71
|
@record.valid?
|
72
72
|
error = @record.errors_for(:addresses).first
|
73
73
|
assert_nil(error)
|
74
|
-
|
74
|
+
|
75
75
|
# Invalid address
|
76
76
|
@record.addresses[0].type = "INVALID TYPE"
|
77
77
|
@record.valid?
|
78
78
|
error = @record.errors_for(:addresses).first
|
79
79
|
assert_equal('association_invalid_blank', error)
|
80
|
-
|
80
|
+
|
81
81
|
# One invalid address
|
82
82
|
@record.add_address(:type => 'STREET')
|
83
83
|
assert_equal(2, @record.addresses.size)
|
84
84
|
@record.valid?
|
85
85
|
error = @record.errors_for(:addresses).first
|
86
|
-
assert_equal('association_invalid_blank', error)
|
86
|
+
assert_equal('association_invalid_blank', error)
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
context "inclusion validator" do
|
92
|
-
|
92
|
+
|
93
93
|
should "be included in list" do
|
94
94
|
# Nil type
|
95
95
|
assert_equal(false, @record.valid?)
|
96
96
|
error = @record.errors_for(:type).first
|
97
97
|
assert_not_nil(error)
|
98
98
|
assert_equal('not_included', error)
|
99
|
-
|
99
|
+
|
100
100
|
# Invalid type
|
101
101
|
@record.type = 'phone not valid'
|
102
102
|
@record.valid?
|
103
103
|
error = @record.errors_for(:type).first
|
104
104
|
assert_not_nil(error)
|
105
105
|
assert_equal('not_included', error)
|
106
|
-
|
106
|
+
|
107
107
|
# Valid type
|
108
108
|
%w(phone fax mobile).each do | valid_type |
|
109
109
|
@record.type = valid_type
|
@@ -112,20 +112,20 @@ class ValidatorsTest < Test::Unit::TestCase
|
|
112
112
|
assert_nil(error)
|
113
113
|
end
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
should "be included in list unless allowed to be blank" do
|
117
117
|
# Nil type_blank
|
118
118
|
assert_equal(false, @record.valid?)
|
119
119
|
error = @record.errors_for(:type_blank).first
|
120
120
|
assert_nil(error)
|
121
|
-
|
121
|
+
|
122
122
|
# Invalid type_blank
|
123
123
|
@record.type_blank = 'phone not valid'
|
124
124
|
@record.valid?
|
125
125
|
error = @record.errors_for(:type_blank).first
|
126
126
|
assert_not_nil(error)
|
127
127
|
assert_equal('not_included_blank', error)
|
128
|
-
|
128
|
+
|
129
129
|
# Valid type_blank
|
130
130
|
%w(phone fax mobile).each do | valid_type |
|
131
131
|
@record.type_blank = valid_type
|
@@ -134,95 +134,95 @@ class ValidatorsTest < Test::Unit::TestCase
|
|
134
134
|
assert_nil(error)
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
context "presence validator" do
|
141
|
-
|
141
|
+
|
142
142
|
should "have name" do
|
143
143
|
assert_equal(false, @record.valid?)
|
144
144
|
error = @record.errors_for(:name).first
|
145
145
|
assert_not_nil(error)
|
146
146
|
assert_equal('blank', error)
|
147
|
-
|
147
|
+
|
148
148
|
@record.name = "NOT BLANK"
|
149
149
|
@record.valid?
|
150
150
|
error = @record.errors_for(:name).first
|
151
151
|
assert_nil(error)
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
should "have name if value is 10" do
|
155
155
|
@record.value = 10
|
156
156
|
assert_equal(false, @record.valid?)
|
157
157
|
error = @record.errors_for(:name_conditional_if).first
|
158
158
|
assert_equal('blank_if_10', error)
|
159
|
-
|
159
|
+
|
160
160
|
@record.name_conditional_if = "NOT BLANK"
|
161
161
|
@record.valid?
|
162
162
|
error = @record.errors_for(:name_conditional_if).first
|
163
163
|
assert_nil(error)
|
164
|
-
|
164
|
+
|
165
165
|
@record.name_conditional_if = nil
|
166
166
|
@record.value = 50
|
167
167
|
@record.valid?
|
168
168
|
error = @record.errors_for(:name_conditional_if).first
|
169
169
|
assert_nil(error)
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
should "have name if value_equals_ten?" do
|
173
173
|
@record.value = 10
|
174
174
|
assert_equal(false, @record.valid?)
|
175
175
|
error = @record.errors_for(:name_conditional_method_if).first
|
176
176
|
assert_equal('blank_if_10', error)
|
177
|
-
|
177
|
+
|
178
178
|
@record.name_conditional_method_if = "NOT BLANK"
|
179
179
|
@record.valid?
|
180
180
|
error = @record.errors_for(:name_conditional_method_if).first
|
181
181
|
assert_nil(error)
|
182
|
-
|
182
|
+
|
183
183
|
@record.name_conditional_method_if = nil
|
184
184
|
@record.value = 50
|
185
185
|
@record.valid?
|
186
186
|
error = @record.errors_for(:name_conditional_method_if).first
|
187
187
|
assert_nil(error)
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
should "have name unless value is 20" do
|
191
191
|
@record.value = 50
|
192
192
|
assert_equal(false, @record.valid?)
|
193
193
|
error = @record.errors_for(:name_conditional_unless).first
|
194
194
|
assert_equal('blank_unless_20', error)
|
195
|
-
|
195
|
+
|
196
196
|
@record.name_conditional_unless = "NOT BLANK"
|
197
197
|
@record.valid?
|
198
198
|
error = @record.errors_for(:name_conditional_unless).first
|
199
199
|
assert_nil(error)
|
200
|
-
|
200
|
+
|
201
201
|
@record.name_conditional_unless = nil
|
202
202
|
@record.value = 20
|
203
203
|
@record.valid?
|
204
204
|
error = @record.errors_for(:name_conditional_unless).first
|
205
205
|
assert_nil(error)
|
206
206
|
end
|
207
|
-
|
207
|
+
|
208
208
|
should "have name unless value_equals_twenty?" do
|
209
209
|
@record.value = 50
|
210
210
|
assert_equal(false, @record.valid?)
|
211
211
|
error = @record.errors_for(:name_conditional_method_unless).first
|
212
212
|
assert_equal('blank_unless_20', error)
|
213
|
-
|
213
|
+
|
214
214
|
@record.name_conditional_method_unless = "NOT BLANK"
|
215
215
|
@record.valid?
|
216
216
|
error = @record.errors_for(:name_conditional_method_unless).first
|
217
217
|
assert_nil(error)
|
218
|
-
|
218
|
+
|
219
219
|
@record.name_conditional_method_unless = nil
|
220
220
|
@record.value = 20
|
221
221
|
@record.valid?
|
222
222
|
error = @record.errors_for(:name_conditional_method_unless).first
|
223
223
|
assert_nil(error)
|
224
224
|
end
|
225
|
-
|
225
|
+
|
226
226
|
end
|
227
|
-
|
227
|
+
|
228
228
|
end
|