rconomic 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/README.md +2 -1
  2. data/lib/economic/cash_book_entry.rb +42 -36
  3. data/lib/economic/creditor.rb +67 -0
  4. data/lib/economic/creditor_contact.rb +62 -0
  5. data/lib/economic/creditor_entry.rb +26 -0
  6. data/lib/economic/current_invoice.rb +30 -10
  7. data/lib/economic/current_invoice_line.rb +2 -0
  8. data/lib/economic/debtor_entry.rb +27 -0
  9. data/lib/economic/economic.wsdl +23134 -17255
  10. data/lib/economic/entity/handle.rb +1 -1
  11. data/lib/economic/entity.rb +8 -4
  12. data/lib/economic/entry.rb +26 -0
  13. data/lib/economic/proxies/cash_book_entry_proxy.rb +53 -15
  14. data/lib/economic/proxies/creditor_contact_proxy.rb +64 -0
  15. data/lib/economic/proxies/creditor_entry_proxy.rb +42 -0
  16. data/lib/economic/proxies/creditor_proxy.rb +73 -0
  17. data/lib/economic/proxies/current_invoice_proxy.rb +2 -1
  18. data/lib/economic/proxies/debtor_entry_proxy.rb +32 -0
  19. data/lib/economic/proxies/entity_proxy.rb +2 -2
  20. data/lib/economic/proxies/entry_proxy.rb +63 -0
  21. data/lib/economic/proxies/invoice_proxy.rb +2 -1
  22. data/lib/economic/session.rb +21 -4
  23. data/lib/economic/support/string.rb +5 -0
  24. data/lib/rconomic/version.rb +1 -1
  25. data/lib/rconomic.rb +10 -0
  26. data/rconomic.gemspec +6 -1
  27. data/spec/economic/creditor_contact_spec.rb +106 -0
  28. data/spec/economic/creditor_spec.rb +52 -0
  29. data/spec/economic/current_invoice_spec.rb +14 -0
  30. data/spec/economic/debtor_entry_spec.rb +20 -0
  31. data/spec/economic/debtor_spec.rb +12 -0
  32. data/spec/economic/entity/handle_spec.rb +21 -0
  33. data/spec/economic/entity_spec.rb +31 -0
  34. data/spec/economic/entry_spec.rb +20 -0
  35. data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +35 -2
  36. data/spec/economic/proxies/creditor_contact_proxy_spec.rb +55 -0
  37. data/spec/economic/proxies/creditor_entry_proxy_spec.rb +49 -0
  38. data/spec/economic/proxies/creditor_proxy_spec.rb +81 -0
  39. data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +1 -1
  40. data/spec/economic/proxies/current_invoice_proxy_spec.rb +3 -3
  41. data/spec/economic/proxies/debtor_entry_proxy_spec.rb +47 -0
  42. data/spec/economic/proxies/entry_proxy_spec.rb +73 -0
  43. data/spec/economic/proxies/invoice_proxy_spec.rb +3 -3
  44. data/spec/fixtures/cash_book_entry_create_creditor_invoice/success.xml +11 -0
  45. data/spec/fixtures/cash_book_entry_create_creditor_payment/success.xml +11 -0
  46. data/spec/fixtures/cash_book_entry_get_data/success.xml +4 -4
  47. data/spec/fixtures/cash_book_entry_set_due_date/success.xml +6 -0
  48. data/spec/fixtures/cash_book_get_all/multiple.xml +2 -2
  49. data/spec/fixtures/cash_book_get_entries/success.xml +4 -4
  50. data/spec/fixtures/creditor_contact_get_data/success.xml +22 -0
  51. data/spec/fixtures/creditor_entry_find_by_invoice_number/many.xml +15 -0
  52. data/spec/fixtures/creditor_entry_find_by_invoice_number/single.xml +12 -0
  53. data/spec/fixtures/creditor_entry_get_data/success.xml +32 -0
  54. data/spec/fixtures/creditor_entry_match_entries/success.xml +5 -0
  55. data/spec/fixtures/creditor_find_by_number/found.xml +10 -0
  56. data/spec/fixtures/creditor_find_by_number/not_found.xml +7 -0
  57. data/spec/fixtures/creditor_get_all/multiple.xml +15 -0
  58. data/spec/fixtures/creditor_get_all/single.xml +12 -0
  59. data/spec/fixtures/creditor_get_data/success.xml +49 -0
  60. data/spec/fixtures/creditor_get_data_array/multiple.xml +93 -0
  61. data/spec/fixtures/current_invoice_book_with_number/success.xml +10 -0
  62. data/spec/fixtures/current_invoice_get_data_array/multiple.xml +4 -4
  63. data/spec/fixtures/debtor_entry_find_by_invoice_number/many.xml +15 -0
  64. data/spec/fixtures/debtor_entry_find_by_invoice_number/single.xml +12 -0
  65. data/spec/fixtures/debtor_entry_match_entries/success.xml +6 -0
  66. data/spec/fixtures/debtor_get_data_array/multiple.xml +4 -4
  67. data/spec/fixtures/entry_find_by_date_interval/many.xml +15 -0
  68. data/spec/fixtures/entry_find_by_date_interval/none.xml +9 -0
  69. data/spec/fixtures/entry_find_by_date_interval/single.xml +12 -0
  70. data/spec/fixtures/entry_find_by_serial_number_interval/many.xml +15 -0
  71. data/spec/fixtures/entry_find_by_serial_number_interval/none.xml +9 -0
  72. data/spec/fixtures/entry_find_by_serial_number_interval/single.xml +12 -0
  73. data/spec/fixtures/entry_get_data/success.xml +40 -0
  74. data/spec/fixtures/entry_get_last_used_serial_number/success.xml +8 -0
  75. data/spec/spec_helper.rb +22 -2
  76. metadata +68 -11
  77. data/Gemfile.lock +0 -61
  78. data/spec/fixtures/wsdl.xml +0 -56596
@@ -0,0 +1,106 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::CreditorContact do
4
+ let(:session) { make_session }
5
+ subject { Economic::CreditorContact.new(:session => session) }
6
+
7
+ it "inherits from Economic::Entity" do
8
+ Economic::CreditorContact.ancestors.should include(Economic::Entity)
9
+ end
10
+
11
+ context "when saving" do
12
+ context "when creditor contact is new" do
13
+ subject { Economic::CreditorContact.new(:session => session) }
14
+
15
+ context "when creditor_handle is nil" do
16
+ before :each do
17
+ subject.creditor_handle = nil
18
+ end
19
+
20
+ it "should send request and let e-conomic return an error" do
21
+ session.expects(:request)
22
+ subject.save
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ describe ".creditor" do
29
+ context "when creditor_handle is not set" do
30
+ it "returns nil" do
31
+ subject.creditor.should be_nil
32
+ end
33
+ end
34
+
35
+ context "when creditor_handle is set" do
36
+ let(:handle) { Economic::CreditorContact::Handle.new({:number => 42}) }
37
+
38
+ before :each do
39
+ subject.creditor_handle = handle
40
+ end
41
+
42
+ it "returns a Creditor" do
43
+ session.creditors.expects(:find).with(42).returns(Economic::Creditor.new)
44
+ subject.creditor.should be_instance_of(Economic::Creditor)
45
+ end
46
+
47
+ it "only looks up the creditor the first time" do
48
+ session.creditors.expects(:find).with(42).returns(Economic::Creditor.new)
49
+ subject.creditor.should === subject.creditor
50
+ end
51
+ end
52
+ end
53
+
54
+ describe ".creditor=" do
55
+ let(:creditor) { make_creditor }
56
+ it "should set creditor_handle" do
57
+ subject.creditor = creditor
58
+ subject.creditor_handle.should == creditor.handle
59
+ end
60
+ end
61
+
62
+ describe ".creditor_handle=" do
63
+ let(:creditor) { make_creditor }
64
+ let(:handle) { creditor.handle }
65
+
66
+ it "should set creditor_handle" do
67
+ subject.creditor_handle = handle
68
+ subject.creditor_handle.should == handle
69
+ end
70
+
71
+ context "when creditor handle is for a different Creditor" do
72
+ before :each do
73
+ subject.creditor = creditor
74
+ end
75
+
76
+ it "should clear cached creditor and fetch the new creditor from API" do
77
+ savon.stubs('Creditor_GetData').returns(:success)
78
+ subject.creditor_handle = Economic::Creditor::Handle.new({:number => 1234})
79
+ subject.creditor.should be_instance_of(Economic::Creditor)
80
+ end
81
+ end
82
+
83
+ context "when creditor handle is for the current Creditor" do
84
+ before :each do
85
+ subject.creditor = creditor
86
+ end
87
+
88
+ it "should not clear cached creditor nor fetch the creditor from API" do
89
+ savon.stubs('Creditor_GetData').never
90
+ subject.creditor_handle = handle
91
+ subject.creditor.should be_instance_of(Economic::Creditor)
92
+ end
93
+ end
94
+ end
95
+
96
+ describe ".proxy" do
97
+ it "should return a CreditorContactProxy" do
98
+ subject.proxy.should be_instance_of(Economic::CreditorContactProxy)
99
+ end
100
+
101
+ it "should return a proxy owned by session" do
102
+ subject.proxy.session.should == session
103
+ end
104
+ end
105
+
106
+ end
@@ -0,0 +1,52 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::Creditor do
4
+ let(:session) { make_session }
5
+ subject { Economic::Creditor.new(:session => session) }
6
+
7
+ it "inherits from Economic::Entity" do
8
+ Economic::Creditor.ancestors.should include(Economic::Entity)
9
+ end
10
+
11
+ describe "class methods" do
12
+ subject { Economic::Creditor }
13
+
14
+ describe ".proxy" do
15
+ it "should return CreditorProxy" do
16
+ subject.proxy.should == Economic::CreditorProxy
17
+ end
18
+ end
19
+
20
+ describe ".key" do
21
+ it "should == :creditor" do
22
+ Economic::Creditor.key.should == :creditor
23
+ end
24
+ end
25
+ end
26
+
27
+ describe ".contacts" do
28
+ it "returns a CreditorContactProxy" do
29
+ subject.contacts.should be_instance_of(Economic::CreditorContactProxy)
30
+ end
31
+
32
+ it "memoizes the proxy" do
33
+ subject.contacts.should === subject.contacts
34
+ end
35
+
36
+ it "should store the session" do
37
+ subject.session.should_not be_nil
38
+ subject.contacts.session.should == subject.session
39
+ end
40
+ end
41
+
42
+ describe ".proxy" do
43
+ it "should return a CreditorProxy" do
44
+ subject.proxy.should be_instance_of(Economic::CreditorProxy)
45
+ end
46
+
47
+ it "should return a proxy owned by session" do
48
+ subject.proxy.session.should == session
49
+ end
50
+ end
51
+
52
+ end
@@ -90,6 +90,20 @@ describe Economic::CurrentInvoice do
90
90
  end
91
91
  end
92
92
 
93
+ describe "#book_with_number" do
94
+ it 'should book the current invoice with the given number and return the created invoice object' do
95
+ savon.stubs('CurrentInvoice_BookWithNumber').returns(:success)
96
+ savon.expects("Invoice_GetData").with('entityHandle' => { 'Number' => 123 }).returns(:success)
97
+ subject.book_with_number(123).should be_instance_of(Economic::Invoice)
98
+ end
99
+
100
+ it 'should request with the right key for handle' do
101
+ savon.stubs('Invoice_GetData').returns(:success)
102
+ savon.expects("CurrentInvoice_BookWithNumber").with('currentInvoiceHandle' => { 'Id' => 512 }, 'number' => 123, :order! => ['currentInvoiceHandle', 'number']).returns(:success)
103
+ subject.book_with_number(123)
104
+ end
105
+ end
106
+
93
107
  describe "#attention" do
94
108
  let(:contact) { (c = Economic::DebtorContact.new).tap { c.session = session }}
95
109
 
@@ -0,0 +1,20 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::DebtorEntry do
4
+ let(:session) { make_session }
5
+ subject { Economic::DebtorEntry.new(:session => session) }
6
+
7
+ it "inherits from Economic::Entity" do
8
+ Economic::DebtorEntry.ancestors.should include(Economic::Entity)
9
+ end
10
+
11
+ describe ".proxy" do
12
+ it "should return a DebtorEntryProxy" do
13
+ subject.proxy.should be_instance_of(Economic::DebtorEntryProxy)
14
+ end
15
+
16
+ it "should return a proxy owned by session" do
17
+ subject.proxy.session.should == session
18
+ end
19
+ end
20
+ end
@@ -81,4 +81,16 @@ describe Economic::Debtor do
81
81
  end
82
82
  end
83
83
 
84
+ describe "equality" do
85
+ context "when other handle is equal" do
86
+ context "when other is a different class" do
87
+ let(:other) { Economic::Invoice.new(:session => session, :handle => subject.handle) }
88
+
89
+ it "should return false" do
90
+ subject.should_not == other
91
+ end
92
+ end
93
+ end
94
+ end
95
+
84
96
  end
@@ -18,6 +18,27 @@ describe Economic::Entity::Handle do
18
18
  it "should not be equal when id or number is equal and the other isn't" do
19
19
  handle_a.should_not == handle_d
20
20
  end
21
+
22
+ describe "CashBookEntry handles" do
23
+ let(:handle_a) { Economic::Entity::Handle.new(:id1 => 1, :id2 => 2) }
24
+
25
+ context "when id1 and id2 values are equal" do
26
+ let(:handle_b) { Economic::Entity::Handle.new(:id1 => 1, :id2 => 2) }
27
+
28
+ it "should be equal" do
29
+ handle_a.should == handle_b
30
+ end
31
+ end
32
+
33
+ context "when id1 and id2 values are different" do
34
+ let(:handle_b) { Economic::Entity::Handle.new(:id1 => 11, :id2 => 12) }
35
+
36
+ it "should_not be equal" do
37
+ handle_a.should_not == handle_b
38
+ end
39
+ end
40
+ end
41
+
21
42
  end
22
43
 
23
44
  describe ".new" do
@@ -213,4 +213,35 @@ describe Economic::Entity do
213
213
  subject.update_properties(:foo => 'bar', 'baz' => 'qux')
214
214
  end
215
215
  end
216
+
217
+ describe "equality" do
218
+ context "when other is nil do" do
219
+ let(:other) { nil }
220
+
221
+ it "should return true" do
222
+ subject.should_not == other
223
+ end
224
+ end
225
+
226
+ context "when other handle is equal" do
227
+ context "when other is same class" do
228
+ let(:other) { Economic::Entity.new(:session => session, :handle => subject.handle) }
229
+
230
+ it "should return true" do
231
+ subject.should == other
232
+ end
233
+ end
234
+
235
+ context "when other is child class" do
236
+ let(:other) { Economic::Debtor.new(:session => session, :handle => subject.handle) }
237
+
238
+ it "should return true" do
239
+ subject.should == other
240
+ end
241
+ end
242
+ end
243
+
244
+
245
+
246
+ end
216
247
  end
@@ -0,0 +1,20 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::Entry do
4
+ let(:session) { make_session }
5
+ subject { Economic::Entry.new(:session => session) }
6
+
7
+ it "inherits from Economic::Entity" do
8
+ Economic::Entry.ancestors.should include(Economic::Entity)
9
+ end
10
+
11
+ describe ".proxy" do
12
+ it "should return a EntryProxy" do
13
+ subject.proxy.should be_instance_of(Economic::EntryProxy)
14
+ end
15
+
16
+ it "should return a proxy owned by session" do
17
+ subject.proxy.session.should == session
18
+ end
19
+ end
20
+ end
@@ -51,11 +51,44 @@ describe Economic::CashBookEntryProxy do
51
51
  end
52
52
  end
53
53
 
54
+ describe "#create_creditor_invoice" do
55
+ it 'should create a creditor invoice and then return the created cash book entry' do
56
+ savon.stubs('CashBookEntry_CreateCreditorInvoice').returns(:success)
57
+ savon.stubs('CashBookEntry_GetData').with(:id1 => 13, :id2 => 14).returns(:success)
58
+ cash_book_entry = subject.create_creditor_invoice(:creditor_handle => { :number => 2 }, :contra_account_handle => { :number => 3 })
59
+ cash_book_entry.should be_instance_of(Economic::CashBookEntry)
60
+ end
61
+
62
+ it 'should not send handles that were not given' do
63
+ savon.stubs('CashBookEntry_CreateCreditorInvoice').with(:cashBookHandle => { 'Number' => 13 }).returns(:success)
64
+ savon.stubs('CashBookEntry_GetData').with(:id1 => 13, :id2 => 14).returns(:success)
65
+ cash_book_entry = subject.create_creditor_invoice({})
66
+ cash_book_entry.should be_instance_of(Economic::CashBookEntry)
67
+ end
68
+ end
69
+
70
+ describe "#create_creditor_payment" do
71
+ it 'should create a creditor payment and then return the created cash book entry' do
72
+ savon.stubs('CashBookEntry_CreateCreditorPayment').returns(:success)
73
+ savon.stubs('CashBookEntry_GetData').with(:id1 => 13, :id2 => 14).returns(:success)
74
+ cash_book_entry = subject.create_creditor_payment(:creditor_handle => { :number => 2 }, :contra_account_handle => { :number => 3 })
75
+ cash_book_entry.should be_instance_of(Economic::CashBookEntry)
76
+ end
77
+ end
78
+
79
+ describe "#set_due_date" do
80
+ it 'should set due date' do
81
+ savon.expects('CashBookEntry_SetDueDate').with("cashBookEntryHandle" => { "Id1" => subject.owner.id, "Id2" => 234 }, :value => Date.new(2012, 12, 21)).returns(:success)
82
+ subject.set_due_date(234, Date.new(2012, 12, 21))
83
+ end
84
+ end
85
+
54
86
  describe "#all" do
55
87
  it 'should get the cash book entries' do
56
88
  savon.stubs('CashBook_GetEntries').returns(:success)
57
- savon.stubs('CashBookEntry_GetData').returns(:success)
58
- subject.all.size.should == 2
89
+ subject.expects(:find).in_sequence.with({:id1 => '1', :id2 => '2'})
90
+ subject.expects(:find).in_sequence.with({:id1 => '11', :id2 => '12'})
91
+ subject.all
59
92
  end
60
93
  end
61
94
 
@@ -0,0 +1,55 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::CreditorContactProxy do
4
+ let(:session) { make_session }
5
+ subject { Economic::CreditorContactProxy.new(session) }
6
+
7
+ describe ".new" do
8
+ it "stores session" do
9
+ subject.session.should === session
10
+ end
11
+ end
12
+
13
+ describe ".build" do
14
+ it "instantiates a new CreditorContact" do
15
+ subject.build.should be_instance_of(Economic::CreditorContact)
16
+ end
17
+
18
+ it "assigns the session to the CreditorContact" do
19
+ subject.build.session.should === session
20
+ end
21
+
22
+ it "should not build a partial CreditorContact" do
23
+ subject.build.should_not be_partial
24
+ end
25
+
26
+ context "when owner is a Creditor" do
27
+ let(:creditor) { make_creditor(:session => session) }
28
+ subject { creditor.contacts }
29
+
30
+ it "should use the Creditors session" do
31
+ subject.build.session.should == creditor.session
32
+ end
33
+
34
+ it "should initialize with values from Creditor" do
35
+ contact = subject.build
36
+ contact.creditor_handle.should == creditor.handle
37
+ end
38
+ end
39
+ end
40
+
41
+ describe ".find" do
42
+ before :each do
43
+ savon.stubs('CreditorContact_GetData').returns(:success)
44
+ end
45
+
46
+ it "gets contact data from API" do
47
+ savon.expects('CreditorContact_GetData').with('entityHandle' => {'Id' => 42}).returns(:success)
48
+ subject.find(42)
49
+ end
50
+
51
+ it "returns CreditorContact object" do
52
+ subject.find(42).should be_instance_of(Economic::CreditorContact)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,49 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::CreditorEntryProxy do
4
+ let(:session) { make_session }
5
+ subject { Economic::CreditorEntryProxy.new(session) }
6
+
7
+ describe "new" do
8
+ it "stores session" do
9
+ subject.session.should === session
10
+ end
11
+ end
12
+
13
+ describe "#find_by_invoice_number" do
14
+ it 'should be able to find multiple creditor entries' do
15
+ savon.expects("CreditorEntry_FindByInvoiceNumber").with('invoiceNumber' => '123').returns(:many)
16
+ subject.find_by_invoice_number('123').should == [1, 2]
17
+ end
18
+
19
+ it 'should handle a single serial number in the response' do
20
+ savon.stubs("CreditorEntry_FindByInvoiceNumber").returns(:single)
21
+ subject.find_by_invoice_number('123').should == [1]
22
+ end
23
+ end
24
+
25
+ describe "#find" do
26
+ it 'should get a creditor entry by serial number' do
27
+ savon.expects("CreditorEntry_GetData").with('entityHandle' => { 'SerialNumber' => '123' }).returns(:success)
28
+ subject.find('123').should be_instance_of(Economic::CreditorEntry)
29
+ end
30
+ end
31
+
32
+ describe "#match" do
33
+ it 'should match two creditor entries by serial numbers' do
34
+ savon.stubs("CreditorEntry_MatchEntries").with(
35
+ :entries => [
36
+ { :creditor_entry_handle => { :serial_number => 1 } },
37
+ { :credior_entry_handle => { :serial_number => 2 } }
38
+ ]
39
+ ).returns(:success)
40
+ subject.match(1, 2)
41
+ end
42
+ end
43
+
44
+ describe "#entity_class" do
45
+ it "should return Economic::CreditorEntry" do
46
+ Economic::CreditorEntryProxy.entity_class.should == Economic::CreditorEntry
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,81 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::CreditorProxy do
4
+ let(:session) { make_session }
5
+ subject { Economic::CreditorProxy.new(session) }
6
+
7
+ describe "new" do
8
+ it "stores session" do
9
+ subject.session.should === session
10
+ end
11
+ end
12
+
13
+ describe "find" do
14
+ before :each do
15
+ savon.stubs('Creditor_GetData').returns(:success)
16
+ end
17
+
18
+ it "gets creditor data from API" do
19
+ savon.expects('Creditor_GetData').with('entityHandle' => {'Number' => 42}).returns(:success)
20
+ subject.find(42)
21
+ end
22
+
23
+ it "returns Creditor object" do
24
+ subject.find(42).should be_instance_of(Economic::Creditor)
25
+ end
26
+ end
27
+
28
+ describe "find_by_number" do
29
+ it "can find a creditor" do
30
+ savon.expects('Creditor_FindByNumber').with('number' => '1').returns(:found)
31
+ result = subject.find_by_number('1')
32
+ result.should be_instance_of(Economic::Creditor)
33
+ result.number.should == 1
34
+ result.partial.should be_true
35
+ result.persisted.should be_true
36
+ result.handle.should == Economic::Entity::Handle.new({ :number => 1 })
37
+ end
38
+
39
+ it "returns nil when there is no creditor" do
40
+ savon.expects('Creditor_FindByNumber').with('number' => '1').returns(:not_found)
41
+ result = subject.find_by_number('1')
42
+ result.should be_nil
43
+ end
44
+ end
45
+
46
+ describe "build" do
47
+ subject { session.creditors.build }
48
+
49
+ it "instantiates a new Creditor" do
50
+ subject.should be_instance_of(Economic::Creditor)
51
+ end
52
+
53
+ it "assigns the session to the Creditor" do
54
+ subject.session.should === session
55
+ end
56
+ end
57
+
58
+ describe "#entity_class" do
59
+ it "should return Economic::Creditor" do
60
+ Economic::CreditorProxy.entity_class.should == Economic::Creditor
61
+ end
62
+ end
63
+
64
+ describe ".all" do
65
+ it "returns a single creditor" do
66
+ savon.expects('Creditor_GetAll').returns(:single)
67
+ savon.expects('Creditor_GetData').with('entityHandle' => {'Number' => 1}).returns(:success)
68
+ all = subject.all
69
+ all.size.should == 1
70
+ all.first.should be_instance_of(Economic::Creditor)
71
+ end
72
+
73
+ it "returns multiple creditors" do
74
+ savon.expects('Creditor_GetAll').returns(:multiple)
75
+ savon.expects('Creditor_GetDataArray').returns(:multiple)
76
+ all = subject.all
77
+ all.size.should == 2
78
+ all.first.should be_instance_of(Economic::Creditor)
79
+ end
80
+ end
81
+ end
@@ -85,7 +85,7 @@ describe Economic::CurrentInvoiceLineProxy do
85
85
  it "can be iterated over" do
86
86
  line = Economic::CurrentInvoiceLine.new
87
87
  subject << line
88
- subject.all? { |l| l == [line] }
88
+ subject.all? { |l| l.is_a?(Economic::CurrentInvoiceLine) }.should be_true
89
89
  end
90
90
  end
91
91
  end
@@ -68,7 +68,7 @@ describe Economic::CurrentInvoiceProxy do
68
68
  it "should be able to return a single current invoice" do
69
69
  from = Time.now - 60
70
70
  unto = Time.now
71
- savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:single)
71
+ savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601, :order! => ['first', 'last']).returns(:single)
72
72
  savon.expects('CurrentInvoice_GetData').returns(:success)
73
73
  results = subject.find_by_date_interval(from, unto)
74
74
  results.size.should == 1
@@ -78,7 +78,7 @@ describe Economic::CurrentInvoiceProxy do
78
78
  it "should be able to return multiple invoices" do
79
79
  from = Time.now - 60
80
80
  unto = Time.now
81
- savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:many)
81
+ savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601, :order! => ['first', 'last']).returns(:many)
82
82
  savon.expects('CurrentInvoice_GetData').returns(:success)
83
83
  savon.expects('CurrentInvoice_GetData').returns(:success)
84
84
  results = subject.find_by_date_interval(from, unto)
@@ -89,7 +89,7 @@ describe Economic::CurrentInvoiceProxy do
89
89
  it "should be able to return nothing" do
90
90
  from = Time.now - 60
91
91
  unto = Time.now
92
- savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:none)
92
+ savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601, :order! => ['first', 'last']).returns(:none)
93
93
  results = subject.find_by_date_interval(from, unto)
94
94
  results.size.should == 0
95
95
  end
@@ -0,0 +1,47 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::DebtorEntryProxy do
4
+ let(:session) { make_session }
5
+ subject { Economic::DebtorEntryProxy.new(session) }
6
+
7
+ describe "new" do
8
+ it "stores session" do
9
+ subject.session.should === session
10
+ end
11
+ end
12
+
13
+ describe "#find_by_invoice_number" do
14
+ it 'should be able to find multiple debtor entries' do
15
+ savon.expects("DebtorEntry_FindByInvoiceNumber").with('from' => '123', 'to' => '456', :order! => ['from', 'to']).returns(:many)
16
+ subject.find_by_invoice_number('123', '456').should == [1, 2]
17
+ end
18
+
19
+ it 'should be able to find debtor entries with one invoice id' do
20
+ savon.expects("DebtorEntry_FindByInvoiceNumber").with('from' => '123', 'to' => '123', :order! => ['from', 'to']).returns(:many)
21
+ subject.find_by_invoice_number('123').should == [1, 2]
22
+ end
23
+
24
+ it 'should handle a single serial number in the response' do
25
+ savon.stubs("DebtorEntry_FindByInvoiceNumber").returns(:single)
26
+ subject.find_by_invoice_number('123').should == [1]
27
+ end
28
+ end
29
+
30
+ describe "#match" do
31
+ it 'should match two debtor entries by serial numbers' do
32
+ savon.stubs("DebtorEntry_MatchEntries").with(
33
+ :entries => [
34
+ { :debtor_entry_handle => { :serial_number => 1 } },
35
+ { :debtor_entry_handle => { :serial_number => 2 } }
36
+ ]
37
+ ).returns(:success)
38
+ subject.match(1, 2)
39
+ end
40
+ end
41
+
42
+ describe "#entity_class" do
43
+ it "should return Economic::DebtorEntry" do
44
+ Economic::DebtorEntryProxy.entity_class.should == Economic::DebtorEntry
45
+ end
46
+ end
47
+ end