activenetsuite 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be30c904151989986a967d8a1a3a7c7d2ab5b578
4
- data.tar.gz: c86034831bf144333cd794c566edd9b471eec078
3
+ metadata.gz: a3ae2182bb4b0ed5f80d1b87cfba3619ea67a377
4
+ data.tar.gz: 7bf7b4fb3bc103ffa0dc5232d65c1171e1083fd4
5
5
  SHA512:
6
- metadata.gz: 3f50d7ad4fdcc9e4dcb77fd2bffc11b90db0025836156e92228a08f77ef49b3747a401bef3c3fa497f8bfa648fee46d94a784625aa63af53097143470c6ee1ea
7
- data.tar.gz: ca254c174566c6947a992c51744f0ce2b95b29dd45c6897f9e5db679294a4087e7adb644da9262e08f5473c25fa700c7eb22639506dea28c9c3c4b66c00a772a
6
+ metadata.gz: f7795d2cfb911860ef8c60b9b402f64312caac098697792eaf299374d8162387a6e6584f651981799bd16a47ed56a11b2de895d1e3c1fa0cad03a6bdf0347d4b
7
+ data.tar.gz: b510bf5324e604bb2d0f3276ffb4145fe1c5246001cafd299b46317283503a67c4ed8b54d8e5922e8625a5501b719fb226680c94e5edc2a35b71840246dd4c1d
@@ -12,6 +12,7 @@ module NetSuite
12
12
 
13
13
  Dir.chdir(File.dirname(__FILE__)) do
14
14
  Dir[*%w(
15
+ activenetsuite/types/*.rb
15
16
  activenetsuite/helpers/*.rb
16
17
  activenetsuite/accounting/*.rb
17
18
  activenetsuite/core/*.rb
@@ -3,17 +3,9 @@ module ActiveNetsuite
3
3
  class Record
4
4
  include MethodInflector
5
5
 
6
- def to_s
7
- instance_variables.
8
- map do |var|
9
- [var, instance_variable_get(var)]
10
- end.
11
- select do |var, val|
12
- val
13
- end
14
- end
15
-
16
6
  class << self
7
+ extend Forwardable
8
+
17
9
  def client
18
10
  @@client ||= nil
19
11
  end
@@ -48,30 +40,17 @@ class Record
48
40
  "::#{to_s}SearchBasic".constantize
49
41
  end
50
42
 
51
- def search_next(search_result, page_index)
52
- client.search_next(search, page_index)
53
- end
43
+ def_delegators :search, :where, :find_by, :inactive, :active
54
44
 
55
- def where(*args)
56
- search.where(*args)
57
- end
58
-
59
- def find_by(*args)
60
- search.find_by(*args)
45
+ def list(objects)
46
+ objects = [objects] unless objects.respond_to?(:map)
47
+ client.get_list(refs(objects))
61
48
  end
62
49
 
63
50
  def all
64
51
  search.response
65
52
  end
66
53
 
67
- def inactive
68
- search.inactive
69
- end
70
-
71
- def active
72
- search.active
73
- end
74
-
75
54
  def delete(objects)
76
55
  objects = [objects] unless objects.respond_to?(:map)
77
56
  client.delete_list(refs(objects))
@@ -97,8 +76,13 @@ class Record
97
76
  client.get_deleted(get_deleted_filter)
98
77
  end
99
78
 
100
- # Convert Hash or Id to RecordRef
101
- # @param arg Hash or String
79
+ # Convert arg to RecordRef
80
+ # @overload ref(internal_id)
81
+ # @param [String] internal_id
82
+ # @overload ref(hash)
83
+ # @param [Hash] hash with internal_id or external_id
84
+ # @option opts [String] :internal_id
85
+ # @option opts [String] :external_id
102
86
  # @return RecordRef
103
87
  # @example
104
88
  # ref = Record.arg(12)
@@ -156,10 +140,38 @@ class Record
156
140
  res
157
141
  end
158
142
 
143
+ def add!
144
+ raise_on_fail(:add)
145
+ end
146
+
159
147
  def update
160
148
  client.update(self)
161
149
  end
162
150
 
151
+ def update!
152
+ raise_on_fail(:update)
153
+ end
154
+
155
+ def save
156
+ if new?
157
+ add
158
+ else
159
+ update
160
+ end
161
+ end
162
+
163
+ def save!
164
+ if new?
165
+ add!
166
+ else
167
+ update!
168
+ end
169
+ end
170
+
171
+ def new?
172
+ !internal_id
173
+ end
174
+
163
175
  def delete
164
176
  res = client.delete(ref)
165
177
  if res.success?
@@ -168,6 +180,10 @@ class Record
168
180
  res
169
181
  end
170
182
 
183
+ def delete!
184
+ raise_on_error(:delete)
185
+ end
186
+
171
187
  def client
172
188
  self.class.client
173
189
  end
@@ -175,9 +191,9 @@ class Record
175
191
  def load
176
192
  return self if loaded?
177
193
 
178
- record = find_by_id
179
- record.getters.each do |getter|
180
- send :"#{getter}=", record.send(getter)
194
+ result = find_by_id
195
+ result.getters.each do |getter|
196
+ send :"#{getter}=", result.send(getter)
181
197
  end
182
198
  @loaded = true
183
199
  self
@@ -188,7 +204,11 @@ class Record
188
204
  end
189
205
 
190
206
  def active?
191
- !inactive?
207
+ !is_inactive
208
+ end
209
+
210
+ def inactive?
211
+ !active?
192
212
  end
193
213
 
194
214
  def active=(value)
@@ -199,16 +219,6 @@ class Record
199
219
  self.is_inactive = !!value
200
220
  end
201
221
 
202
- def activate
203
- self.active = true
204
- self
205
- end
206
-
207
- def inactivate
208
- self.active = false
209
- self
210
- end
211
-
212
222
  def ref
213
223
  self.class.ref(internal_id)
214
224
  end
@@ -223,6 +233,12 @@ class Record
223
233
 
224
234
  private
225
235
 
236
+ def raise_on_fail(method)
237
+ res = send(method)
238
+ return res if res.success?
239
+ raise NetsuiteError, res
240
+ end
241
+
226
242
  def raise_not_found_error
227
243
  self.class.raise_not_found_error(ref)
228
244
  end
@@ -7,13 +7,7 @@ class SearchRecord
7
7
  attr_accessor :record_class
8
8
 
9
9
  def_delegators :response, :page_index, :page_size, :search_id, :total_pages,
10
- :total_records, :has_more?, :next
11
-
12
- def each
13
- response.each do |result|
14
- yield result if block_given?
15
- end
16
- end
10
+ :total_records, :more?, :next, :each, :to_a
17
11
 
18
12
  def where(*args)
19
13
  dup.send(:add, *args)
@@ -23,16 +17,25 @@ class SearchRecord
23
17
  where(*args).first
24
18
  end
25
19
 
26
- def to_a
27
- response.to_a
28
- end
29
-
30
20
  def inactive
31
- dup.send(:add, isInactive: true)
21
+ where(isInactive: true)
32
22
  end
33
23
 
34
24
  def active
35
- dup.send(:add, isInactive: false)
25
+ where(isInactive: false)
26
+ end
27
+
28
+ def deleted(op, val)
29
+ search_value = SearchDateField.new
30
+ search_value.xmlattr_operator = SearchDateFieldOperator.make(op)
31
+ search_value.predefinedSearchValue = SearchDate.make(val)
32
+
33
+ search_type = SearchEnumMultiSelectField.new
34
+ search_type.xmlattr_operator = SearchEnumMultiSelectFieldOperator::AnyOf
35
+ search_type.searchValue = type
36
+
37
+ get_deleted_filter = GetDeletedFilter.new(search_value, search_type)
38
+ client.get_deleted(get_deleted_filter)
36
39
  end
37
40
 
38
41
  def response
@@ -50,7 +53,7 @@ class SearchRecord
50
53
  def add(*args)
51
54
  if args.first.is_a?(Hash)
52
55
  @method, @value = args.first.flatten
53
- @op = :is
56
+ @op = default_operator
54
57
  end
55
58
  if args.size == 3
56
59
  @method, @op, @value = args
@@ -66,6 +69,19 @@ class SearchRecord
66
69
  self
67
70
  end
68
71
 
72
+ def default_operator
73
+ case value
74
+ when String
75
+ :is
76
+ when Fixnum
77
+ :equal_to
78
+ when Date, DateTime
79
+ :on
80
+ else
81
+ raise ArgumentError, "Can't find search class for #{value.inspect}"
82
+ end
83
+ end
84
+
69
85
  def search_class
70
86
  case value
71
87
  when String
@@ -89,7 +105,6 @@ class SearchRecord
89
105
 
90
106
  def record_class
91
107
  @record_class
92
- #"::#{self.class.to_s.gsub(/SearchBasic$/, '')}".constantize
93
108
  end
94
109
  end
95
110
 
@@ -3,7 +3,7 @@ module ActiveNetsuite
3
3
  class SearchResult
4
4
  include MethodInflector
5
5
 
6
- def has_more?
6
+ def more?
7
7
  page_index < total_pages
8
8
  end
9
9
  end
@@ -1,20 +1,27 @@
1
1
  module ActiveNetsuite
2
2
 
3
3
  class Status
4
- DUP_ITEM = 'DUP_ITEM'
5
- DUP_RCRD = 'DUP_RCRD'
6
- DUP_ENTITY = 'DUP_ENTITY'
7
- DUP_VENDOR_NAME = 'DUP_VENDOR_NAME'
8
- RCRD_TYPE_REQD = 'RCRD_TYPE_REQD'
9
- USER_ERROR = 'USER_ERROR'
10
- MAX_RCRDS_EXCEEDED = 'MAX_RCRDS_EXCEEDED'
11
- INVALID_INTERNALID = 'INVALID_INTERNALID'
12
- INVALID_FLD_VALUE = 'INVALID_FLD_VALUE'
4
+ # Make it so Status responds to error_code? style methods
5
+ # @param [Symbol] method name
6
+ # @return [Boolean]
7
+ # @example
8
+ # status.code # => 'DUP_ITEM'
9
+ # status.dup_item? # => true
10
+ # status.cogs_error? # => false
11
+ def method_missing(method)
12
+ if method.to_s.end_with?('?')
13
+ code == method.to_s.chop.upcase
14
+ else
15
+ super
16
+ end
17
+ end
13
18
 
19
+ # True if status is success
14
20
  def success?
15
- xmlattr_isSuccess
21
+ !!xmlattr_isSuccess
16
22
  end
17
23
 
24
+ # True if status is failure
18
25
  def failure?
19
26
  !success?
20
27
  end
@@ -27,15 +34,6 @@ class Status
27
34
  status_detail.message if status_detail
28
35
  end
29
36
 
30
- constants.each do |constant|
31
- name = (constant.to_s.underscore + '?').to_sym
32
- value = const_get(constant)
33
- next unless value.is_a?(String)
34
- define_method name do
35
- code == value
36
- end
37
- end
38
-
39
37
  def duplicate?
40
38
  dup_item? || dup_rcrd? || dup_entity? || dup_vendor_name?
41
39
  end
@@ -0,0 +1,6 @@
1
+ module ActiveNetsuite
2
+
3
+ class StatusDetail
4
+ end
5
+
6
+ end
@@ -65,7 +65,7 @@ class Client
65
65
  @driver.get(GetRequest.new(ref))
66
66
  end
67
67
 
68
- def get_all(refs)
68
+ def get_list(refs)
69
69
  @driver.getList(GetListRequest.new(refs))
70
70
  end
71
71
 
@@ -1,7 +1,6 @@
1
1
  module ActiveNetsuite
2
2
 
3
- class NotFoundError < StandardError
4
- end
3
+ class NetsuiteError < StandardError; end
4
+ class NotFoundError < NetsuiteError; end
5
5
 
6
6
  end
7
-
@@ -7,7 +7,7 @@ module SearchResponseMethods
7
7
  def_delegators :records, :[]
8
8
 
9
9
  def_delegators :result, :page_index, :page_size, :search_id, :total_pages,
10
- :total_records, :has_more?
10
+ :total_records, :more?
11
11
 
12
12
  def each
13
13
  records.each do |record|
@@ -0,0 +1,18 @@
1
+ module ActiveNetsuite
2
+
3
+ class GetListResponse
4
+ include Enumerable
5
+ extend Forwardable
6
+
7
+ def_delegators :records, :[]
8
+
9
+ alias_method :records, :readResponseList
10
+
11
+ def each
12
+ records.each do |record|
13
+ yield record if block_given?
14
+ end
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,9 @@
1
+ module ActiveNetsuite
2
+
3
+ class SearchDate < ::String
4
+ def self.make(operator)
5
+ (name + '::' + operator.to_s.camelize).constantize
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ module ActiveNetsuite
2
+
3
+ class SearchDateFieldOperator < ::String
4
+ def self.make(operator)
5
+ (name + '::' + operator.to_s.camelize).constantize
6
+ end
7
+ end
8
+
9
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveNetsuite
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -26,21 +26,22 @@ class ActiveNetsuite::Record
26
26
 
27
27
  attr_accessor :foo
28
28
  attr_accessor :bar
29
+ attr_accessor :is_inactive
29
30
  end
30
31
 
31
32
  class ActiveNetsuite::RecordSearchBasic; end
32
33
 
33
34
  describe Record do
34
- let(:model) { Record.new args }
35
+ let(:record) { Record.new args }
35
36
  let(:args) { nil }
36
37
  let(:client) { double }
37
38
  before { Record.client = client }
38
39
 
39
40
  describe '#add' do
40
- subject { model.add }
41
+ subject { record.add }
41
42
 
42
43
  before do
43
- model.client.stub(:add) { result }
44
+ record.client.stub(:add) { result }
44
45
  end
45
46
  let(:result) { double success?: success, internal_id: :internal_id }
46
47
  let(:success) { true }
@@ -49,31 +50,56 @@ describe Record do
49
50
 
50
51
  context 'when success' do
51
52
  let(:success) { true }
52
- it { expect { subject }.to change { model.internal_id }.to(:internal_id) }
53
+ it { expect { subject }.to change { record.internal_id }.to(:internal_id) }
53
54
  end
54
55
 
55
56
  context 'when not success' do
56
57
  let(:success) { false }
57
58
  it { expect { subject }.to_not \
58
- change { model.internal_id }.to(:internal_id) }
59
+ change { record.internal_id }.to(:internal_id) }
59
60
  end
60
61
  end
61
62
 
63
+ describe '#add!' do
64
+ subject { record.add! }
65
+
66
+ before do
67
+ record.client.stub(:add) { result }
68
+ end
69
+ let(:result) { double success?: success, internal_id: :internal_id }
70
+ let(:success) { true }
71
+
72
+ it { should eq result }
73
+
74
+ context 'when success' do
75
+ let(:success) { true }
76
+ it { expect { subject }.to change { record.internal_id }.to(:internal_id) }
77
+ end
78
+
79
+ context 'when not success' do
80
+ let(:success) { false }
81
+ it { expect { subject rescue nil }.to_not \
82
+ change { record.internal_id }.to(:internal_id) }
83
+ it { expect { subject }.to raise_error NetsuiteError }
84
+ end
85
+
86
+ end
87
+
62
88
  describe '#update' do
63
- subject { model.update }
89
+ subject { record.update }
64
90
 
65
- before { model.client.stub(:update).with(model) { result } }
91
+ before { record.client.stub(:update).with(record) { result } }
66
92
  let(:result) { double }
67
93
 
68
94
  it { should be result }
69
95
  end
70
96
 
71
97
  describe '#delete' do
72
- subject { model.delete }
98
+ subject { record.delete }
73
99
 
74
100
  before do
75
101
  client.stub(:delete) { result }
76
- model.internal_id = 100
102
+ record.internal_id = 100
77
103
  end
78
104
  let(:result) { double success?: success }
79
105
  let(:success) { true }
@@ -81,34 +107,34 @@ describe Record do
81
107
 
82
108
  context 'when it is success' do
83
109
  let(:success) { true }
84
- it { expect { subject }.to change { model.internal_id }.to(nil) }
110
+ it { expect { subject }.to change { record.internal_id }.to(nil) }
85
111
  end
86
112
 
87
113
  context 'when it is failure' do
88
114
  let(:success) { false }
89
- it { expect { subject }.to_not change { model.internal_id }.from(100) }
115
+ it { expect { subject }.to_not change { record.internal_id }.from(100) }
90
116
  end
91
117
  end
92
118
 
93
119
  describe '#client' do
94
- subject { model.client }
95
- before { model.class.client = client }
120
+ subject { record.client }
121
+ before { record.class.client = client }
96
122
  let(:client) { double }
97
123
 
98
124
  it { should be client }
99
125
  end
100
126
 
101
127
  describe '#load' do
102
- subject { model.load }
103
- before { model.instance_variable_set(:@loaded, loaded) }
128
+ subject { record.load }
129
+ before { record.instance_variable_set(:@loaded, loaded) }
104
130
  let(:loaded) { double }
105
131
 
106
- it { should be model }
132
+ it { should be record }
107
133
 
108
134
  context 'when already loaded' do
109
135
  let(:loaded) { true }
110
136
 
111
- it { should be model }
137
+ it { should be record }
112
138
  it do
113
139
  client.should_not_receive(:get)
114
140
  subject
@@ -119,38 +145,38 @@ describe Record do
119
145
  let(:loaded) { false }
120
146
 
121
147
  before do
122
- model.internal_id = 123
123
- client.stub(:get) { double record: record }
148
+ record.internal_id = 123
149
+ client.stub(:get) { double record: result }
124
150
  end
125
151
 
126
- let(:record) do
152
+ let(:result) do
127
153
  double getters: [:foo, :bar],
128
154
  foo: :foo,
129
155
  bar: :bar
130
156
  end
131
157
 
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) }
158
+ it { expect { subject }.to change { record.loaded? }.to(true) }
159
+ it { expect { subject }.to change { record.foo }.to(:foo) }
160
+ it { expect { subject }.to change { record.bar }.to(:bar) }
135
161
  end
136
162
  end
137
163
 
138
164
  describe '#loaded?' do
139
- subject { model.loaded? }
140
- before { model.instance_variable_set(:@loaded, true) }
165
+ subject { record.loaded? }
166
+ before { record.instance_variable_set(:@loaded, true) }
141
167
  it { should be_true }
142
168
  end
143
169
 
144
170
  describe '#ref' do
145
- subject { model.ref }
171
+ subject { record.ref }
146
172
 
147
173
  it { should be_a RecordRef }
148
174
  its(:type) { should eq "record" }
149
- its(:internal_id) { should eq model.internal_id }
175
+ its(:internal_id) { should eq record.internal_id }
150
176
  end
151
177
 
152
178
  describe '#setters' do
153
- subject { model.setters }
179
+ subject { record.setters }
154
180
  it do
155
181
  should include :foo=, :bar=, :nullFieldList=,
156
182
  :xmlattr_externalId=, :xmlattr_internalId=
@@ -158,12 +184,68 @@ describe Record do
158
184
  end
159
185
 
160
186
  describe '#getters' do
161
- subject { model.getters }
187
+ subject { record.getters }
162
188
  it do
163
189
  should include :foo, :bar, :xmlattr_externalId, :xmlattr_internalId
164
190
  end
165
191
  end
166
192
 
193
+ describe '.list' do
194
+ subject { described_class.list(objects) }
195
+
196
+ let(:ids) { [10, 20] }
197
+
198
+ let(:recs) do
199
+ ids.map do |id|
200
+ rec = Record.new
201
+ rec.internal_id = id
202
+ rec
203
+ end
204
+ end
205
+
206
+ let(:refs) do
207
+ ids.map do |id|
208
+ ref = RecordRef.new
209
+ ref.internal_id = id
210
+ ref.type = 'record'
211
+ ref
212
+ end
213
+ end
214
+
215
+ context 'when internal ids given' do
216
+ let(:objects) { ids }
217
+
218
+ it do
219
+ described_class.client.should_receive(:get_list) do |args|
220
+ args == refs
221
+ end
222
+ subject
223
+ end
224
+ end
225
+
226
+ context 'when Records given' do
227
+ let(:objects) { recs }
228
+
229
+ it do
230
+ described_class.client.should_receive(:get_list) do |args|
231
+ args == refs
232
+ end
233
+ subject
234
+ end
235
+ end
236
+
237
+ context 'when Refs given' do
238
+ let(:objects) { refs }
239
+
240
+ it do
241
+ described_class.client.should_receive(:get_list) do |args|
242
+ args == refs
243
+ end
244
+ subject
245
+ end
246
+ end
247
+ end
248
+
167
249
  describe '.delete' do
168
250
  subject { described_class.delete(objects) }
169
251
 
@@ -295,4 +377,61 @@ describe Record do
295
377
  subject { Record.basic_search_class }
296
378
  it { should be RecordSearchBasic }
297
379
  end
380
+
381
+ describe '#active?' do
382
+ subject { record.active? }
383
+
384
+ context 'when is_inactive=true' do
385
+ before { record.is_inactive = true }
386
+ it { should be_false }
387
+ end
388
+
389
+ context 'when is_inactive=false' do
390
+ before { record.is_inactive = false }
391
+ it { should be_true }
392
+ end
393
+ end
394
+
395
+ describe '#save' do
396
+ subject { record.save }
397
+ let :result do
398
+ double success?: true, internal_id: 123
399
+ end
400
+ before do
401
+ client.stub(:add).with(record) { result }
402
+ end
403
+
404
+ context 'when new record' do
405
+ before { record.internal_id = nil }
406
+ specify do
407
+ client.should_receive(:add).with(record) { result }
408
+ subject
409
+ end
410
+
411
+ it { expect { subject }.to change { record.internal_id }.to(123) }
412
+ end
413
+
414
+ context 'when existing record' do
415
+ before { record.internal_id = 123 }
416
+ specify do
417
+ client.should_receive(:update).with(record) { result }
418
+ subject
419
+ end
420
+ end
421
+ end
422
+
423
+ describe '#new?' do
424
+ subject { record.new? }
425
+ before { record.internal_id = internal_id }
426
+
427
+ context 'when there is no internal_id' do
428
+ let(:internal_id) { nil }
429
+ it { should be_true }
430
+ end
431
+
432
+ context 'when there is internal_id' do
433
+ let(:internal_id) { 123 }
434
+ it { should be_false }
435
+ end
436
+ end
298
437
  end
@@ -10,41 +10,89 @@ describe SearchRecord do
10
10
  search.record_class = Record
11
11
  search
12
12
  end
13
+ let(:client) { double search: response }
14
+ let(:response) { double }
13
15
 
14
16
  before do
15
17
  Record.stub(:client) { client }
16
18
  SearchRecord.stub(:inflected_method) { :foo }
17
19
  end
18
20
 
19
- describe '#each' do
20
- subject { search.each }
21
- let(:client) { double search: response }
22
- let(:response) { [:a, :b, :c] }
23
- it do
24
- search.response.should_receive(:each).and_yield(response)
25
- subject
26
- end
27
- end
28
-
29
21
  describe '#where' do
30
22
  subject { search.where *args }
31
23
  let(:args) { double }
32
24
 
33
25
  context 'when foo: "bar" given' do
34
26
  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
27
 
43
28
  it { should be_a SearchRecord }
29
+ it { should_not be search }
44
30
  its(:foo) { should be_a SearchStringField }
45
31
  its('foo.xmlattr_operator') { should eq SearchStringFieldOperator::Is }
46
32
  its('foo.searchValue') { 'bar' }
47
33
  end
34
+
35
+ context 'when foo: 10 given' do
36
+ let(:args) { [{foo: 10} ] }
37
+
38
+ it { should be_a SearchRecord }
39
+ it { should_not be search }
40
+ its(:foo) { should be_a SearchLongField }
41
+ its('foo.xmlattr_operator') { should eq SearchLongFieldOperator::EqualTo }
42
+ its('foo.searchValue') { 10 }
43
+ end
44
+
45
+ context 'when foo: Date.new(2000, 1, 2) given' do
46
+ let(:args) { [{foo: Date.new(2000, 1, 2)} ] }
47
+
48
+ it { should be_a SearchRecord }
49
+ it { should_not be search }
50
+ its(:foo) { should be_a SearchDateField }
51
+ its('foo.xmlattr_operator') { should eq SearchDateFieldOperator::On }
52
+ its('foo.searchValue') { Date.new(2000, 1, 2) }
53
+ end
54
+
55
+ context 'when :foo, :has_keywords, "key" given' do
56
+ let(:args) { [:foo, :has_keywords, 'key'] }
57
+
58
+ it { should be_a SearchRecord }
59
+ it { should_not be search }
60
+ its(:foo) { should be_a SearchStringField }
61
+ its('foo.xmlattr_operator') { should eq SearchStringFieldOperator::HasKeywords }
62
+ its('foo.searchValue') { 'key' }
63
+ end
64
+ end
65
+
66
+ describe '#find_by' do
67
+ subject { search.find_by *args }
68
+ end
69
+
70
+ describe 'response delegators' do
71
+ [:page_index, :page_size, :search_id, :total_pages,
72
+ :total_records, :more?, :next, :each].each do |method|
73
+
74
+ describe "#{method}" do
75
+ subject { search.send method }
76
+ let(:response) { double method => value }
77
+ let(:value) { double }
78
+ specify do
79
+ client.should_receive(:search).with(search) { response }
80
+ should eq value
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#find_by' do
87
+ subject { search.find_by *args }
88
+ before do
89
+ search.stub(:where).with(args) { response }
90
+ end
91
+ let(:args) { double }
92
+ let(:response) { double first: record }
93
+ let(:record) { double }
94
+
95
+ it { should eq record }
48
96
  end
49
97
  end
50
98
 
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe SearchResult do
4
4
  let(:result) { SearchResult.new }
5
5
 
6
- describe '#has_more?' do
7
- subject { result.has_more? }
6
+ describe '#more?' do
7
+ subject { result.more? }
8
8
  before do
9
9
  result.page_index = page_index
10
10
  result.total_pages = total_pages
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Status do
4
+ let(:status) { described_class.new }
5
+
6
+ describe '#success?' do
7
+ subject { status.success? }
8
+ before { status.stub(:xmlattr_isSuccess) { false } }
9
+ it { should be_false }
10
+ end
11
+
12
+ describe '#failure?' do
13
+ subject { status.failure? }
14
+ before { status.stub(:xmlattr_isSuccess) { false } }
15
+ it { should be_true }
16
+ end
17
+
18
+ describe '#code' do
19
+ subject { status.code }
20
+ before do
21
+ status.stub(:statusDetail) { status_detail }
22
+ end
23
+
24
+ context 'when there is statusDetail' do
25
+ let(:status_detail) { [double(code: :code)] }
26
+ it { should be :code }
27
+ end
28
+
29
+ context 'when there is no statusDetail' do
30
+ let(:status_detail) { nil }
31
+ it { should be_nil }
32
+ end
33
+ end
34
+
35
+ describe '#message' do
36
+ subject { status.message }
37
+ before do
38
+ status.stub(:statusDetail) { status_detail }
39
+ end
40
+
41
+ context 'when there is statusDetail' do
42
+ let(:status_detail) { [double(message: :message)] }
43
+ it { should be :message }
44
+ end
45
+
46
+ context 'when there is no statusDetail' do
47
+ let(:status_detail) { nil }
48
+ it { should be_nil }
49
+ end
50
+ end
51
+
52
+ describe '#duplicate?' do
53
+ subject { status.duplicate? }
54
+ before do
55
+ status.stub(:statusDetail) { [double(code: code)] }
56
+ end
57
+
58
+ context 'when code==DUP_ITEM for example' do
59
+ let(:code) { 'DUP_ITEM' }
60
+ it { should be_true }
61
+ end
62
+
63
+ context 'when code==COGS_ERROR for example' do
64
+ let(:code) { 'COGS_ERROR' }
65
+ it { should be_false }
66
+ end
67
+ end
68
+
69
+ describe '#missing_method' do
70
+ subject { status.send method }
71
+ before do
72
+ status.stub(:statusDetail) { [double(code: code)] }
73
+ end
74
+
75
+ context 'when method ends with ? and matches code' do
76
+ let(:method) { :dup_item? }
77
+ let(:code) { 'DUP_ITEM' }
78
+ it { should be_true }
79
+ end
80
+
81
+ context 'when method ends with ? and does not match code' do
82
+ let(:method) { :dup_item? }
83
+ let(:code) { 'COGS_ERROR' }
84
+ it { should be_false }
85
+ end
86
+
87
+ context 'when method does not end with ?' do
88
+ let(:method) { :missing }
89
+ it 'does not try to evaluate code' do
90
+ status.should_not_receive(:code)
91
+ subject rescue nil
92
+ end
93
+ end
94
+ end
95
+ end
@@ -105,8 +105,39 @@ describe Client do
105
105
  it do
106
106
  client.driver.should_receive(:addList) do |req|
107
107
  req.should be_a AddListRequest
108
- req.should have(1).record
109
- req.first.should eq recs.first
108
+ req.should eq recs
109
+ res
110
+ end
111
+ should eq res
112
+ end
113
+ end
114
+
115
+ describe '#update' do
116
+ subject { client.update(rec) }
117
+
118
+ let(:rec) { double }
119
+ let(:res) { double }
120
+
121
+ it do
122
+ client.driver.should_receive(:update) do |req|
123
+ req.should be_a UpdateRequest
124
+ req.record.should be rec
125
+ res
126
+ end
127
+ should eq res
128
+ end
129
+ end
130
+
131
+ describe '#update_list' do
132
+ subject { client.update_list(recs) }
133
+
134
+ let(:recs) { [double] }
135
+ let(:res) { double }
136
+
137
+ it do
138
+ client.driver.should_receive(:updateList) do |req|
139
+ req.should be_a UpdateListRequest
140
+ req.should eq recs
110
141
  res
111
142
  end
112
143
  should eq res
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe SearchDateFieldOperator do
4
+ describe '.make' do
5
+ subject { described_class.make :not_empty }
6
+ it { should be described_class::NotEmpty }
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe SearchDate do
4
+ describe '.make' do
5
+ subject { described_class.make :next_week }
6
+ it { should be described_class::NextWeek }
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activenetsuite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stan Mazhara
@@ -149,6 +149,7 @@ files:
149
149
  - lib/activenetsuite/core/search_record.rb
150
150
  - lib/activenetsuite/core/search_result.rb
151
151
  - lib/activenetsuite/core/status.rb
152
+ - lib/activenetsuite/core/status_detail.rb
152
153
  - lib/activenetsuite/helpers/client.rb
153
154
  - lib/activenetsuite/helpers/error.rb
154
155
  - lib/activenetsuite/helpers/method_inflector.rb
@@ -159,6 +160,7 @@ files:
159
160
  - lib/activenetsuite/messages/delete_response.rb
160
161
  - lib/activenetsuite/messages/get_deleted_response.rb
161
162
  - lib/activenetsuite/messages/get_deleted_result.rb
163
+ - lib/activenetsuite/messages/get_list_response.rb
162
164
  - lib/activenetsuite/messages/get_response.rb
163
165
  - lib/activenetsuite/messages/read_response.rb
164
166
  - lib/activenetsuite/messages/search_more_with_id_response.rb
@@ -173,6 +175,8 @@ files:
173
175
  - lib/activenetsuite/soap/default.rb
174
176
  - lib/activenetsuite/soap/defaultDriver.rb
175
177
  - lib/activenetsuite/soap/defaultMappingRegistry.rb
178
+ - lib/activenetsuite/types/search_date.rb
179
+ - lib/activenetsuite/types/search_date_field_operator.rb
176
180
  - lib/activenetsuite/version.rb
177
181
  - spec/lib/activenetsuite/accounting/account_spec.rb
178
182
  - spec/lib/activenetsuite/accounting/non_inventory_sale_item_spec.rb
@@ -180,6 +184,7 @@ files:
180
184
  - spec/lib/activenetsuite/core/record_spec.rb
181
185
  - spec/lib/activenetsuite/core/search_record_spec.rb
182
186
  - spec/lib/activenetsuite/core/search_result_spec.rb
187
+ - spec/lib/activenetsuite/core/status_spec.rb
183
188
  - spec/lib/activenetsuite/helpers/client_spec.rb
184
189
  - spec/lib/activenetsuite/helpers/method_inflector_spec.rb
185
190
  - spec/lib/activenetsuite/helpers/search_response_methods_spec.rb
@@ -189,6 +194,8 @@ files:
189
194
  - spec/lib/activenetsuite/relationships/vendor_spec.rb
190
195
  - spec/lib/activenetsuite/sales/cash_refund_spec.rb
191
196
  - spec/lib/activenetsuite/sales/cash_sale_spec.rb
197
+ - spec/lib/activenetsuite/types/search_date_field_operator_spec.rb
198
+ - spec/lib/activenetsuite/types/search_date_spec.rb
192
199
  - spec/spec_helper.rb
193
200
  homepage: https://github.com/smazhara/activenetsuite
194
201
  licenses: