active_shipping 1.14.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -25
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +2 -0
- data/README.md +2 -8
- data/active_shipping.gemspec +9 -3
- data/gemfiles/activesupport42.gemfile +0 -1
- data/lib/active_shipping.rb +1 -1
- data/lib/active_shipping/carrier.rb +2 -4
- data/lib/active_shipping/carriers/australia_post.rb +2 -4
- data/lib/active_shipping/carriers/canada_post.rb +1 -1
- data/lib/active_shipping/carriers/canada_post_pws.rb +33 -37
- data/lib/active_shipping/carriers/correios.rb +0 -2
- data/lib/active_shipping/carriers/new_zealand_post.rb +0 -2
- data/lib/active_shipping/carriers/ups.rb +0 -2
- data/lib/active_shipping/carriers/usps.rb +1 -3
- data/lib/active_shipping/external_return_label_request.rb +0 -4
- data/lib/active_shipping/location.rb +65 -52
- data/lib/active_shipping/package.rb +17 -21
- data/lib/active_shipping/package_item.rb +8 -20
- data/lib/active_shipping/rate_estimate.rb +1 -1
- data/lib/active_shipping/version.rb +1 -1
- data/test/fixtures/xml/canadapost/example_request.xml +3 -3
- data/test/helpers/holiday_helpers.rb +54 -0
- data/test/remote/australia_post_test.rb +1 -1
- data/test/remote/canada_post_pws_platform_test.rb +1 -3
- data/test/remote/canada_post_pws_test.rb +1 -1
- data/test/remote/canada_post_test.rb +1 -1
- data/test/remote/correios_test.rb +1 -2
- data/test/remote/fedex_test.rb +8 -8
- data/test/remote/kunaki_test.rb +1 -1
- data/test/remote/new_zealand_post_test.rb +1 -1
- data/test/remote/shipwire_test.rb +1 -1
- data/test/remote/stamps_test.rb +7 -7
- data/test/remote/ups_surepost_test.rb +1 -1
- data/test/remote/ups_test.rb +13 -11
- data/test/remote/usps_returns_test.rb +1 -1
- data/test/remote/usps_test.rb +5 -5
- data/test/test_helper.rb +16 -6
- data/test/unit/carrier_test.rb +25 -25
- data/test/unit/carriers/australia_post_test.rb +5 -5
- data/test/unit/carriers/benchmark_test.rb +1 -1
- data/test/unit/carriers/canada_post_pws_rating_test.rb +1 -15
- data/test/unit/carriers/canada_post_pws_register_test.rb +1 -15
- data/test/unit/carriers/canada_post_pws_shipping_test.rb +1 -13
- data/test/unit/carriers/canada_post_pws_test.rb +4 -4
- data/test/unit/carriers/canada_post_pws_tracking_test.rb +1 -1
- data/test/unit/carriers/canada_post_test.rb +9 -9
- data/test/unit/carriers/correios_test.rb +1 -2
- data/test/unit/carriers/fedex_test.rb +5 -5
- data/test/unit/carriers/kunaki_test.rb +1 -1
- data/test/unit/carriers/new_zealand_post_test.rb +9 -10
- data/test/unit/carriers/shipwire_test.rb +1 -1
- data/test/unit/carriers/stamps_test.rb +1 -1
- data/test/unit/carriers/ups_test.rb +1 -1
- data/test/unit/carriers/usps_returns_test.rb +1 -1
- data/test/unit/carriers/usps_test.rb +1 -1
- data/test/unit/carriers_test.rb +4 -5
- data/test/unit/external_return_label_request_test.rb +129 -83
- data/test/unit/location_test.rb +187 -91
- data/test/unit/package_item_test.rb +42 -47
- data/test/unit/package_test.rb +76 -75
- data/test/unit/rate_estimate_test.rb +16 -20
- data/test/unit/response_test.rb +28 -9
- data/test/unit/shipment_event_test.rb +1 -1
- data/test/unit/shipment_packer_test.rb +31 -31
- data/test/unit/tracking_response_test.rb +1 -1
- metadata +71 -23
- data/gemfiles/activesupport32.gemfile +0 -7
- data/gemfiles/activesupport32_nokogiri_17.gemfile +0 -7
- data/gemfiles/activesupport40.gemfile +0 -6
- data/gemfiles/activesupport40_nokogiri_17.gemfile +0 -6
- data/gemfiles/activesupport41.gemfile +0 -6
- data/gemfiles/activesupport41_nokogiri_17.gemfile +0 -6
- data/gemfiles/activesupport42_nokogiri_17.gemfile +0 -6
- data/test/fixtures/xml/canadapost_pws/merchant_details_response_no_contract_number.xml +0 -7
- data/test/fixtures/xml/canadapost_pws/service_options_response_priority_worldwide.xml +0 -41
data/test/unit/package_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class PackageTest <
|
4
|
-
|
3
|
+
class PackageTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
5
|
@weight = 100
|
6
6
|
@dimensions = [5, 6, 7]
|
7
7
|
@value = 1299
|
@@ -30,15 +30,16 @@ class PackageTest < Minitest::Test
|
|
30
30
|
@package = Package.new(@weight, @dimensions, @options)
|
31
31
|
@imperial_package = Package.new(@weight, @dimensions, @options.merge(units: :imperial, dim_units: :imperial, weight_units: :imperial))
|
32
32
|
|
33
|
-
@mass = ::
|
33
|
+
@mass = Measured::Weight.new(@weight, :grams)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
test "#initialize package from mass" do
|
37
|
+
ten_pounds = Measured::Weight.new(10, :pounds)
|
38
|
+
package = Package.new(ten_pounds, [])
|
39
|
+
assert_equal ten_pounds, package.weight
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
+
test "#initialize with defaults" do
|
42
43
|
assert_equal @value, @package.value
|
43
44
|
assert_equal @currency, @package.currency
|
44
45
|
assert_equal @cylinder, @package.cylinder?
|
@@ -48,61 +49,61 @@ class PackageTest < Minitest::Test
|
|
48
49
|
assert_equal @gift, @package.gift?
|
49
50
|
end
|
50
51
|
|
51
|
-
|
52
|
+
test "#initialize with currency cents" do
|
52
53
|
@package = Package.new(@weight, @dimensions, value: money)
|
53
54
|
assert_equal @currency, @package.currency
|
54
55
|
assert_equal @value, @package.value
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
+
test "#initialize sorts the passed in dimensions" do
|
58
59
|
@package = Package.new(@weight, [9, 8, 7], @options)
|
59
60
|
|
60
61
|
assert_equal [7, 8, 9], @package.centimetres
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
+
test "#initialize sets default dimensions if blank" do
|
64
65
|
@package = Package.new(@weight, [], @options)
|
65
66
|
|
66
67
|
assert_equal [0, 0, 0], @package.centimetres
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
+
test "#initialize increases dimension size to three elements in the array and pads" do
|
70
71
|
@package = Package.new(@weight, [2], @options)
|
71
72
|
|
72
73
|
assert_equal [2, 2, 2], @package.centimetres
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
+
test "#initialize default units" do
|
76
77
|
assert_equal @dimensions, @package.centimetres
|
77
78
|
assert_equal @weight, @package.grams
|
78
79
|
end
|
79
80
|
|
80
|
-
|
81
|
+
test "#initialize units" do
|
81
82
|
assert_equal @dimensions, @imperial_package.inches
|
82
83
|
end
|
83
84
|
|
84
|
-
|
85
|
+
test "#initialize weight_units" do
|
85
86
|
@package = Package.new(@weight, @dimensions, @options.merge(weight_units: :imperial))
|
86
87
|
|
87
88
|
assert_equal @weight, @package.ounces
|
88
89
|
end
|
89
90
|
|
90
|
-
|
91
|
+
test "#unpackaged?" do
|
91
92
|
assert_predicate Package.new(@weight, @dimensions, unpackaged: true), :unpackaged?
|
92
93
|
refute_predicate Package.new(@weight, @dimensions, unpackaged: false), :unpackaged?
|
93
94
|
end
|
94
95
|
|
95
|
-
|
96
|
+
test "#oversized?" do
|
96
97
|
assert_predicate Package.new(@weight, @dimensions, oversized: true), :oversized?
|
97
98
|
refute_predicate Package.new(@weight, @dimensions, oversized: false), :oversized?
|
98
99
|
end
|
99
100
|
|
100
|
-
|
101
|
+
test "#gift?" do
|
101
102
|
assert_predicate Package.new(@weight, @dimensions, gift: true), :gift?
|
102
103
|
refute_predicate Package.new(@weight, @dimensions, gift: false), :gift?
|
103
104
|
end
|
104
105
|
|
105
|
-
|
106
|
+
test "#cylinder? and #tube? check both values" do
|
106
107
|
@package = Package.new(@weight, @dimensions, cylinder: false, tube: false)
|
107
108
|
refute_predicate @package, :cylinder?
|
108
109
|
refute_predicate @package, :tube?
|
@@ -120,28 +121,28 @@ class PackageTest < Minitest::Test
|
|
120
121
|
assert_predicate @package, :tube?
|
121
122
|
end
|
122
123
|
|
123
|
-
|
124
|
+
test "#inches performs lookup with a numerical index" do
|
124
125
|
assert_equal @dimensions[0], @imperial_package.inches(0)
|
125
126
|
assert_equal @dimensions[1], @imperial_package.inches(1)
|
126
127
|
assert_equal @dimensions[2], @imperial_package.inches(2)
|
127
128
|
assert_nil @imperial_package.inches(3)
|
128
129
|
end
|
129
130
|
|
130
|
-
|
131
|
+
test "#inches for dimension x" do
|
131
132
|
assert_equal @dimensions[2], @imperial_package.inches(:x)
|
132
133
|
assert_equal @dimensions[2], @imperial_package.inches(:max)
|
133
134
|
assert_equal @dimensions[2], @imperial_package.inches(:length)
|
134
135
|
assert_equal @dimensions[2], @imperial_package.inches(:long)
|
135
136
|
end
|
136
137
|
|
137
|
-
|
138
|
+
test "#inches for dimension y" do
|
138
139
|
assert_equal @dimensions[1], @imperial_package.inches(:y)
|
139
140
|
assert_equal @dimensions[1], @imperial_package.inches(:mid)
|
140
141
|
assert_equal @dimensions[1], @imperial_package.inches(:width)
|
141
142
|
assert_equal @dimensions[1], @imperial_package.inches(:wide)
|
142
143
|
end
|
143
144
|
|
144
|
-
|
145
|
+
test "#inches for dimension z" do
|
145
146
|
assert_equal @dimensions[0], @imperial_package.inches(:z)
|
146
147
|
assert_equal @dimensions[0], @imperial_package.inches(:min)
|
147
148
|
assert_equal @dimensions[0], @imperial_package.inches(:height)
|
@@ -150,7 +151,7 @@ class PackageTest < Minitest::Test
|
|
150
151
|
assert_equal @dimensions[0], @imperial_package.inches(:deep)
|
151
152
|
end
|
152
153
|
|
153
|
-
|
154
|
+
test "#inches for girth of a cylinder" do
|
154
155
|
@imperial_package = Package.new(@weight, @dimensions, @options.merge(cylinder: true, units: :imperial, dim_units: :imperial))
|
155
156
|
|
156
157
|
assert_predicate @imperial_package, :cylinder?
|
@@ -160,60 +161,60 @@ class PackageTest < Minitest::Test
|
|
160
161
|
|
161
162
|
end
|
162
163
|
|
163
|
-
|
164
|
+
test "#inches for girth of a non cylinder" do
|
164
165
|
refute_predicate @imperial_package, :cylinder?
|
165
166
|
assert_in_delta 22, @imperial_package.inches(:girth), 1
|
166
167
|
assert_in_delta 22, @imperial_package.inches(:around), 1
|
167
168
|
assert_in_delta 22, @imperial_package.inches(:circumference), 1
|
168
169
|
end
|
169
170
|
|
170
|
-
|
171
|
+
test "#inches for the volume of a cylinder" do
|
171
172
|
@imperial_package = Package.new(@weight, @dimensions, @options.merge(cylinder: true, units: :imperial, dim_units: :imperial))
|
172
173
|
|
173
174
|
assert_predicate @imperial_package, :cylinder?
|
174
175
|
assert_in_delta 522.4, @imperial_package.inches(:volume), 1
|
175
176
|
end
|
176
177
|
|
177
|
-
|
178
|
+
test "#inches for volume" do
|
178
179
|
refute_predicate @imperial_package, :cylinder?
|
179
180
|
assert_equal 210, @imperial_package.inches(:volume)
|
180
181
|
end
|
181
182
|
|
182
|
-
|
183
|
+
test "#inches for box_volume" do
|
183
184
|
assert_equal 210, @imperial_package.inches(:box_volume)
|
184
185
|
end
|
185
186
|
|
186
|
-
|
187
|
+
test "#inches of an unknown value" do
|
187
188
|
assert_nil @imperial_package.inches(:unknown)
|
188
189
|
end
|
189
190
|
|
190
|
-
|
191
|
+
test "#inches alias to #in" do
|
191
192
|
assert_equal @dimensions, @imperial_package.inches
|
192
193
|
assert_equal @dimensions, @imperial_package.in
|
193
194
|
end
|
194
195
|
|
195
|
-
|
196
|
+
test "#centimetres performs lookup with a numerical index" do
|
196
197
|
assert_equal @dimensions[0], @package.centimetres(0)
|
197
198
|
assert_equal @dimensions[1], @package.centimetres(1)
|
198
199
|
assert_equal @dimensions[2], @package.centimetres(2)
|
199
200
|
assert_nil @package.centimetres(3)
|
200
201
|
end
|
201
202
|
|
202
|
-
|
203
|
+
test "#centimetres for dimension x" do
|
203
204
|
assert_equal @dimensions[2], @package.centimetres(:x)
|
204
205
|
assert_equal @dimensions[2], @package.centimetres(:max)
|
205
206
|
assert_equal @dimensions[2], @package.centimetres(:length)
|
206
207
|
assert_equal @dimensions[2], @package.centimetres(:long)
|
207
208
|
end
|
208
209
|
|
209
|
-
|
210
|
+
test "#centimetres for dimension y" do
|
210
211
|
assert_equal @dimensions[1], @package.centimetres(:y)
|
211
212
|
assert_equal @dimensions[1], @package.centimetres(:mid)
|
212
213
|
assert_equal @dimensions[1], @package.centimetres(:width)
|
213
214
|
assert_equal @dimensions[1], @package.centimetres(:wide)
|
214
215
|
end
|
215
216
|
|
216
|
-
|
217
|
+
test "#centimetres for dimension z" do
|
217
218
|
assert_equal @dimensions[0], @package.centimetres(:z)
|
218
219
|
assert_equal @dimensions[0], @package.centimetres(:min)
|
219
220
|
assert_equal @dimensions[0], @package.centimetres(:height)
|
@@ -222,7 +223,7 @@ class PackageTest < Minitest::Test
|
|
222
223
|
assert_equal @dimensions[0], @package.centimetres(:deep)
|
223
224
|
end
|
224
225
|
|
225
|
-
|
226
|
+
test "#centimetres for girth of a cylinder" do
|
226
227
|
@package = Package.new(@weight, @dimensions, @options.merge(cylinder: true, units: :metric, dim_units: :metric))
|
227
228
|
|
228
229
|
assert_predicate @package, :cylinder?
|
@@ -232,158 +233,158 @@ class PackageTest < Minitest::Test
|
|
232
233
|
|
233
234
|
end
|
234
235
|
|
235
|
-
|
236
|
+
test "#centimetres for girth of a non-cylinder" do
|
236
237
|
refute_predicate @package, :cylinder?
|
237
238
|
assert_in_delta 22, @package.centimetres(:girth), 1
|
238
239
|
assert_in_delta 22, @package.centimetres(:around), 1
|
239
240
|
assert_in_delta 22, @package.centimetres(:circumference), 1
|
240
241
|
end
|
241
242
|
|
242
|
-
|
243
|
+
test "#centimetres for the volume of a cylinder" do
|
243
244
|
@package = Package.new(@weight, @dimensions, @options.merge(cylinder: true, units: :metric, dim_units: :metric))
|
244
245
|
|
245
246
|
assert_predicate @package, :cylinder?
|
246
247
|
assert_in_delta 522.4, @package.centimetres(:volume), 1
|
247
248
|
end
|
248
249
|
|
249
|
-
|
250
|
+
test "#centimetres for volume" do
|
250
251
|
refute_predicate @package, :cylinder?
|
251
252
|
assert_equal 210, @package.centimetres(:volume)
|
252
253
|
end
|
253
254
|
|
254
|
-
|
255
|
+
test "#centimetres for box_volume" do
|
255
256
|
assert_equal 210, @package.centimetres(:box_volume)
|
256
257
|
end
|
257
258
|
|
258
|
-
|
259
|
+
test "#centimetres of an unknown value" do
|
259
260
|
assert_nil @package.centimetres(:unknown)
|
260
261
|
end
|
261
262
|
|
262
|
-
|
263
|
+
test "#centimetres alias to #cm" do
|
263
264
|
assert_equal @dimensions, @package.centimetres
|
264
265
|
assert_equal @dimensions, @package.cm
|
265
266
|
end
|
266
267
|
|
267
|
-
|
268
|
+
test "#weight" do
|
268
269
|
assert_equal @mass, @package.weight
|
269
|
-
assert_instance_of ::
|
270
|
+
assert_instance_of Measured::Weight, @package.weight
|
270
271
|
end
|
271
272
|
|
272
|
-
|
273
|
+
test "#weight for actual" do
|
273
274
|
assert_equal @mass, @package.weight(type: :actual)
|
274
|
-
assert_instance_of ::
|
275
|
+
assert_instance_of Measured::Weight, @package.weight(type: :actual)
|
275
276
|
end
|
276
277
|
|
277
|
-
|
278
|
-
assert_equal ::
|
278
|
+
test "#weight volumetric" do
|
279
|
+
assert_equal Measured::Weight.new(35, :grams), @package.weight(type: :volumetric)
|
279
280
|
end
|
280
281
|
|
281
|
-
|
282
|
-
assert_equal ::
|
282
|
+
test "#weight dimensional" do
|
283
|
+
assert_equal Measured::Weight.new(35, :grams), @package.weight(type: :dimensional)
|
283
284
|
end
|
284
285
|
|
285
|
-
|
286
|
-
assert_equal ::
|
286
|
+
test "#weight billable is the max of weight and volumetric" do
|
287
|
+
assert_equal Measured::Weight.new(100, :grams), @package.weight(type: :billable)
|
287
288
|
|
288
289
|
@package = Package.new(500, [1, 1, 1], @options)
|
289
|
-
assert_equal ::
|
290
|
+
assert_equal Measured::Weight.new(500, :grams), @package.weight(type: :billable)
|
290
291
|
end
|
291
292
|
|
292
|
-
|
293
|
+
test "#grams value" do
|
293
294
|
assert_equal 100, @package.grams
|
294
295
|
end
|
295
296
|
|
296
|
-
|
297
|
+
test "#grams accepts options with type" do
|
297
298
|
assert_in_delta 35, @package.grams(type: :volumetric), 1
|
298
299
|
end
|
299
300
|
|
300
|
-
|
301
|
+
test "#grams converts to another unit from another system" do
|
301
302
|
@package = Package.new(@weight, @dimensions, weight_units: :imperial)
|
302
303
|
|
303
304
|
assert_in_delta 2834.9, @package.grams, 1
|
304
305
|
end
|
305
306
|
|
306
|
-
|
307
|
+
test "#grams alias to #g" do
|
307
308
|
assert_equal @package.grams, @package.g
|
308
309
|
end
|
309
310
|
|
310
|
-
|
311
|
+
test "#ounces value" do
|
311
312
|
assert_equal 100, @imperial_package.ounces
|
312
313
|
end
|
313
314
|
|
314
|
-
|
315
|
+
test "#ounces accepts options with type" do
|
315
316
|
assert_in_delta 20.2, @imperial_package.ounces(type: :volumetric), 1
|
316
317
|
end
|
317
318
|
|
318
|
-
|
319
|
+
test "#ounces converts to another unit from another system" do
|
319
320
|
assert_in_delta 3.5, @package.ounces, 1
|
320
321
|
end
|
321
322
|
|
322
|
-
|
323
|
+
test "#ounces alias to #oz" do
|
323
324
|
assert_equal @imperial_package.ounces, @imperial_package.oz
|
324
325
|
end
|
325
326
|
|
326
|
-
|
327
|
+
test "#pounds value" do
|
327
328
|
assert_equal 6.25, @imperial_package.pounds
|
328
329
|
end
|
329
330
|
|
330
|
-
|
331
|
+
test "#pounds accepts options with type" do
|
331
332
|
assert_in_delta 0.07, @package.pounds(type: :volumetric), 0.01
|
332
333
|
end
|
333
334
|
|
334
|
-
|
335
|
+
test "#pounds converts to another unit from another system" do
|
335
336
|
assert_in_delta 0.22, @package.pounds, 0.01
|
336
337
|
end
|
337
338
|
|
338
|
-
|
339
|
+
test "#pounds alias to #lb" do
|
339
340
|
assert_equal @package.pounds, @package.lb
|
340
341
|
end
|
341
342
|
|
342
|
-
|
343
|
+
test "#pounds alias to #lbs" do
|
343
344
|
assert_equal @package.pounds, @package.lbs
|
344
345
|
end
|
345
346
|
|
346
|
-
|
347
|
+
test "#kilograms value" do
|
347
348
|
assert_equal 0.1, @package.kilograms
|
348
349
|
end
|
349
350
|
|
350
|
-
|
351
|
+
test "#kilograms accepts options with type" do
|
351
352
|
assert_equal 0.035, @package.kilograms(type: :volumetric)
|
352
353
|
end
|
353
354
|
|
354
|
-
|
355
|
+
test "#kilograms converts to another unit from another system" do
|
355
356
|
assert_in_delta 2.8, @imperial_package.kilograms, 1
|
356
357
|
end
|
357
358
|
|
358
|
-
|
359
|
+
test "#kilograms alias to #kg" do
|
359
360
|
assert_equal 0.1, @package.kg
|
360
361
|
end
|
361
362
|
|
362
|
-
|
363
|
+
test "#kilograms alias to #kgs" do
|
363
364
|
assert_equal @package.kilograms, @package.kgs
|
364
365
|
end
|
365
366
|
|
366
|
-
|
367
|
+
test ".cents_from nil" do
|
367
368
|
assert_nil Package.cents_from(nil)
|
368
369
|
end
|
369
370
|
|
370
|
-
|
371
|
+
test ".cents_from cents on a money object" do
|
371
372
|
assert_equal @value, Package.cents_from(money)
|
372
373
|
end
|
373
374
|
|
374
|
-
|
375
|
+
test ".cents_from float" do
|
375
376
|
assert_equal 120, Package.cents_from(1.2)
|
376
377
|
end
|
377
378
|
|
378
|
-
|
379
|
+
test ".cents_from string" do
|
379
380
|
assert_equal 120, Package.cents_from("1.20")
|
380
381
|
end
|
381
382
|
|
382
|
-
|
383
|
+
test ".cents_from integer" do
|
383
384
|
assert_equal 12, Package.cents_from(12)
|
384
385
|
end
|
385
386
|
|
386
|
-
|
387
|
+
test ".cents_from an unhandled object" do
|
387
388
|
exception = assert_raises NoMethodError do
|
388
389
|
Package.cents_from(Object.new)
|
389
390
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class RateEstimateTest <
|
4
|
-
|
3
|
+
class RateEstimateTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
5
|
@origin = {address1: "61A York St", city: "Ottawa", province: "ON", country: "Canada", postal_code: "K1N 5T2"}
|
6
6
|
@destination = {city: "Beverly Hills", state: "CA", country: "United States", postal_code: "90210"}
|
7
7
|
@line_items = [Package.new(500, [2, 3, 4], description: "a box full of stuff", value: 2500)]
|
@@ -11,11 +11,7 @@ class RateEstimateTest < Minitest::Test
|
|
11
11
|
@rate_estimate = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
assert_nil @rate_estimate.send(:date_for, nil)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_phone_required
|
14
|
+
test "#initialize accepts phone_required option field" do
|
19
15
|
est = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(phone_required: true))
|
20
16
|
assert_equal true, est.phone_required
|
21
17
|
|
@@ -26,44 +22,40 @@ class RateEstimateTest < Minitest::Test
|
|
26
22
|
assert_equal false, est.phone_required
|
27
23
|
end
|
28
24
|
|
29
|
-
|
25
|
+
test "#initialize accepts description option field" do
|
30
26
|
rate_estimate = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(description: "It's free!"))
|
31
27
|
assert_equal "It's free!", rate_estimate.description
|
32
28
|
end
|
33
29
|
|
34
|
-
|
35
|
-
assert_nil @rate_estimate.send(:date_for, "Up to 2 weeks") if RUBY_VERSION.include?('1.9')
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_rate_estimate_converts_noniso_to_iso
|
30
|
+
test "#initialize converts noniso currency to iso" do
|
39
31
|
rate_estimate = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(currency: 'UKL'))
|
40
32
|
assert_equal 'GBP', rate_estimate.currency
|
41
33
|
end
|
42
34
|
|
43
|
-
|
35
|
+
test "#initialize raises if invalid currency code" do
|
44
36
|
assert_raises(ActiveUtils::InvalidCurrencyCodeError) do
|
45
37
|
RateEstimate.new(nil, nil, nil, nil, currency: 'FAKE')
|
46
38
|
end
|
47
39
|
end
|
48
40
|
|
49
|
-
|
41
|
+
test "#initialize accepts estimate_reference option field" do
|
50
42
|
est = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(estimate_reference: "somefakeref"))
|
51
43
|
|
52
44
|
assert_equal "somefakeref", est.estimate_reference
|
53
45
|
end
|
54
46
|
|
55
|
-
|
47
|
+
test "#initialize accepts compare_price option field" do
|
56
48
|
est = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(compare_price: 10.0))
|
57
49
|
assert_equal 1000, est.compare_price
|
58
50
|
end
|
59
51
|
|
60
|
-
|
52
|
+
test "#initialize accepts delivery_category option field" do
|
61
53
|
est = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(delivery_category: "local_delivery"))
|
62
54
|
|
63
55
|
assert_equal "local_delivery", est.delivery_category
|
64
56
|
end
|
65
57
|
|
66
|
-
|
58
|
+
test "#initialize accepts charge_items option field" do
|
67
59
|
charge_items = [
|
68
60
|
{
|
69
61
|
group: "base_charge",
|
@@ -85,13 +77,17 @@ class RateEstimateTest < Minitest::Test
|
|
85
77
|
assert_equal charge_items, est.charge_items
|
86
78
|
end
|
87
79
|
|
88
|
-
|
80
|
+
test "delivery_date is pulled from the later date of the delivery_range" do
|
89
81
|
assert_equal [DateTime.parse("Fri 01 Jul 2016"), DateTime.parse("Sun 03 Jul 2016")], @rate_estimate.delivery_range
|
90
82
|
assert_equal DateTime.parse("Sun 03 Jul 2016"), @rate_estimate.delivery_date
|
91
83
|
end
|
92
84
|
|
93
|
-
|
85
|
+
test "#initialize accepts messages option field" do
|
94
86
|
rate = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(messages: ["warning"]))
|
95
87
|
assert_equal ["warning"], rate.messages
|
96
88
|
end
|
89
|
+
|
90
|
+
test "#date_for returns nil when given nil string" do
|
91
|
+
assert_nil @rate_estimate.send(:date_for, nil)
|
92
|
+
end
|
97
93
|
end
|