activenetsuite 0.1.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.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.rspec +1 -0
- data/CHANGELOG +0 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +51 -0
- data/History.txt +3 -0
- data/Manifest.txt +60 -0
- data/README.rdoc +14 -0
- data/Rakefile +14 -0
- data/activenetsuite.gemspec +30 -0
- data/lib/activenetsuite.rb +30 -0
- data/lib/activenetsuite/accounting/account.rb +11 -0
- data/lib/activenetsuite/accounting/non_inventory_sale_item.rb +10 -0
- data/lib/activenetsuite/core/custom_field_list.rb +7 -0
- data/lib/activenetsuite/core/custom_field_ref.rb +8 -0
- data/lib/activenetsuite/core/deleted_record.rb +10 -0
- data/lib/activenetsuite/core/get_deleted_result.rb +13 -0
- data/lib/activenetsuite/core/record.rb +254 -0
- data/lib/activenetsuite/core/record_ref.rb +35 -0
- data/lib/activenetsuite/core/search_record.rb +97 -0
- data/lib/activenetsuite/core/search_result.rb +12 -0
- data/lib/activenetsuite/core/status.rb +50 -0
- data/lib/activenetsuite/helpers/client.rb +135 -0
- data/lib/activenetsuite/helpers/error.rb +7 -0
- data/lib/activenetsuite/helpers/method_inflector.rb +78 -0
- data/lib/activenetsuite/helpers/response_methods.rb +21 -0
- data/lib/activenetsuite/helpers/search_response_methods.rb +62 -0
- data/lib/activenetsuite/messages/add_response.rb +8 -0
- data/lib/activenetsuite/messages/delete_list_response.rb +19 -0
- data/lib/activenetsuite/messages/delete_response.rb +8 -0
- data/lib/activenetsuite/messages/get_deleted_response.rb +23 -0
- data/lib/activenetsuite/messages/get_deleted_result.rb +21 -0
- data/lib/activenetsuite/messages/get_response.rb +13 -0
- data/lib/activenetsuite/messages/read_response.rb +7 -0
- data/lib/activenetsuite/messages/search_more_with_id_response.rb +8 -0
- data/lib/activenetsuite/messages/search_response.rb +8 -0
- data/lib/activenetsuite/messages/update_response.rb +8 -0
- data/lib/activenetsuite/messages/write_response.rb +16 -0
- data/lib/activenetsuite/relationships/partner.rb +18 -0
- data/lib/activenetsuite/relationships/vendor.rb +14 -0
- data/lib/activenetsuite/sales/cash_refund.rb +12 -0
- data/lib/activenetsuite/sales/cash_sale.rb +12 -0
- data/lib/activenetsuite/soap/NetSuiteServiceClient.rb +978 -0
- data/lib/activenetsuite/soap/default.rb +68163 -0
- data/lib/activenetsuite/soap/defaultDriver.rb +419 -0
- data/lib/activenetsuite/soap/defaultMappingRegistry.rb +62549 -0
- data/lib/activenetsuite/version.rb +3 -0
- data/spec/lib/activenetsuite/accounting/non_inventory_sale_item_spec.rb +9 -0
- data/spec/lib/activenetsuite/core/record_ref_spec.rb +56 -0
- data/spec/lib/activenetsuite/core/record_spec.rb +298 -0
- data/spec/lib/activenetsuite/core/search_record_spec.rb +50 -0
- data/spec/lib/activenetsuite/core/search_result_spec.rb +26 -0
- data/spec/lib/activenetsuite/helpers/client_spec.rb +115 -0
- data/spec/lib/activenetsuite/helpers/method_inflector_spec.rb +85 -0
- data/spec/lib/activenetsuite/helpers/search_response_methods_spec.rb +50 -0
- data/spec/lib/activenetsuite/messages/search_response_spec.rb +5 -0
- data/spec/lib/activenetsuite/relationships/partner_spec.rb +22 -0
- data/spec/lib/activenetsuite/relationships/vendor_spec.rb +14 -0
- data/spec/lib/activenetsuite/sales/cash_refund_spec.rb +10 -0
- data/spec/lib/activenetsuite/sales/cash_sale_spec.rb +10 -0
- data/spec/spec_helper.rb +17 -0
- metadata +138 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RecordRef do
|
4
|
+
let(:ref) do
|
5
|
+
ref = described_class.new
|
6
|
+
ref.type = 'record'
|
7
|
+
ref.internal_id = 12
|
8
|
+
ref.external_id = 45
|
9
|
+
ref
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#==' do
|
13
|
+
subject { this == that }
|
14
|
+
|
15
|
+
let :this do
|
16
|
+
this = RecordRef.new
|
17
|
+
this.internal_id = 12
|
18
|
+
this.external_id = 34
|
19
|
+
this.type = 'record'
|
20
|
+
this
|
21
|
+
end
|
22
|
+
|
23
|
+
let :that do
|
24
|
+
that = RecordRef.new
|
25
|
+
that.internal_id = 12
|
26
|
+
that.external_id = 34
|
27
|
+
that.type = 'record'
|
28
|
+
that
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when all attributes match' do
|
32
|
+
it { should be_true }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when all attributes match' do
|
36
|
+
before { that.internal_id = 56 }
|
37
|
+
it { should be_false }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#record' do
|
42
|
+
subject { ref.record }
|
43
|
+
|
44
|
+
it { should be_a Record }
|
45
|
+
its(:internal_id) { should eq 12 }
|
46
|
+
its(:external_id) { should eq 45 }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#delete' do
|
50
|
+
subject { ref.delete }
|
51
|
+
it do
|
52
|
+
Record.should_receive(:delete).with([ref])
|
53
|
+
subject
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,298 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class ActiveNetsuite::Record
|
4
|
+
AttrExternalId = XSD::QName.new(nil, "externalId")
|
5
|
+
AttrInternalId = XSD::QName.new(nil, "internalId")
|
6
|
+
|
7
|
+
def __xmlattr
|
8
|
+
@__xmlattr ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def xmlattr_internalId
|
12
|
+
__xmlattr[AttrInternalId]
|
13
|
+
end
|
14
|
+
|
15
|
+
def xmlattr_internalId=(value)
|
16
|
+
__xmlattr[AttrInternalId] = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def xmlattr_externalId
|
20
|
+
__xmlattr[AttrExternalId]
|
21
|
+
end
|
22
|
+
|
23
|
+
def xmlattr_externalId=(value)
|
24
|
+
__xmlattr[AttrExternalId] = value
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_accessor :foo
|
28
|
+
attr_accessor :bar
|
29
|
+
end
|
30
|
+
|
31
|
+
class ActiveNetsuite::RecordSearchBasic; end
|
32
|
+
|
33
|
+
describe Record do
|
34
|
+
let(:model) { Record.new args }
|
35
|
+
let(:args) { nil }
|
36
|
+
let(:client) { double }
|
37
|
+
before { Record.client = client }
|
38
|
+
|
39
|
+
describe '#add' do
|
40
|
+
subject { model.add }
|
41
|
+
|
42
|
+
before do
|
43
|
+
model.client.stub(:add) { result }
|
44
|
+
end
|
45
|
+
let(:result) { double success?: success, internal_id: :internal_id }
|
46
|
+
let(:success) { true }
|
47
|
+
|
48
|
+
it { should eq result }
|
49
|
+
|
50
|
+
context 'when success' do
|
51
|
+
let(:success) { true }
|
52
|
+
it { expect { subject }.to change { model.internal_id }.to(:internal_id) }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when not success' do
|
56
|
+
let(:success) { false }
|
57
|
+
it { expect { subject }.to_not \
|
58
|
+
change { model.internal_id }.to(:internal_id) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#update' do
|
63
|
+
subject { model.update }
|
64
|
+
|
65
|
+
before { model.client.stub(:update).with(model) { result } }
|
66
|
+
let(:result) { double }
|
67
|
+
|
68
|
+
it { should be result }
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#delete' do
|
72
|
+
subject { model.delete }
|
73
|
+
|
74
|
+
before do
|
75
|
+
client.stub(:delete) { result }
|
76
|
+
model.internal_id = 100
|
77
|
+
end
|
78
|
+
let(:result) { double success?: success }
|
79
|
+
let(:success) { true }
|
80
|
+
it { should be result }
|
81
|
+
|
82
|
+
context 'when it is success' do
|
83
|
+
let(:success) { true }
|
84
|
+
it { expect { subject }.to change { model.internal_id }.to(nil) }
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when it is failure' do
|
88
|
+
let(:success) { false }
|
89
|
+
it { expect { subject }.to_not change { model.internal_id }.from(100) }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#client' do
|
94
|
+
subject { model.client }
|
95
|
+
before { model.class.client = client }
|
96
|
+
let(:client) { double }
|
97
|
+
|
98
|
+
it { should be client }
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#load' do
|
102
|
+
subject { model.load }
|
103
|
+
before { model.instance_variable_set(:@loaded, loaded) }
|
104
|
+
let(:loaded) { double }
|
105
|
+
|
106
|
+
it { should be model }
|
107
|
+
|
108
|
+
context 'when already loaded' do
|
109
|
+
let(:loaded) { true }
|
110
|
+
|
111
|
+
it { should be model }
|
112
|
+
it do
|
113
|
+
client.should_not_receive(:get)
|
114
|
+
subject
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when internal_id is set' do
|
119
|
+
let(:loaded) { false }
|
120
|
+
|
121
|
+
before do
|
122
|
+
model.internal_id = 123
|
123
|
+
client.stub(:get) { double record: record }
|
124
|
+
end
|
125
|
+
|
126
|
+
let(:record) do
|
127
|
+
double getters: %i(foo bar),
|
128
|
+
foo: :foo,
|
129
|
+
bar: :bar
|
130
|
+
end
|
131
|
+
|
132
|
+
it { expect { subject }.to change { model.loaded? }.to(true) }
|
133
|
+
it { expect { subject }.to change { model.foo }.to(:foo) }
|
134
|
+
it { expect { subject }.to change { model.bar }.to(:bar) }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe '#loaded?' do
|
139
|
+
subject { model.loaded? }
|
140
|
+
before { model.instance_variable_set(:@loaded, true) }
|
141
|
+
it { should be_true }
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#ref' do
|
145
|
+
subject { model.ref }
|
146
|
+
|
147
|
+
it { should be_a RecordRef }
|
148
|
+
its(:type) { should eq "record" }
|
149
|
+
its(:internal_id) { should eq model.internal_id }
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#setters' do
|
153
|
+
subject { model.setters }
|
154
|
+
it do
|
155
|
+
should include *%i(foo= bar= nullFieldList=
|
156
|
+
xmlattr_externalId= xmlattr_internalId=)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#getters' do
|
161
|
+
subject { model.getters }
|
162
|
+
it do
|
163
|
+
should include *%i(foo bar xmlattr_externalId xmlattr_internalId)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '.delete' do
|
168
|
+
subject { described_class.delete(objects) }
|
169
|
+
|
170
|
+
let(:ids) { [10, 20] }
|
171
|
+
|
172
|
+
let(:recs) do
|
173
|
+
ids.map do |id|
|
174
|
+
rec = Record.new
|
175
|
+
rec.internal_id = id
|
176
|
+
rec
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
let(:refs) do
|
181
|
+
ids.map do |id|
|
182
|
+
ref = RecordRef.new
|
183
|
+
ref.internal_id = id
|
184
|
+
ref.type = 'record'
|
185
|
+
ref
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when internal ids given' do
|
190
|
+
let(:objects) { ids }
|
191
|
+
|
192
|
+
it do
|
193
|
+
described_class.client.should_receive(:delete_list) do |args|
|
194
|
+
args == refs
|
195
|
+
end
|
196
|
+
subject
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'when Records given' do
|
201
|
+
let(:objects) { recs }
|
202
|
+
|
203
|
+
it do
|
204
|
+
described_class.client.should_receive(:delete_list) do |args|
|
205
|
+
args == refs
|
206
|
+
end
|
207
|
+
subject
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'when Refs given' do
|
212
|
+
let(:objects) { refs }
|
213
|
+
|
214
|
+
it do
|
215
|
+
described_class.client.should_receive(:delete_list) do |args|
|
216
|
+
args == refs
|
217
|
+
end
|
218
|
+
subject
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe '.client' do
|
224
|
+
subject { Record.client }
|
225
|
+
before { Record.client = client }
|
226
|
+
it { should be client }
|
227
|
+
end
|
228
|
+
|
229
|
+
describe '.client=' do
|
230
|
+
subject { Record.client = client }
|
231
|
+
before { Record.client = nil }
|
232
|
+
it { expect { subject }.to change { Record.client }.to(client) }
|
233
|
+
end
|
234
|
+
|
235
|
+
describe '.find' do
|
236
|
+
subject { Record.find 123 }
|
237
|
+
before { client.stub(:get).with(ref) { response } }
|
238
|
+
let :ref do
|
239
|
+
ref = RecordRef.new
|
240
|
+
ref.type = 'record'
|
241
|
+
ref.internal_id = 123
|
242
|
+
ref
|
243
|
+
end
|
244
|
+
let(:response) { double record: record }
|
245
|
+
|
246
|
+
context 'when record found' do
|
247
|
+
let(:record) { double }
|
248
|
+
it { should eq record }
|
249
|
+
end
|
250
|
+
|
251
|
+
context 'when record not found' do
|
252
|
+
let(:record) { nil }
|
253
|
+
it { expect { subject }.to raise_error NotFoundError,
|
254
|
+
'type: record, internal_id: 123, external_id: ' }
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'when record found' do
|
258
|
+
let(:record) { double }
|
259
|
+
it { should be record }
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe '.find_by_internal_id' do
|
264
|
+
subject { Record.find_by_internal_id 123 }
|
265
|
+
before { client.stub(:get).with(ref) { response } }
|
266
|
+
let :ref do
|
267
|
+
ref = RecordRef.new
|
268
|
+
ref.type = 'record'
|
269
|
+
ref.internal_id = 123
|
270
|
+
ref
|
271
|
+
end
|
272
|
+
let(:response) { double record: :record }
|
273
|
+
it { should eq :record }
|
274
|
+
end
|
275
|
+
|
276
|
+
describe '.find_by_external_id' do
|
277
|
+
subject { Record.find_by_external_id 'boo' }
|
278
|
+
|
279
|
+
before { client.stub(:get).with(ref) { response } }
|
280
|
+
|
281
|
+
let :ref do
|
282
|
+
ref = RecordRef.new
|
283
|
+
ref.type = 'record'
|
284
|
+
ref.external_id = 'boo'
|
285
|
+
ref.internal_id = nil
|
286
|
+
ref
|
287
|
+
end
|
288
|
+
let(:response) { double record: record }
|
289
|
+
let(:record) { double }
|
290
|
+
|
291
|
+
it { should eq record }
|
292
|
+
end
|
293
|
+
|
294
|
+
describe '.basic_search_class' do
|
295
|
+
subject { Record.basic_search_class }
|
296
|
+
it { should be RecordSearchBasic }
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchRecord do
|
4
|
+
class SearchRecord
|
5
|
+
attr_accessor :foo
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:search) do
|
9
|
+
search = SearchRecord.new
|
10
|
+
search.record_class = Record
|
11
|
+
search
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
Record.stub(:client) { client }
|
16
|
+
SearchRecord.stub(:inflected_method) { :foo }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#each' do
|
20
|
+
subject { search.each }
|
21
|
+
let(:client) { double search: response }
|
22
|
+
let(:response) { %i(a b c) }
|
23
|
+
it do
|
24
|
+
search.response.should_receive(:each).and_yield(response)
|
25
|
+
subject
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#where' do
|
30
|
+
subject { search.where *args }
|
31
|
+
let(:args) { double }
|
32
|
+
|
33
|
+
context 'when foo: "bar" given' do
|
34
|
+
let(:args) { [{foo: 'bar'}] }
|
35
|
+
let :where do
|
36
|
+
where = SearchRecord.new
|
37
|
+
where.foo = SearchStringField.new
|
38
|
+
where.foo.xmlattr_operator = SearchStringFieldOperator::Is
|
39
|
+
where.foo.searchValue = 'bar'
|
40
|
+
where
|
41
|
+
end
|
42
|
+
|
43
|
+
it { should be_a SearchRecord }
|
44
|
+
its(:foo) { should be_a SearchStringField }
|
45
|
+
its('foo.xmlattr_operator') { should eq SearchStringFieldOperator::Is }
|
46
|
+
its('foo.searchValue') { 'bar' }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchResult do
|
4
|
+
let(:result) { SearchResult.new }
|
5
|
+
|
6
|
+
describe '#has_more?' do
|
7
|
+
subject { result.has_more? }
|
8
|
+
before do
|
9
|
+
result.page_index = page_index
|
10
|
+
result.total_pages = total_pages
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when page_index < total_pages' do
|
14
|
+
let(:page_index) { 10 }
|
15
|
+
let(:total_pages) { 20 }
|
16
|
+
it { should be_true }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when page_index = total_pages' do
|
20
|
+
let(:page_index) { 10 }
|
21
|
+
let(:total_pages) { 10 }
|
22
|
+
it { should be_false }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|