xeroizer 0.1.3 → 0.2.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.
data/test/test_helper.rb CHANGED
@@ -39,11 +39,19 @@ module TestHelper
39
39
  end
40
40
  end
41
41
 
42
+ def get_report_xml(report_type)
43
+ get_file_as_string("reports/#{report_type.underscore}.xml")
44
+ end
45
+
42
46
  def mock_api(model_name)
43
47
  @client.stubs(:http_get).with {|client, url, params| url =~ /#{model_name}$/ }.returns(get_record_xml("#{model_name.underscore.pluralize}".to_sym))
44
48
  @client.send("#{model_name.singularize}".to_sym).all.each do | record |
45
49
  @client.stubs(:http_get).with {|client, url, params| url =~ /#{model_name}\/#{record.id}$/ }.returns(get_record_xml("#{model_name.underscore.singularize}".to_sym, record.id))
46
50
  end
47
51
  end
52
+
53
+ def mock_report_api(report_type)
54
+ @client.stubs(:http_get).with { | client, url, params | url =~ /Report\/#{report_type}$/ }.returns(get_report_xml(report_type))
55
+ end
48
56
 
49
57
  end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class RecordDefinitionTest < Test::Unit::TestCase
4
+ include TestHelper
5
+
6
+ def setup
7
+ @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ end
9
+
10
+ context "record definitions" do
11
+
12
+ should "be defined correctly" do
13
+ [
14
+ :Account, :BrandingTheme, :Contact, :CreditNote, :Currency, :Invoice,
15
+ :Item, :Journal, :ManualJournal, :Organisation, :Payment, :TaxRate,
16
+ :TrackingCategory
17
+ ].each do | record_type |
18
+ record_factory = @client.send(record_type)
19
+ assert_kind_of(Xeroizer::Record::BaseModel, record_factory)
20
+ assert_kind_of(Xeroizer::GenericApplication, record_factory.application)
21
+ assert_equal(record_type.to_s, record_factory.model_name)
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class ReportDefinitionTest < Test::Unit::TestCase
4
+ include TestHelper
5
+
6
+ def setup
7
+ @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ end
9
+
10
+ context "report definitions" do
11
+
12
+ should "be defined correctly" do
13
+ [
14
+ :AgedPayablesByContact, :AgedReceivablesByContact, :BalanceSheet, :BankStatement, :BankSummary,
15
+ :BudgetSummary, :ExecutiveSummary, :ProfitAndLoss, :TrialBalance
16
+ ].each do | report_type |
17
+ report_factory = @client.send(report_type)
18
+ assert_kind_of(Xeroizer::Report::Factory, report_factory)
19
+ assert_kind_of(Xeroizer::GenericApplication, report_factory.application)
20
+ assert_equal(report_type.to_s, report_factory.report_type)
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,145 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class FactoryTest < Test::Unit::TestCase
4
+ include TestHelper
5
+
6
+ def setup
7
+ @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ mock_report_api("TrialBalance")
9
+ @report = @client.TrialBalance.get
10
+ end
11
+
12
+ context "report factory" do
13
+
14
+ should "have correct API-part of URL based on its type" do
15
+ [
16
+ :AgedPayablesByContact, :AgedReceivablesByContact, :BalanceSheet, :BankStatement, :BankSummary,
17
+ :BudgetSummary, :ExecutiveSummary, :ProfitAndLoss, :TrialBalance
18
+ ].each do | report_type |
19
+ report_factory = @client.send(report_type)
20
+ assert_equal("Report/#{report_type}", report_factory.api_controller_name)
21
+ end
22
+ end
23
+
24
+ should "build report model from XML" do
25
+ assert_kind_of(Xeroizer::Report::Base, @report)
26
+ end
27
+
28
+ should "have all attributes in report summary" do
29
+ assert_equal("TrialBalance", @report.id)
30
+ assert_equal("TrialBalance", @report.type)
31
+ assert_equal("Trial Balance", @report.name)
32
+ assert_equal(['Trial Balance', 'Demo Company (AU)', 'As at 23 March 2011'], @report.titles)
33
+ assert_equal(Date.parse('2011-03-23'), @report.date)
34
+ assert_equal(Time.parse('2011-03-23T00:29:12.6021453Z'), @report.updated_at)
35
+ end
36
+
37
+ should "have valid rows" do
38
+ assert_not_equal(0, @report.rows.size)
39
+ @report.rows.each do | row |
40
+ assert_kind_of(Xeroizer::Report::Row, row)
41
+ assert(%w(Header Row SummaryRow Section).include?(row.type), "'#{row.type}' is not a valid row type.")
42
+ end
43
+ end
44
+
45
+ should "have cells and no rows if not Section" do
46
+ @report.rows.each do | row |
47
+ if row.type != 'Section'
48
+ assert_not_equal(0, row.cells.size)
49
+ assert_equal(0, row.rows.size)
50
+ end
51
+ end
52
+ end
53
+
54
+ should "have rows and no cells if Section" do
55
+ @report.rows.each do | row |
56
+ if row.type == 'Section'
57
+ assert_equal(0, row.cells.size)
58
+ assert_not_equal(0, row.rows.size)
59
+ end
60
+ end
61
+ end
62
+
63
+ should "convert cells to BigDecimal where possible" do
64
+ num_regex = /^[-]?\d+(\.\d+)?$/
65
+ counter = 0
66
+ @report.rows.each do | row |
67
+ if row.row? || row.summary?
68
+ row.cells.each do | cell |
69
+ counter += 1 if cell.value.is_a?(BigDecimal) && cell.value > 0
70
+ end
71
+ elsif row.section?
72
+ row.rows.each do | row |
73
+ if row.row? || row.summary?
74
+ row.cells.each do | cell |
75
+ counter += 1 if cell.value.is_a?(BigDecimal) && cell.value > 0
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ assert_not_equal(0, counter, "at least one converted number in the report should be greater than 0")
82
+ end
83
+
84
+ should "be at least one Section row with a title" do
85
+ counter = 0
86
+ @report.rows.each do | row |
87
+ counter += 1 if row.section? && row.title.to_s != ''
88
+ end
89
+ assert_not_equal(0, counter, "at least one row with type 'Section' should have a title")
90
+ end
91
+
92
+ should "have working report type helpers" do
93
+ @report.rows.each do | row |
94
+ if row.type == 'Section'
95
+ check_valid_report_type(row)
96
+ row.rows.each do | row |
97
+ check_valid_report_type(row)
98
+ end
99
+ else
100
+ check_valid_report_type(row)
101
+ end
102
+ end
103
+ end
104
+
105
+ should "have valid header row" do
106
+ assert_kind_of(Xeroizer::Report::HeaderRow, @report.header)
107
+ assert_equal(['Account', 'Debit', 'Credit', 'YTD Debit', 'YTD Credit'], @report.header.cells.map { | c | c.value })
108
+ end
109
+
110
+ should "have sections" do
111
+ assert_not_equal(0, @report.sections)
112
+ @report.sections.each do | section |
113
+ assert_kind_of(Xeroizer::Report::SectionRow, section)
114
+ end
115
+ end
116
+
117
+ should "have summary" do
118
+ assert_kind_of(Xeroizer::Report::SummaryRow, @report.summary)
119
+ assert_equal(['Total', '33244.04', '33244.04', '80938.93', '80938.93'], @report.summary.cells.map { | c | c.value.to_s })
120
+ end
121
+
122
+ should "have summary on final section for trial balance (which has a blank title)" do
123
+ section = @report.sections.last
124
+ summary = section.rows.last
125
+ assert_kind_of(Xeroizer::Report::SummaryRow, summary)
126
+ assert_nil(section.title)
127
+ assert_equal(['Total', '33244.04', '33244.04', '80938.93', '80938.93'], summary.cells.map { | c | c.value.to_s })
128
+ end
129
+
130
+ end
131
+
132
+ private
133
+
134
+ def check_valid_report_type(row)
135
+ case row.type
136
+ when 'Header' then assert_equal(true, row.header?)
137
+ when 'Row' then assert_equal(true, row.row?)
138
+ when 'SummaryRow' then assert_equal(true, row.summary?)
139
+ when 'Section' then assert_equal(true, row.section?)
140
+ else
141
+ assert(false, "Invalid type: #{row.type}")
142
+ end
143
+ end
144
+
145
+ end
data/xeroizer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{xeroizer}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wayne Robinson"]
12
- s.date = %q{2011-03-02}
12
+ s.date = %q{2011-03-23}
13
13
  s.description = %q{Ruby library for the Xero accounting system API.}
14
14
  s.email = %q{wayne.robinson@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/class_level_inheritable_attributes.rb",
30
30
  "lib/nokogiri_utils.rb",
31
31
  "lib/xeroizer.rb",
32
+ "lib/xeroizer/application_http_proxy.rb",
32
33
  "lib/xeroizer/ca-certificates.crt",
33
34
  "lib/xeroizer/exceptions.rb",
34
35
  "lib/xeroizer/generic_application.rb",
@@ -71,6 +72,16 @@ Gem::Specification.new do |s|
71
72
  "lib/xeroizer/record/validators/presence_of_validator.rb",
72
73
  "lib/xeroizer/record/validators/validator.rb",
73
74
  "lib/xeroizer/record/xml_helper.rb",
75
+ "lib/xeroizer/report/base.rb",
76
+ "lib/xeroizer/report/cell.rb",
77
+ "lib/xeroizer/report/cell_xml_helper.rb",
78
+ "lib/xeroizer/report/factory.rb",
79
+ "lib/xeroizer/report/row/header.rb",
80
+ "lib/xeroizer/report/row/row.rb",
81
+ "lib/xeroizer/report/row/section.rb",
82
+ "lib/xeroizer/report/row/summary.rb",
83
+ "lib/xeroizer/report/row/xml_helper.rb",
84
+ "lib/xeroizer/report/xml_helper.rb",
74
85
  "lib/xeroizer/response.rb",
75
86
  "test/stub_responses/accounts.xml",
76
87
  "test/stub_responses/api_exception.xml",
@@ -291,6 +302,7 @@ Gem::Specification.new do |s|
291
302
  "test/stub_responses/records/manual_journal-bb6cfcfc-4500-4475-bd3a-93ee512428e0.xml",
292
303
  "test/stub_responses/records/manual_journal-f00a355b-7374-445c-886b-0437bea4095c.xml",
293
304
  "test/stub_responses/refresh_responses.rb",
305
+ "test/stub_responses/reports/trial_balance.xml",
294
306
  "test/stub_responses/tax_rates.xml",
295
307
  "test/stub_responses/token_expired",
296
308
  "test/stub_responses/tracking_categories.xml",
@@ -307,6 +319,9 @@ Gem::Specification.new do |s|
307
319
  "test/unit/record/parse_where_hash_test.rb",
308
320
  "test/unit/record/record_association_test.rb",
309
321
  "test/unit/record/validators_test.rb",
322
+ "test/unit/record_definition_test.rb",
323
+ "test/unit/report_definition_test.rb",
324
+ "test/unit/report_test.rb",
310
325
  "xeroizer.gemspec"
311
326
  ]
312
327
  s.homepage = %q{http://github.com/waynerobinson/xeroizer}
@@ -327,7 +342,10 @@ Gem::Specification.new do |s|
327
342
  "test/unit/record/model_definition_test.rb",
328
343
  "test/unit/record/parse_where_hash_test.rb",
329
344
  "test/unit/record/record_association_test.rb",
330
- "test/unit/record/validators_test.rb"
345
+ "test/unit/record/validators_test.rb",
346
+ "test/unit/record_definition_test.rb",
347
+ "test/unit/report_definition_test.rb",
348
+ "test/unit/report_test.rb"
331
349
  ]
332
350
 
333
351
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xeroizer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Wayne Robinson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-02 00:00:00 +10:00
18
+ date: 2011-03-23 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -204,6 +204,7 @@ files:
204
204
  - lib/class_level_inheritable_attributes.rb
205
205
  - lib/nokogiri_utils.rb
206
206
  - lib/xeroizer.rb
207
+ - lib/xeroizer/application_http_proxy.rb
207
208
  - lib/xeroizer/ca-certificates.crt
208
209
  - lib/xeroizer/exceptions.rb
209
210
  - lib/xeroizer/generic_application.rb
@@ -246,6 +247,16 @@ files:
246
247
  - lib/xeroizer/record/validators/presence_of_validator.rb
247
248
  - lib/xeroizer/record/validators/validator.rb
248
249
  - lib/xeroizer/record/xml_helper.rb
250
+ - lib/xeroizer/report/base.rb
251
+ - lib/xeroizer/report/cell.rb
252
+ - lib/xeroizer/report/cell_xml_helper.rb
253
+ - lib/xeroizer/report/factory.rb
254
+ - lib/xeroizer/report/row/header.rb
255
+ - lib/xeroizer/report/row/row.rb
256
+ - lib/xeroizer/report/row/section.rb
257
+ - lib/xeroizer/report/row/summary.rb
258
+ - lib/xeroizer/report/row/xml_helper.rb
259
+ - lib/xeroizer/report/xml_helper.rb
249
260
  - lib/xeroizer/response.rb
250
261
  - test/stub_responses/accounts.xml
251
262
  - test/stub_responses/api_exception.xml
@@ -466,6 +477,7 @@ files:
466
477
  - test/stub_responses/records/manual_journal-bb6cfcfc-4500-4475-bd3a-93ee512428e0.xml
467
478
  - test/stub_responses/records/manual_journal-f00a355b-7374-445c-886b-0437bea4095c.xml
468
479
  - test/stub_responses/refresh_responses.rb
480
+ - test/stub_responses/reports/trial_balance.xml
469
481
  - test/stub_responses/tax_rates.xml
470
482
  - test/stub_responses/token_expired
471
483
  - test/stub_responses/tracking_categories.xml
@@ -482,6 +494,9 @@ files:
482
494
  - test/unit/record/parse_where_hash_test.rb
483
495
  - test/unit/record/record_association_test.rb
484
496
  - test/unit/record/validators_test.rb
497
+ - test/unit/record_definition_test.rb
498
+ - test/unit/report_definition_test.rb
499
+ - test/unit/report_test.rb
485
500
  - xeroizer.gemspec
486
501
  has_rdoc: true
487
502
  homepage: http://github.com/waynerobinson/xeroizer
@@ -531,3 +546,6 @@ test_files:
531
546
  - test/unit/record/parse_where_hash_test.rb
532
547
  - test/unit/record/record_association_test.rb
533
548
  - test/unit/record/validators_test.rb
549
+ - test/unit/record_definition_test.rb
550
+ - test/unit/report_definition_test.rb
551
+ - test/unit/report_test.rb