rconomic 0.2.1 → 0.3
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/.travis.yml +1 -0
- data/Gemfile +8 -1
- data/Gemfile.lock +8 -1
- data/Guardfile +6 -0
- data/README.md +39 -14
- data/lib/economic/account.rb +25 -0
- data/lib/economic/cash_book.rb +39 -0
- data/lib/economic/cash_book_entry.rb +111 -0
- data/lib/economic/current_invoice.rb +33 -2
- data/lib/economic/current_invoice_line.rb +1 -1
- data/lib/economic/debtor.rb +2 -1
- data/lib/economic/debtor_contact.rb +1 -1
- data/lib/economic/entity/handle.rb +66 -0
- data/lib/economic/entity.rb +39 -36
- data/lib/economic/invoice.rb +58 -0
- data/lib/economic/proxies/account_proxy.rb +22 -0
- data/lib/economic/proxies/cash_book_entry_proxy.rb +53 -0
- data/lib/economic/proxies/cash_book_proxy.rb +47 -0
- data/lib/economic/proxies/current_invoice_line_proxy.rb +7 -1
- data/lib/economic/proxies/current_invoice_proxy.rb +18 -1
- data/lib/economic/proxies/debtor_contact_proxy.rb +36 -10
- data/lib/economic/proxies/debtor_proxy.rb +32 -1
- data/lib/economic/proxies/entity_proxy.rb +30 -3
- data/lib/economic/proxies/invoice_proxy.rb +31 -0
- data/lib/economic/session.rb +18 -1
- data/lib/economic/support/string.rb +19 -0
- data/lib/rconomic/version.rb +1 -1
- data/lib/rconomic.rb +10 -2
- data/spec/economic/cash_book_entry_spec.rb +20 -0
- data/spec/economic/cash_book_spec.rb +34 -0
- data/spec/economic/current_invoice_spec.rb +44 -1
- data/spec/economic/debtor_contact_spec.rb +2 -2
- data/spec/economic/debtor_spec.rb +6 -0
- data/spec/economic/entity/handle_spec.rb +116 -0
- data/spec/economic/entity_spec.rb +26 -22
- data/spec/economic/invoice_spec.rb +68 -0
- data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +62 -0
- data/spec/economic/proxies/cash_book_proxy_spec.rb +54 -0
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +1 -1
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +66 -2
- data/spec/economic/proxies/debtor_proxy_spec.rb +39 -1
- data/spec/economic/proxies/invoice_proxy_spec.rb +75 -0
- data/spec/economic/session_spec.rb +11 -1
- data/spec/fixtures/cash_book_book/success.xml +10 -0
- data/spec/fixtures/cash_book_entry_create_debtor_payment/success.xml +11 -0
- data/spec/fixtures/cash_book_entry_create_finance_voucher/success.xml +11 -0
- data/spec/fixtures/cash_book_entry_create_from_data/success.xml +11 -0
- data/spec/fixtures/cash_book_entry_get_data/success.xml +73 -0
- data/spec/fixtures/cash_book_get_all/multiple.xml +15 -0
- data/spec/fixtures/cash_book_get_entries/success.xml +17 -0
- data/spec/fixtures/cash_book_get_name/success.xml +8 -0
- data/spec/fixtures/current_invoice_book/success.xml +10 -0
- data/spec/fixtures/current_invoice_find_by_date_interval/many.xml +15 -0
- data/spec/fixtures/current_invoice_find_by_date_interval/none.xml +8 -0
- data/spec/fixtures/current_invoice_find_by_date_interval/single.xml +12 -0
- data/spec/fixtures/current_invoice_get_all/multiple.xml +15 -0
- data/spec/fixtures/current_invoice_get_all/none.xml +8 -0
- data/spec/fixtures/current_invoice_get_all/single.xml +12 -0
- data/spec/fixtures/current_invoice_get_data_array/multiple.xml +141 -0
- data/spec/fixtures/current_invoice_get_data_array/single.xml +75 -0
- data/spec/fixtures/debtor_find_by_number/found.xml +10 -0
- data/spec/fixtures/debtor_find_by_number/not_found.xml +7 -0
- data/spec/fixtures/debtor_get_all/multiple.xml +15 -0
- data/spec/fixtures/debtor_get_all/single.xml +12 -0
- data/spec/fixtures/debtor_get_data_array/multiple.xml +103 -0
- data/spec/fixtures/invoice_find_by_date_interval/many.xml +15 -0
- data/spec/fixtures/invoice_find_by_date_interval/none.xml +9 -0
- data/spec/fixtures/invoice_find_by_date_interval/single.xml +12 -0
- data/spec/fixtures/invoice_get_data/success.xml +74 -0
- data/spec/fixtures/invoice_get_pdf/success.xml +8 -0
- data/spec/fixtures/invoice_get_remainder/success.xml +8 -0
- data/spec/fixtures/spec_entity_delete/success.xml +6 -0
- metadata +54 -6
@@ -0,0 +1,116 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Economic::Entity::Handle do
|
4
|
+
describe "equality" do
|
5
|
+
let(:handle_a) { Economic::Entity::Handle.new(:id => 1, :number => 2) }
|
6
|
+
let(:handle_b) { Economic::Entity::Handle.new(:id => 1, :number => 2) }
|
7
|
+
let(:handle_c) { Economic::Entity::Handle.new(:id => 1) }
|
8
|
+
let(:handle_d) { Economic::Entity::Handle.new(:id => 1, :number => 3) }
|
9
|
+
|
10
|
+
it "should be equal when both id and number are equal" do
|
11
|
+
handle_a.should == handle_b
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not be equal when id or number is missing" do
|
15
|
+
handle_a.should_not == handle_c
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not be equal when id or number is equal and the other isn't" do
|
19
|
+
handle_a.should_not == handle_d
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".new" do
|
24
|
+
it "should raise error if argument isn't supported" do
|
25
|
+
lambda do
|
26
|
+
Economic::Entity::Handle.new(true)
|
27
|
+
end.should raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should assume :id if argument is numeric" do
|
31
|
+
handle = Economic::Entity::Handle.new(12)
|
32
|
+
handle.id.should == 12
|
33
|
+
handle.number.should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should use to_i on numeric argument" do
|
37
|
+
handle = Economic::Entity::Handle.new("42")
|
38
|
+
handle.id.should == 42
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise error if argument is nil" do
|
42
|
+
lambda do
|
43
|
+
Economic::Entity::Handle.new(nil)
|
44
|
+
end.should raise_error(ArgumentError)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should raise error if argument contains invalid key" do
|
48
|
+
lambda do
|
49
|
+
Economic::Entity::Handle.new(:Numeric => 12)
|
50
|
+
end.should raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should raise error if argument contains invalid values" do
|
54
|
+
lambda do
|
55
|
+
Economic::Entity::Handle.new(:number => {:number => 12})
|
56
|
+
end.should raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set id" do
|
60
|
+
handle = Economic::Entity::Handle.new(:id => 12)
|
61
|
+
handle.id.should == 12
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should set number" do
|
65
|
+
handle = Economic::Entity::Handle.new(:number => 12)
|
66
|
+
handle.number.should == 12
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should set both id and number" do
|
70
|
+
handle = Economic::Entity::Handle.new(:id => 37, :number => 42)
|
71
|
+
handle.id.should == 37
|
72
|
+
handle.number.should == 42
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should set id1 and id2' do
|
76
|
+
handle = Economic::Entity::Handle.new(:id1 => 37, :id2 => 42)
|
77
|
+
handle.id1.should == 37
|
78
|
+
handle.id2.should == 42
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should to_i values" do
|
82
|
+
handle = Economic::Entity::Handle.new(:id => "37", :number => "42")
|
83
|
+
handle.id.should == 37
|
84
|
+
handle.number.should == 42
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not to_i nil values" do
|
88
|
+
handle = Economic::Entity::Handle.new(:id => "37")
|
89
|
+
handle.id.should == 37
|
90
|
+
handle.number.should be_nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should accept a Hash with capitalized keys" do
|
94
|
+
handle = Economic::Entity::Handle.new({"Id" => 37, "Number" => 42})
|
95
|
+
handle.id.should == 37
|
96
|
+
handle.number.should == 42
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should accept another Handle" do
|
100
|
+
original_handle = Economic::Entity::Handle.new(:id => 37)
|
101
|
+
handle = Economic::Entity::Handle.new(original_handle)
|
102
|
+
handle.id.should == 37
|
103
|
+
handle.number.should be_nil
|
104
|
+
handle.should == original_handle
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe ".to_hash" do
|
109
|
+
subject { Economic::Entity::Handle.new({:id => 42, :number => 37}) }
|
110
|
+
|
111
|
+
it "should return a handle for putting into the body of a SOAP request" do
|
112
|
+
subject.to_hash.should == {'Id' => 42, 'Number' => 37}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
@@ -171,6 +171,32 @@ describe Economic::Entity do
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
+
describe "destroy" do
|
175
|
+
subject { (e = SpecEntity.new).tap { |e| e.id = 42; e.persisted = true; e.partial = false; e.session = session } }
|
176
|
+
|
177
|
+
it "sends data to the API" do
|
178
|
+
savon.expects(:spec_entity_delete).returns(:success)
|
179
|
+
subject.destroy
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should request with the correct model and id" do
|
183
|
+
savon.expects(:spec_entity_delete).with('specEntityHandle' => {'Id' => 42}).returns(:success)
|
184
|
+
subject.destroy
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should mark the entity as not persisted and partial" do
|
188
|
+
savon.expects(:spec_entity_delete).returns(:success)
|
189
|
+
subject.destroy
|
190
|
+
subject.should_not be_persisted
|
191
|
+
subject.should be_partial
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should return the response" do
|
195
|
+
session.expects(:request).returns({ :response => true })
|
196
|
+
subject.destroy.should == { :response => true }
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
174
200
|
describe "update_properties" do
|
175
201
|
subject { SpecEntity.new }
|
176
202
|
|
@@ -188,25 +214,3 @@ describe Economic::Entity do
|
|
188
214
|
end
|
189
215
|
end
|
190
216
|
end
|
191
|
-
|
192
|
-
describe Economic::Entity::Handle do
|
193
|
-
|
194
|
-
describe "equality" do
|
195
|
-
let(:handle_a) { Economic::Entity::Handle.new(:id => 1, :number => 2) }
|
196
|
-
let(:handle_b) { Economic::Entity::Handle.new(:id => 1, :number => 2) }
|
197
|
-
let(:handle_c) { Economic::Entity::Handle.new(:id => 1) }
|
198
|
-
let(:handle_d) { Economic::Entity::Handle.new(:id => 1, :number => 3) }
|
199
|
-
|
200
|
-
it "should be equal when both id and number are equal" do
|
201
|
-
handle_a.should == handle_b
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should not be equal when id or number is missing" do
|
205
|
-
handle_a.should_not == handle_c
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should not be equal when id or number is equal and the other isn't" do
|
209
|
-
handle_a.should_not == handle_d
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Economic::Invoice do
|
4
|
+
let(:session) { make_session }
|
5
|
+
subject { Economic::Invoice.new(:session => session, :number => 512) }
|
6
|
+
|
7
|
+
it "inherits from Economic::Entity" do
|
8
|
+
Economic::Invoice.ancestors.should include(Economic::Entity)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#remainder' do
|
12
|
+
it 'should get the remainder' do
|
13
|
+
savon.expects('Invoice_GetRemainder').with("invoiceHandle" => { "Number" => 512 }).returns(:success)
|
14
|
+
subject.remainder.should == "512.32"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".proxy" do
|
19
|
+
it "should return a InvoiceProxy" do
|
20
|
+
subject.proxy.should be_instance_of(Economic::InvoiceProxy)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return a proxy owned by session" do
|
24
|
+
subject.proxy.session.should == session
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".key" do
|
29
|
+
it "should == :invoice" do
|
30
|
+
Economic::Invoice.key.should == :invoice
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#pdf" do
|
35
|
+
before :each do
|
36
|
+
savon.stubs('Invoice_GetPdf').returns(:success)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "gets PDF data from API" do
|
40
|
+
savon.expects('Invoice_GetPdf').with('invoiceHandle' => {'Number' => 512}).returns(:success)
|
41
|
+
subject.pdf
|
42
|
+
end
|
43
|
+
|
44
|
+
it "decodes the base64Binary encoded data" do
|
45
|
+
subject.pdf.should == 'This is not really PDF data'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#attention" do
|
50
|
+
let(:contact) { (c = Economic::DebtorContact.new).tap { c.session = session }}
|
51
|
+
|
52
|
+
it "should be set- and gettable" do
|
53
|
+
subject.attention = contact
|
54
|
+
subject.attention_handle.should == contact.handle
|
55
|
+
subject.attention.should == contact
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#debtor" do
|
60
|
+
let(:debtor) { (c = Economic::Debtor.new).tap { c.session = session }}
|
61
|
+
|
62
|
+
it "should be set- and gettable" do
|
63
|
+
subject.debtor = debtor
|
64
|
+
subject.debtor_handle.should == debtor.handle
|
65
|
+
subject.debtor.should == debtor
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Economic::CashBookEntryProxy do
|
4
|
+
|
5
|
+
let(:session) { make_session }
|
6
|
+
let(:cash_book) { Economic::CashBook.new(:session => session) }
|
7
|
+
subject { Economic::CashBookEntryProxy.new(cash_book) }
|
8
|
+
|
9
|
+
describe ".new" do
|
10
|
+
it "stores owner" do
|
11
|
+
subject.owner.should == cash_book
|
12
|
+
end
|
13
|
+
|
14
|
+
it "stores session" do
|
15
|
+
subject.session.should === session
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".build" do
|
20
|
+
it "instantiates a new CashBookEntry" do
|
21
|
+
subject.build.should be_instance_of(Economic::CashBookEntry)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "assigns the session to the CashBookEntry" do
|
25
|
+
subject.build.session.should === session
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#save" do
|
30
|
+
it 'should save it' do
|
31
|
+
savon.stubs('CashBookEntry_CreateFromData').returns(:success)
|
32
|
+
subject.build.save
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#create_finance_voucher" do
|
37
|
+
it 'should create a finance voucher and return the created cash book entry' do
|
38
|
+
savon.stubs('CashBookEntry_CreateFinanceVoucher').returns(:success)
|
39
|
+
savon.stubs('CashBookEntry_GetData').with(:id1 => 15, :id2 => 16).returns(:success)
|
40
|
+
cash_book_entry = subject.create_finance_voucher(:account_handle => { :number => 2 }, :contra_account_handle => { :number => 3 })
|
41
|
+
cash_book_entry.should be_instance_of(Economic::CashBookEntry)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#create_debtor_payment" do
|
46
|
+
it 'should create a debtor payment and then return the created cash book entry' do
|
47
|
+
savon.stubs('CashBookEntry_CreateDebtorPayment').returns(:success)
|
48
|
+
savon.stubs('CashBookEntry_GetData').with(:id1 => 13, :id2 => 14).returns(:success)
|
49
|
+
cash_book_entry = subject.create_debtor_payment(:debtor_handle => { :number => 2 }, :contra_account_handle => { :number => 3 })
|
50
|
+
cash_book_entry.should be_instance_of(Economic::CashBookEntry)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#all" do
|
55
|
+
it 'should get the cash book entries' do
|
56
|
+
savon.stubs('CashBook_GetEntries').returns(:success)
|
57
|
+
savon.stubs('CashBookEntry_GetData').returns(:success)
|
58
|
+
subject.all.size.should == 2
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Economic::CashBookProxy do
|
4
|
+
|
5
|
+
let(:session) { make_session }
|
6
|
+
subject { Economic::CashBookProxy.new(session) }
|
7
|
+
|
8
|
+
describe ".new" do
|
9
|
+
|
10
|
+
it "stores session" do
|
11
|
+
subject.session.should === session
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".build" do
|
17
|
+
|
18
|
+
it "instantiates a new CashBook" do
|
19
|
+
subject.build.should be_instance_of(Economic::CashBook)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "assigns the session to the CashBook" do
|
23
|
+
subject.build.session.should === session
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".all" do
|
29
|
+
|
30
|
+
it "returns multiple cashbooks" do
|
31
|
+
savon.expects('CashBook_GetAll').returns(:multiple)
|
32
|
+
savon.expects('CashBook_GetName').returns(:success)
|
33
|
+
savon.expects('CashBook_GetName').returns(:success)
|
34
|
+
all = subject.all
|
35
|
+
all.size.should == 2
|
36
|
+
all[0].should be_instance_of(Economic::CashBook)
|
37
|
+
all[1].should be_instance_of(Economic::CashBook)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".get_name" do
|
43
|
+
|
44
|
+
it 'returns a cash book with a name' do
|
45
|
+
savon.expects('CashBook_GetName').with("cashBookHandle" => { "Number" => "52" }).returns(:success)
|
46
|
+
result = subject.get_name("52")
|
47
|
+
result.should be_instance_of(Economic::CashBook)
|
48
|
+
result.number.should == "52"
|
49
|
+
result.name.should be_a(String)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Economic::CurrentInvoiceProxy do
|
4
|
+
|
4
5
|
let(:session) { make_session }
|
5
6
|
subject { Economic::CurrentInvoiceProxy.new(session) }
|
6
7
|
|
@@ -53,7 +54,7 @@ describe Economic::CurrentInvoiceProxy do
|
|
53
54
|
end
|
54
55
|
|
55
56
|
it "gets invoice data from API" do
|
56
|
-
savon.expects('CurrentInvoice_GetData').with('entityHandle' => {'
|
57
|
+
savon.expects('CurrentInvoice_GetData').with('entityHandle' => {'Id' => 42}).returns(:success)
|
57
58
|
subject.find(42)
|
58
59
|
end
|
59
60
|
|
@@ -61,4 +62,67 @@ describe Economic::CurrentInvoiceProxy do
|
|
61
62
|
subject.find(42).should be_instance_of(Economic::CurrentInvoice)
|
62
63
|
end
|
63
64
|
end
|
64
|
-
|
65
|
+
|
66
|
+
describe ".find_by_date_interval" do
|
67
|
+
|
68
|
+
it "should be able to return a single current invoice" do
|
69
|
+
from = Time.now - 60
|
70
|
+
unto = Time.now
|
71
|
+
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:single)
|
72
|
+
savon.expects('CurrentInvoice_GetData').returns(:success)
|
73
|
+
results = subject.find_by_date_interval(from, unto)
|
74
|
+
results.size.should == 1
|
75
|
+
results.first.should be_instance_of(Economic::CurrentInvoice)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should be able to return multiple invoices" do
|
79
|
+
from = Time.now - 60
|
80
|
+
unto = Time.now
|
81
|
+
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:many)
|
82
|
+
savon.expects('CurrentInvoice_GetData').returns(:success)
|
83
|
+
savon.expects('CurrentInvoice_GetData').returns(:success)
|
84
|
+
results = subject.find_by_date_interval(from, unto)
|
85
|
+
results.size.should == 2
|
86
|
+
results.first.should be_instance_of(Economic::CurrentInvoice)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should be able to return nothing" do
|
90
|
+
from = Time.now - 60
|
91
|
+
unto = Time.now
|
92
|
+
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:none)
|
93
|
+
results = subject.find_by_date_interval(from, unto)
|
94
|
+
results.size.should == 0
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe ".all" do
|
100
|
+
|
101
|
+
it "returns an empty array when there are no current invoices" do
|
102
|
+
savon.expects('CurrentInvoice_GetAll').returns(:none)
|
103
|
+
subject.all.size.should == 0
|
104
|
+
end
|
105
|
+
|
106
|
+
it "finds and adds a single current invoice" do
|
107
|
+
savon.expects('CurrentInvoice_GetAll').returns(:single)
|
108
|
+
savon.expects('CurrentInvoice_GetData').with('entityHandle' => {'Id' => 1}).returns(:success)
|
109
|
+
|
110
|
+
current_invoices = subject.all
|
111
|
+
current_invoices.should be_instance_of(Economic::CurrentInvoiceProxy)
|
112
|
+
|
113
|
+
current_invoices.size.should == 1
|
114
|
+
current_invoices.first.should be_instance_of(Economic::CurrentInvoice)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "adds multiple current invoices" do
|
118
|
+
savon.expects('CurrentInvoice_GetAll').returns(:multiple)
|
119
|
+
savon.expects('CurrentInvoice_GetDataArray').returns(:multiple)
|
120
|
+
|
121
|
+
current_invoices = subject.all
|
122
|
+
current_invoices.size.should == 2
|
123
|
+
current_invoices.items.first.should be_instance_of(Economic::CurrentInvoice)
|
124
|
+
current_invoices.items.last.should be_instance_of(Economic::CurrentInvoice)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
@@ -53,6 +53,24 @@ describe Economic::DebtorProxy do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
describe "find_by_number" do
|
57
|
+
it "can find a debtor" do
|
58
|
+
savon.expects('Debtor_FindByNumber').with('number' => '1').returns(:found)
|
59
|
+
result = subject.find_by_number('1')
|
60
|
+
result.should be_instance_of(Economic::Debtor)
|
61
|
+
result.number.should == 1
|
62
|
+
result.partial.should be_true
|
63
|
+
result.persisted.should be_true
|
64
|
+
result.handle.should == Economic::Entity::Handle.new({ :number => 1 })
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns nil when there is no debtor" do
|
68
|
+
savon.expects('Debtor_FindByNumber').with('number' => '1').returns(:not_found)
|
69
|
+
result = subject.find_by_number('1')
|
70
|
+
result.should be_nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
56
74
|
describe "next_available_number" do
|
57
75
|
it "gets the next available debtor number from API" do
|
58
76
|
savon.expects('Debtor_GetNextAvailableNumber').returns(:success)
|
@@ -77,4 +95,24 @@ describe Economic::DebtorProxy do
|
|
77
95
|
Economic::DebtorProxy.entity_class.should == Economic::Debtor
|
78
96
|
end
|
79
97
|
end
|
80
|
-
|
98
|
+
|
99
|
+
# Complete specs in current_invoice, no point in duplicating them here, just ensuring that
|
100
|
+
# it handles debtors "Number" id.
|
101
|
+
describe ".all" do
|
102
|
+
it "returns a single debtor" do
|
103
|
+
savon.expects('Debtor_GetAll').returns(:single)
|
104
|
+
savon.expects('Debtor_GetData').with('entityHandle' => {'Number' => 1}).returns(:success)
|
105
|
+
all = subject.all
|
106
|
+
all.size.should == 1
|
107
|
+
all.first.should be_instance_of(Economic::Debtor)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "returns multiple debtors" do
|
111
|
+
savon.expects('Debtor_GetAll').returns(:multiple)
|
112
|
+
savon.expects('Debtor_GetDataArray').returns(:multiple)
|
113
|
+
all = subject.all
|
114
|
+
all.size.should == 2
|
115
|
+
all.first.should be_instance_of(Economic::Debtor)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Economic::InvoiceProxy do
|
4
|
+
|
5
|
+
let(:session) { make_session }
|
6
|
+
subject { Economic::InvoiceProxy.new(session) }
|
7
|
+
|
8
|
+
describe ".new" do
|
9
|
+
it "stores session" do
|
10
|
+
subject.session.should === session
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".build" do
|
15
|
+
it "instantiates a new Invoice" do
|
16
|
+
subject.build.should be_instance_of(Economic::Invoice)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "assigns the session to the Invoice" do
|
20
|
+
subject.build.session.should === session
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not build a partial Invoice" do
|
24
|
+
subject.build.should_not be_partial
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".find" do
|
29
|
+
before :each do
|
30
|
+
savon.stubs('Invoice_GetData').returns(:success)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "gets invoice data from API" do
|
34
|
+
savon.expects('Invoice_GetData').with('entityHandle' => {'Number' => 42}).returns(:success)
|
35
|
+
subject.find(42)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns Invoice object" do
|
39
|
+
subject.find(42).should be_instance_of(Economic::Invoice)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".find_by_date_interval" do
|
44
|
+
|
45
|
+
it "should be able to return a single current invoice" do
|
46
|
+
from = Time.now - 60
|
47
|
+
unto = Time.now
|
48
|
+
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:single)
|
49
|
+
savon.expects('Invoice_GetData').returns(:success)
|
50
|
+
results = subject.find_by_date_interval(from, unto)
|
51
|
+
results.size.should == 1
|
52
|
+
results.first.should be_instance_of(Economic::Invoice)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be able to return multiple invoices" do
|
56
|
+
from = Time.now - 60
|
57
|
+
unto = Time.now
|
58
|
+
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:many)
|
59
|
+
savon.expects('Invoice_GetData').returns(:success)
|
60
|
+
savon.expects('Invoice_GetData').returns(:success)
|
61
|
+
results = subject.find_by_date_interval(from, unto)
|
62
|
+
results.size.should == 2
|
63
|
+
results.first.should be_instance_of(Economic::Invoice)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be able to return nothing" do
|
67
|
+
from = Time.now - 60
|
68
|
+
unto = Time.now
|
69
|
+
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:none)
|
70
|
+
results = subject.find_by_date_interval(from, unto)
|
71
|
+
results.size.should == 0
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -58,6 +58,16 @@ describe Economic::Session do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
describe "invoices" do
|
62
|
+
it "returns an InvoiceProxy" do
|
63
|
+
subject.invoices.should be_instance_of(Economic::InvoiceProxy)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "memoizes the proxy" do
|
67
|
+
subject.invoices.should === subject.invoices
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
61
71
|
describe "debtors" do
|
62
72
|
it "returns a DebtorProxy" do
|
63
73
|
subject.debtors.should be_instance_of(Economic::DebtorProxy)
|
@@ -71,4 +81,4 @@ describe Economic::Session do
|
|
71
81
|
describe "request" do
|
72
82
|
end
|
73
83
|
|
74
|
-
end
|
84
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
3
|
+
<soap:Body>
|
4
|
+
<CashBook_BookResponse xmlns="http://e-conomic.com">
|
5
|
+
<CashBook_BookResult>
|
6
|
+
<Number>832</Number>
|
7
|
+
</CashBook_BookResult>
|
8
|
+
</CashBook_BookResponse>
|
9
|
+
</soap:Body>
|
10
|
+
</soap:Envelope>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
3
|
+
<soap:Body>
|
4
|
+
<CashBookEntry_CreateDebtorPaymentResponse xmlns="http://e-conomic.com">
|
5
|
+
<CashBookEntry_CreateDebtorPaymentResult>
|
6
|
+
<Id1>13</Id1>
|
7
|
+
<Id2>14</Id2>
|
8
|
+
</CashBookEntry_CreateDebtorPaymentResult>
|
9
|
+
</CashBookEntry_CreateDebtorPaymentResponse>
|
10
|
+
</soap:Body>
|
11
|
+
</soap:Envelope>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
3
|
+
<soap:Body>
|
4
|
+
<CashBookEntry_CreateFinanceVoucherResponse xmlns="http://e-conomic.com">
|
5
|
+
<CashBookEntry_CreateFinanceVoucherResult>
|
6
|
+
<Id1>15</Id1>
|
7
|
+
<Id2>16</Id2>
|
8
|
+
</CashBookEntry_CreateFinanceVoucherResult>
|
9
|
+
</CashBookEntry_CreateFinanceVoucherResponse>
|
10
|
+
</soap:Body>
|
11
|
+
</soap:Envelope>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
3
|
+
<soap:Body>
|
4
|
+
<CashBookEntry_CreateFromDataResponse xmlns="http://e-conomic.com">
|
5
|
+
<CashBookEntry_CreateFromDataResult>
|
6
|
+
<Id1>int</Id1>
|
7
|
+
<Id2>int</Id2>
|
8
|
+
</CashBookEntry_CreateFromDataResult>
|
9
|
+
</CashBookEntry_CreateFromDataResponse>
|
10
|
+
</soap:Body>
|
11
|
+
</soap:Envelope>
|