rconomic 0.5.0 → 0.5.1
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.
- checksums.yaml +6 -14
- data/.travis.yml +0 -1
- data/Gemfile +0 -1
- data/lib/economic/account.rb +3 -5
- data/lib/economic/cash_book.rb +1 -1
- data/lib/economic/cash_book_entry.rb +92 -94
- data/lib/economic/creditor.rb +1 -1
- data/lib/economic/creditor_contact.rb +15 -17
- data/lib/economic/creditor_entry.rb +0 -1
- data/lib/economic/current_invoice.rb +32 -35
- data/lib/economic/current_invoice_line.rb +14 -2
- data/lib/economic/debtor.rb +60 -37
- data/lib/economic/debtor_contact.rb +26 -20
- data/lib/economic/endpoint.rb +72 -0
- data/lib/economic/entity/handle.rb +35 -21
- data/lib/economic/entity/mapper.rb +41 -0
- data/lib/economic/entity.rb +58 -34
- data/lib/economic/invoice.rb +15 -2
- data/lib/economic/proxies/account_proxy.rb +2 -3
- data/lib/economic/proxies/actions/find_by_ci_number.rb +4 -2
- data/lib/economic/proxies/actions/find_by_date_interval.rb +0 -1
- data/lib/economic/proxies/actions/find_by_name.rb +5 -1
- data/lib/economic/proxies/cash_book_entry_proxy.rb +1 -1
- data/lib/economic/proxies/entity_proxy.rb +15 -8
- data/lib/economic/session.rb +27 -31
- data/lib/rconomic/version.rb +1 -1
- data/rconomic.gemspec +1 -5
- data/spec/economic/cash_book_entry_spec.rb +27 -5
- data/spec/economic/cash_book_spec.rb +6 -6
- data/spec/economic/creditor_contact_spec.rb +24 -15
- data/spec/economic/creditor_spec.rb +9 -9
- data/spec/economic/current_invoice_line_spec.rb +7 -7
- data/spec/economic/current_invoice_spec.rb +82 -33
- data/spec/economic/debtor_contact_spec.rb +25 -15
- data/spec/economic/debtor_entry_spec.rb +3 -3
- data/spec/economic/debtor_spec.rb +49 -15
- data/spec/economic/endpoint_spec.rb +71 -0
- data/spec/economic/entity/handle_spec.rb +42 -49
- data/spec/economic/entity/mapper_spec.rb +54 -0
- data/spec/economic/entity_spec.rb +78 -72
- data/spec/economic/entry_spec.rb +3 -3
- data/spec/economic/invoice_spec.rb +37 -18
- data/spec/economic/proxies/actions/find_by_name_spec.rb +15 -12
- data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +26 -24
- data/spec/economic/proxies/cash_book_proxy_spec.rb +23 -21
- data/spec/economic/proxies/creditor_contact_proxy_spec.rb +12 -16
- data/spec/economic/proxies/creditor_entry_proxy_spec.rb +18 -14
- data/spec/economic/proxies/creditor_proxy_spec.rb +23 -26
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +17 -20
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +38 -41
- data/spec/economic/proxies/debtor_contact_proxy_spec.rb +12 -15
- data/spec/economic/proxies/debtor_entry_proxy_spec.rb +18 -14
- data/spec/economic/proxies/debtor_proxy_spec.rb +31 -34
- data/spec/economic/proxies/entry_proxy_spec.rb +26 -22
- data/spec/economic/proxies/invoice_proxy_spec.rb +18 -21
- data/spec/economic/session_spec.rb +57 -44
- data/spec/fixtures/{spec_entity_create_from_data → account_create_from_data}/success.xml +5 -5
- data/spec/fixtures/{spec_entity_delete → account_delete}/success.xml +1 -1
- data/spec/fixtures/{spec_entity_get_data → account_get_data}/success.xml +5 -5
- data/spec/fixtures/{spec_entity_update_from_data → account_update_from_data}/success.xml +5 -5
- data/spec/fixtures/cash_book_entry_create_creditor_invoice/success.xml +2 -2
- data/spec/fixtures/cash_book_entry_create_creditor_payment/success.xml +2 -2
- data/spec/fixtures/creditor_contact_create_from_data/success.xml +10 -0
- data/spec/fixtures/debtor_contact_create_from_data/success.xml +10 -0
- data/spec/fixtures/debtor_create_from_data/success.xml +57 -0
- data/spec/spec_helper.rb +10 -104
- data/spec/support/api_requests.rb +20 -0
- data/spec/support/factories.rb +65 -0
- data/spec/support/fixtures.rb +9 -0
- metadata +27 -31
@@ -1,223 +1,229 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
has_properties :id, :foo, :baz
|
3
|
+
class Account < Economic::Entity
|
4
|
+
has_properties :id, :foo, :baz, :bar_handle
|
5
5
|
|
6
|
-
def build_soap_data; {}; end
|
6
|
+
def build_soap_data; {:foo => "bar"}; end
|
7
7
|
def existing_method; end
|
8
8
|
|
9
|
-
def proxy; Economic::
|
9
|
+
def proxy; Economic::AccountProxy.new(session); end
|
10
10
|
end
|
11
11
|
|
12
|
-
class Economic::
|
12
|
+
class Economic::AccountProxy < Economic::EntityProxy; end
|
13
13
|
|
14
14
|
describe Economic::Entity do
|
15
15
|
let(:session) { make_session }
|
16
16
|
|
17
17
|
describe "class methods" do
|
18
|
-
subject {
|
18
|
+
subject { Account }
|
19
19
|
|
20
20
|
describe "new" do
|
21
21
|
subject { Economic::Entity.new }
|
22
22
|
|
23
23
|
it "creates a new instance" do
|
24
|
-
subject.
|
24
|
+
expect(subject).to be_instance_of(Economic::Entity)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "sets persisted to false" do
|
28
|
-
subject.
|
28
|
+
expect(subject).to_not be_persisted
|
29
29
|
end
|
30
30
|
|
31
31
|
it "sets partial to true" do
|
32
|
-
subject.
|
32
|
+
expect(subject).to be_partial
|
33
33
|
end
|
34
34
|
|
35
35
|
it "initializes the entity with values from the given hash" do
|
36
|
-
entity =
|
37
|
-
entity.foo.
|
38
|
-
entity.baz.
|
36
|
+
entity = Account.new(:foo => 'bar', :baz => 'qux')
|
37
|
+
expect(entity.foo).to eq('bar')
|
38
|
+
expect(entity.baz).to eq('qux')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
describe "properties_not_triggering_full_load" do
|
43
43
|
it "returns names of special id'ish properties" do
|
44
|
-
subject.properties_not_triggering_full_load.
|
44
|
+
expect(subject.properties_not_triggering_full_load).to eq([:id, :number, :handle])
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "has_properties" do
|
49
49
|
it "creates getter for all properties" do
|
50
|
-
subject.
|
51
|
-
subject.
|
50
|
+
expect(subject).to receive(:define_method).with('name')
|
51
|
+
expect(subject).to receive(:define_method).with('age')
|
52
52
|
subject.has_properties :name, :age
|
53
53
|
end
|
54
54
|
|
55
55
|
it "creates setter for all properties" do
|
56
|
-
subject.
|
57
|
-
subject.
|
56
|
+
expect(subject).to receive(:attr_writer).with(:name)
|
57
|
+
expect(subject).to receive(:attr_writer).with(:age)
|
58
58
|
subject.has_properties :name, :age
|
59
59
|
end
|
60
60
|
|
61
|
+
describe "setter for handles" do
|
62
|
+
subject { Account.new }
|
63
|
+
|
64
|
+
it "accepts a Handle" do
|
65
|
+
subject.bar_handle = Economic::Entity::Handle.new(:id => 2)
|
66
|
+
expect(subject.bar_handle.id).to eq(2)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "converts Hash input to Handle" do
|
70
|
+
subject.bar_handle = {:id => 1}
|
71
|
+
expect(subject.bar_handle).to eq(Economic::Entity::Handle.new(:id => 1))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
61
75
|
it "does not create setter or getter for id'ish properties" do
|
62
|
-
subject.
|
63
|
-
subject.
|
64
|
-
subject.
|
76
|
+
expect(subject).to receive(:define_method).with('id').never
|
77
|
+
expect(subject).to receive(:define_method).with('number').never
|
78
|
+
expect(subject).to receive(:define_method).with('handle').never
|
65
79
|
subject.has_properties :id, :number, :handle
|
66
80
|
end
|
67
81
|
|
68
82
|
it "does clobber existing methods" do
|
69
|
-
subject.
|
83
|
+
expect(subject).to receive(:define_method).with('existing_method')
|
70
84
|
subject.has_properties :existing_method
|
71
85
|
end
|
72
86
|
|
73
87
|
describe "properties created with has_properties" do
|
74
88
|
end
|
75
89
|
end
|
76
|
-
|
77
|
-
describe "soap_action" do
|
78
|
-
it "returns the name for the given soap action on this class" do
|
79
|
-
subject.soap_action_name(:get_data).should == :spec_entity_get_data
|
80
|
-
|
81
|
-
class Car < Economic::Entity; end
|
82
|
-
Car.soap_action_name(:start_engine).should == :car_start_engine
|
83
|
-
Car.soap_action_name('StartEngine').should == :car_start_engine
|
84
|
-
end
|
85
|
-
end
|
86
90
|
end
|
87
91
|
|
88
92
|
describe "get_data" do
|
89
|
-
subject { (e =
|
93
|
+
subject { (e = Account.new).tap { |e| e.session = session } }
|
90
94
|
|
91
95
|
before :each do
|
92
|
-
savon.stubs(:spec_entity_get_data).returns(:success)
|
93
96
|
end
|
94
97
|
|
95
98
|
it "fetches data from API" do
|
96
99
|
subject.instance_variable_set('@number', 42)
|
97
|
-
|
100
|
+
mock_request(:account_get_data, {'entityHandle' => {'Number' => 42}}, :success)
|
98
101
|
subject.get_data
|
99
102
|
end
|
100
103
|
|
101
104
|
it "updates the entity with the response" do
|
102
|
-
|
105
|
+
stub_request(:account_get_data, nil, :success)
|
106
|
+
expect(subject).to receive(:update_properties).with({:foo => 'bar', :baz => 'qux'})
|
103
107
|
subject.get_data
|
104
108
|
end
|
105
109
|
|
106
110
|
it "sets partial to false" do
|
111
|
+
stub_request(:account_get_data, nil, :success)
|
107
112
|
subject.get_data
|
108
|
-
subject.
|
113
|
+
expect(subject).to_not be_partial
|
109
114
|
end
|
110
115
|
|
111
116
|
it "sets persisted to true" do
|
117
|
+
stub_request(:account_get_data, nil, :success)
|
112
118
|
subject.get_data
|
113
|
-
subject.
|
119
|
+
expect(subject).to be_persisted
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
117
123
|
describe "save" do
|
118
|
-
subject { (e =
|
124
|
+
subject { (e = Account.new).tap { |e| e.session = session } }
|
119
125
|
|
120
126
|
context "entity has not been persisted" do
|
121
127
|
before :each do
|
122
|
-
subject.
|
128
|
+
allow(subject).to receive(:persisted?).and_return(false)
|
123
129
|
end
|
124
130
|
|
125
131
|
it "creates the entity" do
|
126
|
-
subject.
|
132
|
+
expect(subject).to receive(:create)
|
127
133
|
subject.save
|
128
134
|
end
|
129
135
|
end
|
130
136
|
|
131
137
|
context "entity has already been persisted" do
|
132
138
|
before :each do
|
133
|
-
subject.
|
139
|
+
allow(subject).to receive(:persisted?).and_return(true)
|
134
140
|
end
|
135
141
|
|
136
142
|
it "updates the entity" do
|
137
|
-
subject.
|
143
|
+
expect(subject).to receive(:update)
|
138
144
|
subject.save
|
139
145
|
end
|
140
146
|
end
|
141
147
|
end
|
142
148
|
|
143
149
|
describe "create" do
|
144
|
-
subject { (e =
|
150
|
+
subject { (e = Account.new).tap { |e| e.persisted = false; e.session = session } }
|
145
151
|
|
146
152
|
it "sends data to the API" do
|
147
|
-
|
153
|
+
mock_request(:account_create_from_data, {"data" => {:foo => "bar"}}, :success)
|
148
154
|
subject.save
|
149
155
|
end
|
150
156
|
|
151
157
|
it "updates handle with the number returned from API" do
|
152
|
-
|
158
|
+
stub_request(:account_create_from_data, :any, :success)
|
153
159
|
subject.save
|
154
|
-
subject.number.
|
160
|
+
expect(subject.number).to eq('42')
|
155
161
|
end
|
156
162
|
end
|
157
163
|
|
158
164
|
describe ".proxy" do
|
159
|
-
subject { (e =
|
165
|
+
subject { (e = Account.new).tap { |e| e.session = session } }
|
160
166
|
|
161
|
-
it "should return
|
162
|
-
subject.proxy.
|
167
|
+
it "should return AccountProxy" do
|
168
|
+
expect(subject.proxy).to be_instance_of(Economic::AccountProxy)
|
163
169
|
end
|
164
170
|
end
|
165
171
|
|
166
172
|
describe "update" do
|
167
|
-
subject { (e =
|
173
|
+
subject { (e = Account.new).tap { |e| e.persisted = true; e.session = session } }
|
168
174
|
|
169
175
|
it "sends data to the API" do
|
170
|
-
|
176
|
+
mock_request(:account_update_from_data, {"data" => {:foo => "bar"}}, :success)
|
171
177
|
subject.save
|
172
178
|
end
|
173
179
|
end
|
174
180
|
|
175
181
|
describe "destroy" do
|
176
|
-
subject { (e =
|
182
|
+
subject { (e = Account.new).tap { |e| e.id = 42; e.persisted = true; e.partial = false; e.session = session } }
|
177
183
|
|
178
184
|
it "sends data to the API" do
|
179
|
-
|
185
|
+
mock_request(:account_delete, :any, :success)
|
180
186
|
subject.destroy
|
181
187
|
end
|
182
188
|
|
183
189
|
it "should request with the correct model and id" do
|
184
|
-
|
190
|
+
mock_request(:account_delete, {'accountHandle' => {'Id' => 42}}, :success)
|
185
191
|
subject.destroy
|
186
192
|
end
|
187
193
|
|
188
194
|
it "should mark the entity as not persisted and partial" do
|
189
|
-
|
195
|
+
mock_request(:account_delete, :any, :success)
|
190
196
|
subject.destroy
|
191
|
-
subject.
|
192
|
-
subject.
|
197
|
+
expect(subject).to_not be_persisted
|
198
|
+
expect(subject).to be_partial
|
193
199
|
end
|
194
200
|
|
195
201
|
it "should return the response" do
|
196
|
-
session.
|
197
|
-
subject.destroy.
|
202
|
+
expect(session).to receive(:request).and_return({ :response => true })
|
203
|
+
expect(subject.destroy).to eq({ :response => true })
|
198
204
|
end
|
199
205
|
end
|
200
206
|
|
201
207
|
describe "update_properties" do
|
202
|
-
subject {
|
208
|
+
subject { Account.new }
|
203
209
|
|
204
210
|
it "sets the properties to the given values" do
|
205
211
|
subject.class.has_properties :foo, :baz
|
206
|
-
subject.
|
207
|
-
subject.
|
212
|
+
expect(subject).to receive(:foo=).with('bar')
|
213
|
+
expect(subject).to receive(:baz=).with('qux')
|
208
214
|
subject.update_properties(:foo => 'bar', 'baz' => 'qux')
|
209
215
|
end
|
210
216
|
|
211
217
|
it "only sets known properties" do
|
212
218
|
subject.class.has_properties :foo, :bar
|
213
|
-
subject.
|
219
|
+
expect(subject).to receive(:foo=).with('bar')
|
214
220
|
subject.update_properties(:foo => 'bar', 'baz' => 'qux')
|
215
221
|
end
|
216
222
|
end
|
217
223
|
|
218
224
|
describe "equality" do
|
219
|
-
subject {
|
220
|
-
let(:other) {
|
225
|
+
subject { Account.new }
|
226
|
+
let(:other) { Account.new }
|
221
227
|
|
222
228
|
context "when other is nil do" do
|
223
229
|
it { should_not == nil }
|
@@ -228,21 +234,21 @@ describe Economic::Entity do
|
|
228
234
|
subject.handle = Economic::Entity::Handle.new({})
|
229
235
|
other.handle = Economic::Entity::Handle.new({})
|
230
236
|
|
231
|
-
subject.
|
237
|
+
expect(subject).not_to eq(other)
|
232
238
|
end
|
233
239
|
end
|
234
240
|
|
235
241
|
context "when self handle isn't present" do
|
236
242
|
it "returns false" do
|
237
243
|
subject.handle = nil
|
238
|
-
subject.
|
244
|
+
expect(subject).not_to eq(other)
|
239
245
|
end
|
240
246
|
end
|
241
247
|
|
242
248
|
context "when other handle isn't present" do
|
243
249
|
it "returns false" do
|
244
250
|
other.handle = nil
|
245
|
-
subject.
|
251
|
+
expect(subject).not_to eq(other)
|
246
252
|
end
|
247
253
|
end
|
248
254
|
|
@@ -253,22 +259,22 @@ describe Economic::Entity do
|
|
253
259
|
context "when other is another class" do
|
254
260
|
it "should return false" do
|
255
261
|
other = Economic::CashBook.new(:handle => handle)
|
256
|
-
subject.
|
262
|
+
expect(subject).not_to eq(other)
|
257
263
|
end
|
258
264
|
end
|
259
265
|
|
260
266
|
context "when other is same class" do
|
261
267
|
it "should return true" do
|
262
268
|
other = Economic::Debtor.new(:handle => handle)
|
263
|
-
subject.
|
269
|
+
expect(subject).to eq(other)
|
264
270
|
end
|
265
271
|
end
|
266
272
|
|
267
273
|
context "when other is child class" do
|
268
274
|
it "should return true" do
|
269
275
|
one = Economic::Entity.new(:handle => handle)
|
270
|
-
other =
|
271
|
-
one.
|
276
|
+
other = Account.new(:handle => handle)
|
277
|
+
expect(one).to eq(other)
|
272
278
|
end
|
273
279
|
end
|
274
280
|
end
|
data/spec/economic/entry_spec.rb
CHANGED
@@ -5,16 +5,16 @@ describe Economic::Entry do
|
|
5
5
|
subject { Economic::Entry.new(:session => session) }
|
6
6
|
|
7
7
|
it "inherits from Economic::Entity" do
|
8
|
-
Economic::Entry.ancestors.
|
8
|
+
expect(Economic::Entry.ancestors).to include(Economic::Entity)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe ".proxy" do
|
12
12
|
it "should return a EntryProxy" do
|
13
|
-
subject.proxy.
|
13
|
+
expect(subject.proxy).to be_instance_of(Economic::EntryProxy)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should return a proxy owned by session" do
|
17
|
-
subject.proxy.session.
|
17
|
+
expect(subject.proxy.session).to eq(session)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -5,64 +5,83 @@ describe Economic::Invoice do
|
|
5
5
|
subject { Economic::Invoice.new(:session => session, :number => 512) }
|
6
6
|
|
7
7
|
it "inherits from Economic::Entity" do
|
8
|
-
Economic::Invoice.ancestors.
|
8
|
+
expect(Economic::Invoice.ancestors).to include(Economic::Entity)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe '#remainder' do
|
12
12
|
it 'should get the remainder' do
|
13
|
-
|
14
|
-
subject.remainder.
|
13
|
+
mock_request('Invoice_GetRemainder', {"invoiceHandle" => { "Number" => 512 }}, :success)
|
14
|
+
expect(subject.remainder).to eq("512.32")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe ".proxy" do
|
19
19
|
it "should return a InvoiceProxy" do
|
20
|
-
subject.proxy.
|
20
|
+
expect(subject.proxy).to be_instance_of(Economic::InvoiceProxy)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should return a proxy owned by session" do
|
24
|
-
subject.proxy.session.
|
24
|
+
expect(subject.proxy.session).to eq(session)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe ".key" do
|
29
29
|
it "should == :invoice" do
|
30
|
-
Economic::Invoice.key.
|
30
|
+
expect(Economic::Invoice.key).to eq(:invoice)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe "#pdf" do
|
35
|
-
before :each do
|
36
|
-
savon.stubs('Invoice_GetPdf').returns(:success)
|
37
|
-
end
|
38
|
-
|
39
35
|
it "gets PDF data from API" do
|
40
|
-
|
36
|
+
mock_request('Invoice_GetPdf', {'invoiceHandle' => {'Number' => 512}}, :success)
|
41
37
|
subject.pdf
|
42
38
|
end
|
43
39
|
|
44
40
|
it "decodes the base64Binary encoded data" do
|
45
|
-
|
41
|
+
stub_request('Invoice_GetPdf', nil, :success)
|
42
|
+
expect(subject.pdf).to eq('This is not really PDF data')
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
49
46
|
describe "#attention" do
|
50
|
-
let(:contact) {
|
47
|
+
let(:contact) {
|
48
|
+
Economic::DebtorContact.new.tap do |c|
|
49
|
+
c.session = session
|
50
|
+
c.id = 5
|
51
|
+
end
|
52
|
+
}
|
51
53
|
|
52
54
|
it "should be set- and gettable" do
|
53
55
|
subject.attention = contact
|
54
|
-
subject.
|
55
|
-
|
56
|
+
expect(subject.attention).to eq(contact)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "updates the handle" do
|
60
|
+
handle = Economic::Entity::Handle.new(:number => 42)
|
61
|
+
contact.handle = handle
|
62
|
+
subject.attention = contact
|
63
|
+
expect(subject.attention_handle).to eq(handle)
|
56
64
|
end
|
57
65
|
end
|
58
66
|
|
59
67
|
describe "#debtor" do
|
60
|
-
let(:debtor) {
|
68
|
+
let(:debtor) {
|
69
|
+
Economic::Debtor.new.tap do |c|
|
70
|
+
c.session = session
|
71
|
+
c.number = 5
|
72
|
+
end
|
73
|
+
}
|
61
74
|
|
62
75
|
it "should be set- and gettable" do
|
63
76
|
subject.debtor = debtor
|
64
|
-
subject.
|
65
|
-
|
77
|
+
expect(subject.debtor).to eq(debtor)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "updates the handle" do
|
81
|
+
handle = Economic::Entity::Handle.new(:number => 42)
|
82
|
+
debtor.handle = handle
|
83
|
+
subject.debtor = debtor
|
84
|
+
expect(subject.debtor_handle).to eq(handle)
|
66
85
|
end
|
67
86
|
end
|
68
87
|
end
|
@@ -9,38 +9,41 @@ describe Economic::Proxies::Actions::FindByName do
|
|
9
9
|
}
|
10
10
|
|
11
11
|
describe "#call" do
|
12
|
-
before :each do
|
13
|
-
savon.stubs('CreditorContact_FindByName').returns(:multiple)
|
14
|
-
end
|
15
|
-
|
16
12
|
it "gets contact data from the API" do
|
17
|
-
|
13
|
+
mock_request('CreditorContact_FindByName', {'name' => 'Bob'}, :multiple)
|
18
14
|
subject.call
|
19
15
|
end
|
20
16
|
|
21
17
|
it "returns creditor contacts" do
|
22
|
-
|
18
|
+
stub_request('CreditorContact_FindByName', nil, :multiple)
|
19
|
+
expect(subject.call.first).to be_instance_of(Economic::CreditorContact)
|
23
20
|
end
|
24
21
|
|
25
22
|
it "returns empty when nothing is found" do
|
26
|
-
|
27
|
-
subject.call.
|
23
|
+
stub_request('CreditorContact_FindByName', nil, :none)
|
24
|
+
expect(subject.call).to be_empty
|
28
25
|
end
|
29
26
|
|
30
27
|
context "when calling proxy is owned by session" do
|
31
28
|
it "returns all creditor contacts" do
|
32
|
-
|
29
|
+
stub_request('CreditorContact_FindByName', nil, :multiple)
|
30
|
+
expect(subject.call.size).to eq(2)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
34
|
context "when calling proxy is owned by a creditor" do
|
37
35
|
it "returns only contacts for creditor" do
|
38
|
-
|
39
|
-
|
36
|
+
# Note the order of these stubs actually matters. They need to match
|
37
|
+
# the order they are called in in the implementation
|
38
|
+
stub_request('CreditorContact_FindByName', nil, :multiple)
|
39
|
+
stub_request("CreditorContact_GetData", nil, :success)
|
40
|
+
stub_request("Creditor_GetData", nil, :success)
|
41
|
+
stub_request("CreditorContact_GetData", nil, :success)
|
42
|
+
stub_request("Creditor_GetData", nil, :success)
|
40
43
|
creditor = session.creditors.build
|
41
44
|
proxy = Economic::CreditorContactProxy.new(creditor)
|
42
45
|
action = Economic::Proxies::Actions::FindByName.new(proxy, "Bob")
|
43
|
-
action.call.each { |contact| contact.creditor.
|
46
|
+
action.call.each { |contact| expect(contact.creditor).to eq(creditor) }
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
@@ -8,79 +8,81 @@ describe Economic::CashBookEntryProxy do
|
|
8
8
|
|
9
9
|
describe ".new" do
|
10
10
|
it "stores owner" do
|
11
|
-
subject.owner.
|
11
|
+
subject.owner.number = 2
|
12
|
+
expect(subject.owner).to eq(cash_book)
|
12
13
|
end
|
13
14
|
|
14
15
|
it "stores session" do
|
15
|
-
subject.session.
|
16
|
+
expect(subject.session).to equal(session)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
describe ".build" do
|
20
21
|
it "instantiates a new CashBookEntry" do
|
21
|
-
subject.build.
|
22
|
+
expect(subject.build).to be_instance_of(Economic::CashBookEntry)
|
22
23
|
end
|
23
24
|
|
24
25
|
it "assigns the session to the CashBookEntry" do
|
25
|
-
subject.build.session.
|
26
|
+
expect(subject.build.session).to equal(session)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
describe "#create_finance_voucher" do
|
30
31
|
it 'should create a finance voucher and return the created cash book entry' do
|
31
|
-
|
32
|
-
|
32
|
+
stub_request('CashBookEntry_CreateFinanceVoucher', nil, :success)
|
33
|
+
stub_request('CashBookEntry_GetData', {"entityHandle" => {"Id1" => 15, "Id2" => 16}}, :success)
|
33
34
|
cash_book_entry = subject.create_finance_voucher(:account_handle => { :number => 2 }, :contra_account_handle => { :number => 3 })
|
34
|
-
cash_book_entry.
|
35
|
+
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
39
|
describe "#create_debtor_payment" do
|
39
40
|
it 'should create a debtor payment and then return the created cash book entry' do
|
40
|
-
|
41
|
-
|
41
|
+
stub_request('CashBookEntry_CreateDebtorPayment', nil, :success)
|
42
|
+
stub_request('CashBookEntry_GetData', {"entityHandle" => {"Id1" => 13, "Id2" => 14}}, :success)
|
42
43
|
cash_book_entry = subject.create_debtor_payment(:debtor_handle => { :number => 2 }, :contra_account_handle => { :number => 3 })
|
43
|
-
cash_book_entry.
|
44
|
+
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
48
|
describe "#create_creditor_invoice" do
|
48
49
|
it 'should create a creditor invoice and then return the created cash book entry' do
|
49
|
-
|
50
|
-
|
50
|
+
stub_request('CashBookEntry_CreateCreditorInvoice', nil, :success)
|
51
|
+
stub_request('CashBookEntry_GetData', {"entityHandle" => {"Id1" => 13, "Id2" => 14}}, :success)
|
51
52
|
cash_book_entry = subject.create_creditor_invoice(:creditor_handle => { :number => 2 }, :contra_account_handle => { :number => 3 })
|
52
|
-
cash_book_entry.
|
53
|
+
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
53
54
|
end
|
54
55
|
|
55
56
|
it 'should not send handles that were not given' do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
cash_book_entry.
|
57
|
+
stub_request('CashBookEntry_CreateCreditorInvoice', {"cashBookHandle" => { 'Number' => 42 }}, :success)
|
58
|
+
stub_request('CashBookEntry_GetData', {"entityHandle" => {"Id1" => 13, "Id2" => 14}}, :success)
|
59
|
+
cash_book.number = 42
|
60
|
+
cash_book_entry = subject.create_creditor_invoice({:number => 13})
|
61
|
+
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
65
|
describe "#create_creditor_payment" do
|
64
66
|
it 'should create a creditor payment and then return the created cash book entry' do
|
65
|
-
|
66
|
-
|
67
|
+
stub_request('CashBookEntry_CreateCreditorPayment', nil, :success)
|
68
|
+
stub_request('CashBookEntry_GetData', {"entityHandle" => {"Id1" => 13, "Id2" => 14}}, :success)
|
67
69
|
cash_book_entry = subject.create_creditor_payment(:creditor_handle => { :number => 2 }, :contra_account_handle => { :number => 3 })
|
68
|
-
cash_book_entry.
|
70
|
+
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
74
|
describe "#set_due_date" do
|
73
75
|
it 'should set due date' do
|
74
|
-
|
76
|
+
mock_request('CashBookEntry_SetDueDate', {"cashBookEntryHandle" => { "Id1" => subject.owner.id, "Id2" => 234 }, :value => Date.new(2012, 12, 21)}, :success)
|
75
77
|
subject.set_due_date(234, Date.new(2012, 12, 21))
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
81
|
describe "#all" do
|
80
82
|
it 'should get the cash book entries' do
|
81
|
-
|
82
|
-
subject.
|
83
|
-
subject.
|
83
|
+
stub_request('CashBook_GetEntries', nil, :success)
|
84
|
+
expect(subject).to receive(:find).with({:id1 => '1', :id2 => '2'})
|
85
|
+
expect(subject).to receive(:find).with({:id1 => '11', :id2 => '12'})
|
84
86
|
subject.all
|
85
87
|
end
|
86
88
|
end
|