cheddargetter_client_ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cheddargetter_client_ruby}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Expected Behavior"]
12
- s.date = %q{2010-12-09}
12
+ s.date = %q{2010-12-10}
13
13
  s.description = %q{A CheddarGetter API wrapper for Ruby}
14
14
  s.email = %q{support@expectedbehavior.com}
15
15
  s.extra_rdoc_files = [
data/example/example.rb CHANGED
@@ -18,7 +18,7 @@ response = client.delete_all_customers
18
18
  if response.valid?
19
19
  puts "\tDeleted old customers"
20
20
  else
21
- puts "\tERROR: #{response.error_message}"
21
+ puts "\tERROR: #{response.error_messages.inspect}"
22
22
  end
23
23
 
24
24
  puts ""
@@ -41,7 +41,7 @@ response = client.new_customer(data)
41
41
  if response.valid?
42
42
  puts "\tCreated Milton Waddams with code=MILTON_WADDAMS"
43
43
  else
44
- puts "\tERROR: #{response.error_message}"
44
+ puts "\tERROR: #{response.error_messages.inspect}"
45
45
  end
46
46
 
47
47
  puts ""
@@ -70,7 +70,7 @@ response = client.new_customer(data)
70
70
  if response.valid?
71
71
  puts "\tCreated Bill Lumberg with code=BILL_LUMBERG. (This should not have happened)"
72
72
  else
73
- puts "\tExpect Error: #{response.error_message}"
73
+ puts "\tExpect Error: #{response.error_messages.inspect}"
74
74
  end
75
75
 
76
76
  puts ""
@@ -100,7 +100,7 @@ response = client.new_customer(data)
100
100
  if response.valid?
101
101
  puts "\tCreated Bill Lumberg with code=BILL_LUMBERG"
102
102
  else
103
- puts "\tERROR: #{response.error_message}"
103
+ puts "\tERROR: #{response.error_messages.inspect}"
104
104
  end
105
105
 
106
106
  #get lumberg and display current details
@@ -118,5 +118,5 @@ if response.valid?
118
118
  puts "\t\t(#{charge[:quantity]}) #{charge[:code]} $#{charge[:eachAmount]*charge[:quantity]}"
119
119
  end
120
120
  else
121
- puts "\tERROR: #{response.error_message}"
121
+ puts "\tERROR: #{response.error_messages.inspect}"
122
122
  end
@@ -7,7 +7,8 @@ module CheddarGetter
7
7
  :customers => :customer,
8
8
  :invoices => :invoice,
9
9
  :charges => :charge,
10
- :transactions => :transaction
10
+ :transactions => :transaction,
11
+ :errors => :error
11
12
  }
12
13
 
13
14
  KEY_TO_DATA_TYPE = {
@@ -42,7 +43,7 @@ module CheddarGetter
42
43
  create_clean_response
43
44
  end
44
45
 
45
- [:error, :plans, :customers].each do |key|
46
+ [:errors, :plans, :customers].each do |key|
46
47
  define_method key.to_s do
47
48
  self[key]
48
49
  end
@@ -50,18 +51,19 @@ module CheddarGetter
50
51
 
51
52
  #true if the response from CheddarGetter was valid
52
53
  def valid?
53
- !self.error && self.raw_response.code < 400
54
+ self.errors.size == 0 && self.raw_response.code < 400
54
55
  end
55
56
 
56
- #the error message (if there was one) if the CheddarGetter response was invalid
57
- def error_message
58
- e = self.error
59
- msg = nil
60
- if e
61
- msg = e[:text]
62
- msg += ": #{e[:fieldName]}" unless e[:fieldName].blank?
57
+ #the error messages (if there were any) if the CheddarGetter response was invalid
58
+ def error_messages
59
+ self.errors.map do |e|
60
+ msg = nil
61
+ if e
62
+ msg = e[:text]
63
+ msg += ": #{e[:fieldName]}" unless e[:fieldName].blank?
64
+ end
65
+ msg
63
66
  end
64
- msg
65
67
  end
66
68
 
67
69
  #Returns the given plan.
@@ -288,9 +290,24 @@ module CheddarGetter
288
290
  end
289
291
  end
290
292
 
293
+ def reduce_clean_errors!(data)
294
+ root_plural = [(data.delete(:errors) || { })[:error]].flatten
295
+ root_singular = [data.delete(:error)]
296
+ embed_singluar = []
297
+ embed_plural = []
298
+ embed = data[:customers] || data[:plans]
299
+ if embed
300
+ embed_singluar = [(embed.delete(:errors) || { })[:error]].flatten
301
+ embed_plural = [embed.delete(:error)]
302
+ end
303
+ new_errors = (root_plural + root_singular + embed_plural + embed_singluar).compact
304
+ data[:errors] = new_errors
305
+ end
306
+
291
307
  def create_clean_response
292
308
  data = self.raw_response.parsed_response.is_a?(Hash) ? self.raw_response.parsed_response : { }
293
309
  deep_symbolize_keys!(data)
310
+ reduce_clean_errors!(data)
294
311
  deep_fix_array_keys!(data)
295
312
  deep_fix_data_types!(data)
296
313
  self.clean_response = data
@@ -300,16 +317,19 @@ module CheddarGetter
300
317
  data = Crack::XML.parse(self.raw_response.body.gsub(/<error(.*)>(.*)<\/error>/,
301
318
  '<error\1><text>\2</text></error>'))
302
319
  deep_symbolize_keys!(data)
320
+ reduce_clean_errors!(data)
303
321
  deep_fix_array_keys!(data)
304
322
  deep_fix_data_types!(data)
305
323
  self.clean_response = data
306
-
307
- aux_code = (self.error[:auxCode] || "")
308
- if aux_code[":"]
309
- split_aux_code = aux_code.split(':')
310
- self.error[:fieldName] = split_aux_code.first
311
- self.error[:errorType] = split_aux_code.last
324
+ self.errors.each do |e|
325
+ aux_code = (e[:auxCode] || "")
326
+ if aux_code[":"]
327
+ split_aux_code = aux_code.split(':')
328
+ e[:fieldName] = split_aux_code.first
329
+ e[:errorType] = split_aux_code.last
330
+ end
312
331
  end
332
+
313
333
  end
314
334
 
315
335
  end
@@ -51,7 +51,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
51
51
  },
52
52
  }
53
53
  end
54
-
54
+
55
55
  should "check various client init exceptions" do
56
56
  assert_raises(CheddarGetter::ClientException) do
57
57
  CheddarGetter::Client.new(:product_code => "code", :password => "password")
@@ -75,24 +75,25 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
75
75
 
76
76
  result = cg.get_plans
77
77
  assert_equal false, result.valid?
78
- assert_equal "Authentication required", result.error_message
78
+ assert_equal ["Authentication required"], result.error_messages
79
79
 
80
80
  cg.username = CG.username
81
81
  cg.password = CG.password
82
82
  result = cg.get_plans
83
83
  assert_equal false, result.valid?
84
- assert_equal "User michael@expectedbehavior.com does not have access to productCode=code", result.error_message
84
+ assert_equal ["User michael@expectedbehavior.com does not have access to productCode=code"],
85
+ result.error_messages
85
86
 
86
87
  cg.product_code = ""
87
88
  result = cg.get_plans
88
89
  assert_equal false, result.valid?
89
- assert_equal "No product selected. Need a productId or productCode.", result.error_message
90
+ assert_equal ["No product selected. Need a productId or productCode."], result.error_messages
90
91
 
91
92
  cg.product_code = nil
92
93
  cg.product_id = "id"
93
94
  result = cg.get_plans
94
95
  assert_equal false, result.valid?
95
- assert_equal "User does not have access to productId=id", result.error_message
96
+ assert_equal ["User does not have access to productId=id"], result.error_messages
96
97
  end
97
98
 
98
99
  should "get 3 plans from cheddar getter" do
@@ -136,7 +137,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
136
137
 
137
138
  result = CG.get_plan(:code => "NOT_A_PLAN")
138
139
  assert_equal false, result.valid?
139
- assert_equal "Plan not found for code=NOT_A_PLAN within productCode=GEM_TEST", result.error_message
140
+ assert_equal ["Plan not found for code=NOT_A_PLAN within productCode=GEM_TEST"], result.error_messages
140
141
  end
141
142
 
142
143
  should "create a single free customer at cheddar getter" do
@@ -166,74 +167,74 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
166
167
  data[:subscription].delete(:ccCardCode)
167
168
  result = CG.new_customer(data)
168
169
  assert_equal false, result.valid?
169
- assert_equal "A value is required: subscription[ccCardCode]", result.error_message
170
+ assert_equal ["A value is required: subscription[ccCardCode]"], result.error_messages
170
171
 
171
172
  data[:subscription][:ccExpiration] = "00/0000"
172
173
  result = CG.new_customer(data)
173
174
  assert_equal false, result.valid?
174
- assert_equal("'00/0000' is not a valid date in format MM/YYYY: subscription[ccExpiration]",
175
- result.error_message)
175
+ assert_equal(["'00/0000' is not a valid date in format MM/YYYY: subscription[ccExpiration]"],
176
+ result.error_messages)
176
177
 
177
178
  data[:subscription].delete(:ccExpiration)
178
179
  result = CG.new_customer(data)
179
180
  assert_equal false, result.valid?
180
- assert_equal "A value is required: subscription[ccExpiration]", result.error_message
181
+ assert_equal ["A value is required: subscription[ccExpiration]"], result.error_messages
181
182
 
182
183
  data[:subscription][:ccNumber] = "1"
183
184
  result = CG.new_customer(data)
184
185
  assert_equal false, result.valid?
185
- assert_equal("'1' is not from an allowed institute: subscription[ccNumber]",
186
- result.error_message)
186
+ assert_equal(["'1' is not from an allowed institute: subscription[ccNumber]"],
187
+ result.error_messages)
187
188
 
188
189
  data[:subscription].delete(:ccNumber)
189
190
  result = CG.new_customer(data)
190
191
  assert_equal false, result.valid?
191
- assert_equal "A value is required: subscription[ccNumber]", result.error_message
192
+ assert_equal ["A value is required: subscription[ccNumber]"], result.error_messages
192
193
 
193
194
  data[:subscription].delete(:ccZip)
194
195
  result = CG.new_customer(data)
195
196
  assert_equal false, result.valid?
196
- assert_equal "A value is required: subscription[ccZip]", result.error_message
197
+ assert_equal ["A value is required: subscription[ccZip]"], result.error_messages
197
198
 
198
199
  data[:subscription].delete(:ccLastName)
199
200
  result = CG.new_customer(data)
200
201
  assert_equal false, result.valid?
201
- assert_equal "A value is required: subscription[ccLastName]", result.error_message
202
+ assert_equal ["A value is required: subscription[ccLastName]"], result.error_messages
202
203
 
203
204
  data[:subscription].delete(:ccFirstName)
204
205
  result = CG.new_customer(data)
205
206
  assert_equal false, result.valid?
206
- assert_equal "A value is required: subscription[ccFirstName]", result.error_message
207
+ assert_equal ["A value is required: subscription[ccFirstName]"], result.error_messages
207
208
 
208
209
  data.delete(:email)
209
210
  result = CG.new_customer(data)
210
211
  assert_equal false, result.valid?
211
- assert_equal "A value is required: email", result.error_message
212
+ assert_equal ["A value is required: email"], result.error_messages
212
213
 
213
214
  data.delete(:code)
214
215
  result = CG.new_customer(data)
215
216
  assert_equal false, result.valid?
216
- assert_equal "A value is required: code", result.error_message
217
+ assert_equal ["A value is required: code"], result.error_messages
217
218
 
218
219
  data.delete(:lastName)
219
220
  result = CG.new_customer(data)
220
221
  assert_equal false, result.valid?
221
- assert_equal "A value is required: lastName", result.error_message
222
+ assert_equal ["A value is required: lastName"], result.error_messages
222
223
 
223
224
  data.delete(:firstName)
224
225
  result = CG.new_customer(data)
225
226
  assert_equal false, result.valid?
226
- assert_equal "A value is required: firstName", result.error_message
227
+ assert_equal ["A value is required: firstName"], result.error_messages
227
228
 
228
229
  data[:subscription][:planCode] = "NOT_A_PLAN"
229
230
  result = CG.new_customer(data)
230
231
  assert_equal false, result.valid?
231
- assert_equal "No plan found with code=NOT_A_PLAN", result.error_message
232
+ assert_equal ["No plan found with code=NOT_A_PLAN"], result.error_messages
232
233
 
233
234
  data[:subscription].delete(:planCode)
234
235
  result = CG.new_customer(data)
235
236
  assert_equal false, result.valid?
236
- assert_equal "A pricing plan is required", result.error_message
237
+ assert_equal ["A pricing plan is required"], result.error_messages
237
238
  end
238
239
 
239
240
  should "try to create a customer with direct forced card errors" do
@@ -243,7 +244,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
243
244
  ERROR_CODES.each do |k, v|
244
245
  result = CG.new_customer(paid_new_user_hash(1, "0#{k}"))
245
246
  assert_equal false, result.valid?
246
- assert_equal v, result.error_message
247
+ assert_equal [v], result.error_messages
247
248
  end
248
249
 
249
250
  end
@@ -257,7 +258,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
257
258
 
258
259
  result = CG.new_customer(paid_new_user_hash(1))
259
260
  assert_equal false, result.valid?
260
- assert_equal "Another customer already exists with code=1: code", result.error_message
261
+ assert_equal ["Another customer already exists with code=1: code"], result.error_messages
261
262
  end
262
263
 
263
264
  should "get customers from cheddargetter" do
@@ -340,7 +341,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
340
341
  assert_raises(CheddarGetter::ClientException){ CG.get_customer }
341
342
  result = CG.get_customer(:code => 6)
342
343
  assert_equal false, result.valid?
343
- assert_equal "Customer not found", result.error_message
344
+ assert_equal ["Customer not found"], result.error_messages
344
345
 
345
346
  result = CG.get_customer(:code => 5)
346
347
  assert_equal true, result.valid?
@@ -377,7 +378,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
377
378
 
378
379
  result = CG.get_customer(:id => "bad_id")
379
380
  assert_equal false, result.valid?
380
- assert_equal "Customer not found", result.error_message
381
+ assert_equal ["Customer not found"], result.error_messages
381
382
  end
382
383
 
383
384
  should "delete a customer from cheddargetter" do
@@ -394,11 +395,11 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
394
395
 
395
396
  result = CG.delete_customer(:code => customer.customer[:code])
396
397
  assert_equal false, result.valid?
397
- assert_equal "Customer not found", result.error_message
398
+ assert_equal ["Customer not found"], result.error_messages
398
399
 
399
400
  result = CG.delete_customer(:id => customer.customer[:id])
400
401
  assert_equal false, result.valid?
401
- assert_equal "Customer not found", result.error_message
402
+ assert_equal ["Customer not found"], result.error_messages
402
403
 
403
404
  customer = CG.new_customer(paid_new_user_hash(1))
404
405
  assert_equal true, customer.valid?
@@ -408,11 +409,11 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
408
409
 
409
410
  result = CG.delete_customer(:code => customer.customer[:code])
410
411
  assert_equal false, result.valid?
411
- assert_equal "Customer not found", result.error_message
412
+ assert_equal ["Customer not found"], result.error_messages
412
413
 
413
414
  result = CG.delete_customer(:id => customer.customer[:id])
414
415
  assert_equal false, result.valid?
415
- assert_equal "Customer not found", result.error_message
416
+ assert_equal ["Customer not found"], result.error_messages
416
417
  end
417
418
 
418
419
  should "cancel a subscription" do
@@ -446,11 +447,11 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
446
447
 
447
448
  result = CG.edit_customer(:code => 1)
448
449
  assert_equal false, result.valid?
449
- assert_equal "Customer not found", result.error_message
450
+ assert_equal ["Customer not found"], result.error_messages
450
451
 
451
452
  result = CG.edit_customer(:id => "not_a_valid_id")
452
453
  assert_equal false, result.valid?
453
- assert_equal "Customer not found", result.error_message
454
+ assert_equal ["Customer not found"], result.error_messages
454
455
 
455
456
  result = CG.new_customer(free_new_user_hash(1))
456
457
  customer = result.customer
@@ -494,11 +495,11 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
494
495
 
495
496
  result = CG.edit_customer_only(:code => 1)
496
497
  assert_equal false, result.valid?
497
- assert_equal "Customer not found", result.error_message
498
+ assert_equal ["Customer not found"], result.error_messages
498
499
 
499
500
  result = CG.edit_customer_only(:id => "not_a_valid_id")
500
501
  assert_equal false, result.valid?
501
- assert_equal "Customer not found", result.error_message
502
+ assert_equal ["Customer not found"], result.error_messages
502
503
 
503
504
  result = CG.new_customer(free_new_user_hash(1))
504
505
  customer = result.customer
@@ -535,11 +536,11 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
535
536
 
536
537
  result = CG.edit_subscription(:code => 1)
537
538
  assert_equal false, result.valid?
538
- assert_equal "Customer not found", result.error_message
539
+ assert_equal ["Customer not found"], result.error_messages
539
540
 
540
541
  result = CG.edit_subscription(:id => "not_a_valid_id")
541
542
  assert_equal false, result.valid?
542
- assert_equal "Customer not found", result.error_message
543
+ assert_equal ["Customer not found"], result.error_messages
543
544
 
544
545
  result = CG.new_customer(free_new_user_hash(1))
545
546
  customer = result.customer
@@ -589,27 +590,27 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
589
590
 
590
591
  result = CG.add_item_quantity(:code => 1, :item_code => "TEST_ITEM_2")
591
592
  assert_equal false, result.valid?
592
- assert_equal "Customer not found", result.error_message
593
+ assert_equal ["Customer not found"], result.error_messages
593
594
 
594
595
  result = CG.add_item_quantity(:id => "not_a_valid_id", :item_code => "TEST_ITEM_2")
595
596
  assert_equal false, result.valid?
596
- assert_equal "Customer not found", result.error_message
597
+ assert_equal ["Customer not found"], result.error_messages
597
598
 
598
599
  result = CG.remove_item_quantity(:code => 1, :item_code => "TEST_ITEM_2")
599
600
  assert_equal false, result.valid?
600
- assert_equal "Customer not found", result.error_message
601
+ assert_equal ["Customer not found"], result.error_messages
601
602
 
602
603
  result = CG.remove_item_quantity(:id => "not_a_valid_id", :item_code => "TEST_ITEM_2")
603
604
  assert_equal false, result.valid?
604
- assert_equal "Customer not found", result.error_message
605
+ assert_equal ["Customer not found"], result.error_messages
605
606
 
606
607
  result = CG.set_item_quantity(:code => 1, :item_code => "TEST_ITEM_2")
607
608
  assert_equal false, result.valid?
608
- assert_equal "Customer not found", result.error_message
609
+ assert_equal ["Customer not found"], result.error_messages
609
610
 
610
611
  result = CG.set_item_quantity(:id => "not_a_valid_id", :item_code => "TEST_ITEM_2")
611
612
  assert_equal false, result.valid?
612
- assert_equal "Customer not found", result.error_message
613
+ assert_equal ["Customer not found"], result.error_messages
613
614
 
614
615
  result = CG.new_customer(paid_new_user_hash(1))
615
616
  assert_equal true, result.valid?
@@ -618,27 +619,27 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
618
619
 
619
620
  result = CG.add_item_quantity(:code => 1, :item_code => "NOT_AN_ITEM")
620
621
  assert_equal false, result.valid?
621
- assert_equal "Item not found (code=NOT_AN_ITEM)", result.error_message
622
+ assert_equal ["Item not found (code=NOT_AN_ITEM)"], result.error_messages
622
623
 
623
624
  result = CG.add_item_quantity(:code => 1, :item_id => "NOT_AN_ITEM")
624
625
  assert_equal false, result.valid?
625
- assert_equal "Item not found (id=NOT_AN_ITEM)", result.error_message
626
+ assert_equal ["Item not found (id=NOT_AN_ITEM)"], result.error_messages
626
627
 
627
628
  result = CG.remove_item_quantity(:code => 1, :item_code => "NOT_AN_ITEM")
628
629
  assert_equal false, result.valid?
629
- assert_equal "Item not found (code=NOT_AN_ITEM)", result.error_message
630
+ assert_equal ["Item not found (code=NOT_AN_ITEM)"], result.error_messages
630
631
 
631
632
  result = CG.remove_item_quantity(:code => 1, :item_id => "NOT_AN_ITEM")
632
633
  assert_equal false, result.valid?
633
- assert_equal "Item not found (id=NOT_AN_ITEM)", result.error_message
634
+ assert_equal ["Item not found (id=NOT_AN_ITEM)"], result.error_messages
634
635
 
635
636
  result = CG.set_item_quantity(:code => 1, :item_code => "NOT_AN_ITEM")
636
637
  assert_equal false, result.valid?
637
- assert_equal "Item not found (code=NOT_AN_ITEM)", result.error_message
638
+ assert_equal ["Item not found (code=NOT_AN_ITEM)"], result.error_messages
638
639
 
639
640
  result = CG.set_item_quantity(:code => 1, :item_id => "NOT_AN_ITEM")
640
641
  assert_equal false, result.valid?
641
- assert_equal "Item not found (id=NOT_AN_ITEM)", result.error_message
642
+ assert_equal ["Item not found (id=NOT_AN_ITEM)"], result.error_messages
642
643
 
643
644
  result = CG.add_item_quantity(:code => 1, :item_code => "TEST_ITEM_2")
644
645
  assert_equal true, result.valid?
@@ -662,7 +663,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
662
663
 
663
664
  result = CG.set_item_quantity({:code => 1, :item_code => "TEST_ITEM_2"})
664
665
  assert_equal false, result.valid?
665
- assert_equal "A value is required: quantity", result.error_message
666
+ assert_equal ["A value is required: quantity"], result.error_messages
666
667
 
667
668
  result = CG.set_item_quantity({:code => 1, :item_code => "TEST_ITEM_2"}, { :quantity => 6 })
668
669
  assert_equal true, result.valid?
@@ -676,7 +677,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
676
677
 
677
678
  result = CG.set_item_quantity({:code => 1, :item_code => "TEST_ITEM_2"}, { :quantity => 15 })
678
679
  assert_equal false, result.valid?
679
- assert_equal "'15' is not less than or equal to '10': quantity", result.error_message
680
+ assert_equal ["'15' is not less than or equal to '10': quantity"], result.error_messages
680
681
 
681
682
  result = CG.set_item_quantity({:code => 1, :item_code => "TEST_ITEM_1"}, { :quantity => 15 })
682
683
  assert_equal 15, result.customer_item("TEST_ITEM_1")[:quantity]
@@ -694,26 +695,26 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
694
695
 
695
696
  result = CG.add_charge(:code => 1)
696
697
  assert_equal false, result.valid?
697
- assert_equal "Customer not found", result.error_message
698
+ assert_equal ["Customer not found"], result.error_messages
698
699
 
699
700
  result = CG.add_charge(:id => "not_a_valid_id")
700
701
  assert_equal false, result.valid?
701
- assert_equal "Customer not found", result.error_message
702
+ assert_equal ["Customer not found"], result.error_messages
702
703
 
703
704
  result = CG.new_customer(paid_new_user_hash(1))
704
705
  assert_equal true, result.valid?
705
706
 
706
707
  result = CG.add_charge(:code => 1)
707
708
  assert_equal false, result.valid?
708
- assert_equal "A value is required: chargeCode", result.error_message
709
+ assert_equal ["A value is required: chargeCode"], result.error_messages
709
710
 
710
711
  result = CG.add_charge({:code => 1}, { :chargeCode => "MY_CHARGE" })
711
712
  assert_equal false, result.valid?
712
- assert_equal "A value is required: quantity", result.error_message
713
+ assert_equal ["A value is required: quantity"], result.error_messages
713
714
 
714
715
  result = CG.add_charge({:code => 1}, { :chargeCode => "MY_CHARGE", :quantity => 1 })
715
716
  assert_equal false, result.valid?
716
- assert_equal "A value is required: eachAmount", result.error_message
717
+ assert_equal ["A value is required: eachAmount"], result.error_messages
717
718
 
718
719
  result = CG.add_charge({:code => 1}, { :chargeCode => "MY_CHARGE", :quantity => 1, :eachAmount => 2 })
719
720
  assert_equal true, result.valid?
@@ -750,7 +751,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
750
751
  assert_equal 2, result.customer_subscriptions.count
751
752
  assert_equal "Test Plan 2", result.customer_plan[:name]
752
753
  end
753
-
754
+
754
755
  should "test customer get filtering" do
755
756
  result = CG.delete_all_customers
756
757
  assert_equal true, result.valid?
@@ -800,7 +801,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
800
801
 
801
802
  result = CG.get_customers(:planCode => "TEST_PLAN_1")
802
803
  assert_equal false, result.valid?
803
- assert_equal "No customers found.", result.error_message
804
+ assert_equal ["No customers found."], result.error_messages
804
805
 
805
806
  result = CG.get_customers(:planCode => ["TEST_PLAN_1", "TEST_PLAN_2", "FREE_PLAN_TEST"])
806
807
  assert_equal true, result.valid?
@@ -828,7 +829,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
828
829
 
829
830
  result = CG.get_customers(:search => "NotFirst")
830
831
  assert_equal false, result.valid?
831
- assert_equal "No customers found.", result.error_message
832
+ assert_equal ["No customers found."], result.error_messages
832
833
  end
833
834
 
834
835
  should "get 100% code coverage :)" do
@@ -848,5 +849,20 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
848
849
  assert_equal "string", data[:test]
849
850
  CheddarGetter::Response::KEY_TO_DATA_TYPE.delete(:test)
850
851
  end
852
+
853
+ should "test embedded errors" do
854
+ result = CG.delete_all_customers
855
+ assert_equal true, result.valid?
856
+
857
+ result = CG.new_customer(paid_new_user_hash(1))
858
+ assert_equal true, result.valid?
859
+
860
+ new_sub = paid_new_user_hash(1, "05003")[:subscription]
861
+ new_sub[:planCode] = "TEST_PLAN_1"
862
+
863
+ result = CG.edit_subscription({:code => 1}, new_sub)
864
+ assert_equal false, result.valid?
865
+ assert_equal ["Credit card type is not accepted"], result.error_messages
866
+ end
851
867
 
852
868
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheddargetter_client_ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Expected Behavior
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-09 00:00:00 -05:00
18
+ date: 2010-12-10 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency