active_shipping 1.8.6 → 1.9.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 +4 -4
- data/.travis.yml +12 -7
- data/CONTRIBUTING.md +14 -38
- data/MIT-LICENSE +2 -2
- data/README.md +61 -24
- data/Rakefile +3 -0
- data/active_shipping.gemspec +25 -26
- data/{Gemfile.activesupport32 → gemfiles/activesupport32.gemfile} +2 -1
- data/{Gemfile.activesupport40 → gemfiles/activesupport40.gemfile} +2 -1
- data/{Gemfile.activesupport41 → gemfiles/activesupport41.gemfile} +2 -1
- data/{Gemfile.activesupport42 → gemfiles/activesupport42.gemfile} +2 -1
- data/{Gemfile.activesupport50 → gemfiles/activesupport50.gemfile} +2 -1
- data/gemfiles/activesupport_master.gemfile +5 -0
- data/lib/active_shipping.rb +1 -23
- data/lib/active_shipping/carrier.rb +3 -3
- data/lib/active_shipping/carriers/canada_post_pws.rb +8 -8
- data/lib/active_shipping/carriers/ups.rb +19 -0
- data/lib/active_shipping/package.rb +3 -75
- data/lib/active_shipping/package_item.rb +72 -0
- data/lib/active_shipping/version.rb +1 -1
- data/test/remote/fedex_test.rb +5 -5
- data/test/remote/ups_test.rb +2 -1
- data/test/test_helper.rb +1 -0
- data/test/unit/carriers/canada_post_pws_tracking_test.rb +2 -2
- data/test/unit/carriers/fedex_test.rb +8 -8
- data/test/unit/carriers/kunaki_test.rb +1 -1
- data/test/unit/carriers/stamps_test.rb +1 -1
- data/test/unit/carriers/usps_test.rb +2 -2
- data/test/unit/external_return_label_request_test.rb +17 -17
- data/test/unit/package_item_test.rb +237 -0
- data/test/unit/package_test.rb +393 -58
- metadata +13 -12
@@ -257,6 +257,25 @@ module ActiveShipping
|
|
257
257
|
xml_builder.to_xml
|
258
258
|
end
|
259
259
|
|
260
|
+
# Builds an XML node to request UPS shipping rates for the given packages
|
261
|
+
#
|
262
|
+
# @param origin [ActiveShipping::Location] Where the shipment will originate from
|
263
|
+
# @param destination [ActiveShipping::Location] Where the package will go
|
264
|
+
# @param packages [Array<ActiveShipping::Package>] The list of packages that will
|
265
|
+
# be in the shipment
|
266
|
+
# @options options [Hash] rate-specific options
|
267
|
+
# @return [ActiveShipping::RateResponse] The response from the UPS, which
|
268
|
+
# includes 0 or more rate estimates for different shipping products
|
269
|
+
#
|
270
|
+
# options:
|
271
|
+
# * service: name of the service
|
272
|
+
# * pickup_type: symbol for PICKUP_CODES
|
273
|
+
# * customer_classification: symbol for CUSTOMER_CLASSIFICATIONS
|
274
|
+
# * shipper: who is sending the package and where it should be returned
|
275
|
+
# if it is undeliverable.
|
276
|
+
# * imperial: if truthy, measurements will use the metric system
|
277
|
+
# * negotiated_rates: if truthy, negotiated rates will be requested from
|
278
|
+
# UPS. Only valid if shipper account has negotiated rates.
|
260
279
|
def build_rate_request(origin, destination, packages, options = {})
|
261
280
|
xml_builder = Nokogiri::XML::Builder.new do |xml|
|
262
281
|
xml.RatingServiceSelectionRequest do
|
@@ -1,78 +1,4 @@
|
|
1
1
|
module ActiveShipping #:nodoc:
|
2
|
-
# A package item is a unique item(s) that is physically in a package.
|
3
|
-
# A single package can have many items. This is only required
|
4
|
-
# for shipping methods (label creation) right now.
|
5
|
-
class PackageItem
|
6
|
-
include Quantified
|
7
|
-
|
8
|
-
attr_reader :sku, :hs_code, :value, :name, :weight, :quantity, :options
|
9
|
-
|
10
|
-
def initialize(name, grams_or_ounces, value, quantity, options = {})
|
11
|
-
@name = name
|
12
|
-
|
13
|
-
imperial = (options[:units] == :imperial) ||
|
14
|
-
(grams_or_ounces.respond_to?(:unit) && m.unit.to_sym == :imperial)
|
15
|
-
|
16
|
-
@unit_system = imperial ? :imperial : :metric
|
17
|
-
|
18
|
-
@weight = attribute_from_metric_or_imperial(grams_or_ounces, Mass, :grams, :ounces)
|
19
|
-
|
20
|
-
@value = Package.cents_from(value)
|
21
|
-
@quantity = quantity > 0 ? quantity : 1
|
22
|
-
|
23
|
-
@sku = options[:sku]
|
24
|
-
@hs_code = options[:hs_code]
|
25
|
-
@options = options
|
26
|
-
end
|
27
|
-
|
28
|
-
def weight(options = {})
|
29
|
-
case options[:type]
|
30
|
-
when nil, :actual
|
31
|
-
@weight
|
32
|
-
when :volumetric, :dimensional
|
33
|
-
@volumetric_weight ||= begin
|
34
|
-
m = Mass.new((centimetres(:box_volume) / 6.0), :grams)
|
35
|
-
@unit_system == :imperial ? m.in_ounces : m
|
36
|
-
end
|
37
|
-
when :billable
|
38
|
-
[weight, weight(:type => :volumetric)].max
|
39
|
-
end
|
40
|
-
end
|
41
|
-
alias_method :mass, :weight
|
42
|
-
|
43
|
-
def ounces(options = {})
|
44
|
-
weight(options).in_ounces.amount
|
45
|
-
end
|
46
|
-
alias_method :oz, :ounces
|
47
|
-
|
48
|
-
def grams(options = {})
|
49
|
-
weight(options).in_grams.amount
|
50
|
-
end
|
51
|
-
alias_method :g, :grams
|
52
|
-
|
53
|
-
def pounds(options = {})
|
54
|
-
weight(options).in_pounds.amount
|
55
|
-
end
|
56
|
-
alias_method :lb, :pounds
|
57
|
-
alias_method :lbs, :pounds
|
58
|
-
|
59
|
-
def kilograms(options = {})
|
60
|
-
weight(options).in_kilograms.amount
|
61
|
-
end
|
62
|
-
alias_method :kg, :kilograms
|
63
|
-
alias_method :kgs, :kilograms
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def attribute_from_metric_or_imperial(obj, klass, metric_unit, imperial_unit)
|
68
|
-
if obj.is_a?(klass)
|
69
|
-
return value
|
70
|
-
else
|
71
|
-
return klass.new(obj, (@unit_system == :imperial ? imperial_unit : metric_unit))
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
2
|
class Package
|
77
3
|
include Quantified
|
78
4
|
|
@@ -136,7 +62,9 @@ module ActiveShipping #:nodoc:
|
|
136
62
|
end
|
137
63
|
alias_method :tube?, :cylinder?
|
138
64
|
|
139
|
-
def gift
|
65
|
+
def gift?
|
66
|
+
@gift
|
67
|
+
end
|
140
68
|
|
141
69
|
def ounces(options = {})
|
142
70
|
weight(options).in_ounces.amount
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ActiveShipping #:nodoc:
|
2
|
+
class PackageItem
|
3
|
+
include Quantified
|
4
|
+
|
5
|
+
attr_reader :sku, :hs_code, :value, :name, :weight, :quantity, :options
|
6
|
+
|
7
|
+
def initialize(name, grams_or_ounces, value, quantity, options = {})
|
8
|
+
@name = name
|
9
|
+
|
10
|
+
imperial = (options[:units] == :imperial) ||
|
11
|
+
(grams_or_ounces.respond_to?(:unit) && m.unit.to_sym == :imperial)
|
12
|
+
|
13
|
+
@unit_system = imperial ? :imperial : :metric
|
14
|
+
|
15
|
+
@weight = attribute_from_metric_or_imperial(grams_or_ounces, Mass, :grams, :ounces)
|
16
|
+
|
17
|
+
@value = Package.cents_from(value)
|
18
|
+
@quantity = quantity > 0 ? quantity : 1
|
19
|
+
|
20
|
+
@sku = options[:sku]
|
21
|
+
@hs_code = options[:hs_code]
|
22
|
+
@options = options
|
23
|
+
end
|
24
|
+
|
25
|
+
def weight(options = {})
|
26
|
+
case options[:type]
|
27
|
+
when nil, :actual
|
28
|
+
@weight
|
29
|
+
when :volumetric, :dimensional
|
30
|
+
@volumetric_weight ||= begin
|
31
|
+
m = Mass.new((centimetres(:box_volume) / 6.0), :grams)
|
32
|
+
@unit_system == :imperial ? m.in_ounces : m
|
33
|
+
end
|
34
|
+
when :billable
|
35
|
+
[weight, weight(:type => :volumetric)].max
|
36
|
+
end
|
37
|
+
end
|
38
|
+
alias_method :mass, :weight
|
39
|
+
|
40
|
+
def ounces(options = {})
|
41
|
+
weight(options).in_ounces.amount
|
42
|
+
end
|
43
|
+
alias_method :oz, :ounces
|
44
|
+
|
45
|
+
def grams(options = {})
|
46
|
+
weight(options).in_grams.amount
|
47
|
+
end
|
48
|
+
alias_method :g, :grams
|
49
|
+
|
50
|
+
def pounds(options = {})
|
51
|
+
weight(options).in_pounds.amount
|
52
|
+
end
|
53
|
+
alias_method :lb, :pounds
|
54
|
+
alias_method :lbs, :pounds
|
55
|
+
|
56
|
+
def kilograms(options = {})
|
57
|
+
weight(options).in_kilograms.amount
|
58
|
+
end
|
59
|
+
alias_method :kg, :kilograms
|
60
|
+
alias_method :kgs, :kilograms
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def attribute_from_metric_or_imperial(obj, klass, metric_unit, imperial_unit)
|
65
|
+
if obj.is_a?(klass)
|
66
|
+
return value
|
67
|
+
else
|
68
|
+
return klass.new(obj, (@unit_system == :imperial ? imperial_unit : metric_unit))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/test/remote/fedex_test.rb
CHANGED
@@ -225,7 +225,7 @@ class RemoteFedExTest < Minitest::Test
|
|
225
225
|
assert_equal "Delivered", response.status_description
|
226
226
|
|
227
227
|
assert_equal Time.parse('Fri, 03 Jan 2014'), response.ship_time
|
228
|
-
|
228
|
+
assert_nil response.scheduled_delivery_date
|
229
229
|
assert_equal Time.parse('2014-01-09 18:31:00 +0000'), response.actual_delivery_date
|
230
230
|
|
231
231
|
origin_address = ActiveShipping::Location.new(
|
@@ -261,7 +261,7 @@ class RemoteFedExTest < Minitest::Test
|
|
261
261
|
assert_equal 'OC', response.shipment_events.second.type_code
|
262
262
|
assert_equal 'AR', response.shipment_events.third.type_code
|
263
263
|
assert_nil response.actual_delivery_date
|
264
|
-
|
264
|
+
assert_nil response.scheduled_delivery_date
|
265
265
|
end
|
266
266
|
|
267
267
|
def test_find_tracking_info_for_in_transit_shipment_2
|
@@ -275,8 +275,8 @@ class RemoteFedExTest < Minitest::Test
|
|
275
275
|
assert_equal "Arrived at FedEx location", response.status_description
|
276
276
|
|
277
277
|
assert_equal Time.parse('Fri, 03 Jan 2014'), response.ship_time
|
278
|
-
|
279
|
-
|
278
|
+
assert_nil response.scheduled_delivery_date
|
279
|
+
assert_nil response.actual_delivery_date
|
280
280
|
|
281
281
|
origin_address = ActiveShipping::Location.new(
|
282
282
|
city: 'CAMBRIDGE',
|
@@ -391,7 +391,7 @@ class RemoteFedExTest < Minitest::Test
|
|
391
391
|
|
392
392
|
assert response.success?
|
393
393
|
refute_empty response.labels
|
394
|
-
data = response.labels.first.img_data
|
394
|
+
data = response.labels.first.img_data
|
395
395
|
refute_empty data
|
396
396
|
assert data[0...4] == '%PDF'
|
397
397
|
end
|
data/test/remote/ups_test.rb
CHANGED
@@ -373,6 +373,7 @@ class RemoteUPSTest < Minitest::Test
|
|
373
373
|
|
374
374
|
def test_delivery_date_estimates_intl
|
375
375
|
today = Date.current
|
376
|
+
|
376
377
|
response = @carrier.get_delivery_date_estimates(
|
377
378
|
location_fixtures[:new_york_with_name],
|
378
379
|
location_fixtures[:ottawa_with_name],
|
@@ -386,7 +387,7 @@ class RemoteUPSTest < Minitest::Test
|
|
386
387
|
assert response.success?
|
387
388
|
refute_empty response.delivery_estimates
|
388
389
|
ww_express_estimate = response.delivery_estimates.select {|de| de.service_name == "UPS Worldwide Express"}.first
|
389
|
-
assert_equal
|
390
|
+
assert_equal 1.business_days.after(today), ww_express_estimate.date
|
390
391
|
end
|
391
392
|
|
392
393
|
def test_void_shipment
|
data/test/test_helper.rb
CHANGED
@@ -112,7 +112,7 @@ class CanadaPostPwsTrackingTest < Minitest::Test
|
|
112
112
|
|
113
113
|
assert_equal CPPWSTrackingResponse, response.class
|
114
114
|
assert_equal "Expedited Parcels", response.service_name
|
115
|
-
|
115
|
+
assert_nil response.expected_date
|
116
116
|
assert_equal "8213295707205355", response.tracking_number
|
117
117
|
assert_equal 1, response.shipment_events.size
|
118
118
|
assert_equal response.origin.city, "MAPLE"
|
@@ -130,7 +130,7 @@ class CanadaPostPwsTrackingTest < Minitest::Test
|
|
130
130
|
response = @cp.find_tracking_info('1371134583769923', {})
|
131
131
|
|
132
132
|
assert_equal false, response.delivered?
|
133
|
-
|
133
|
+
assert_nil response.actual_delivery_time
|
134
134
|
end
|
135
135
|
|
136
136
|
def test_parse_tracking_response_shipment_events
|
@@ -379,7 +379,7 @@ class FedExTest < Minitest::Test
|
|
379
379
|
refute response.exception?
|
380
380
|
|
381
381
|
assert_equal Date.parse('2013-12-30'), response.ship_time
|
382
|
-
|
382
|
+
assert_nil response.scheduled_delivery_date
|
383
383
|
assert_equal Time.parse('2014-01-02T18:23:29Z'), response.actual_delivery_date
|
384
384
|
|
385
385
|
origin_address = ActiveShipping::Location.new(
|
@@ -417,7 +417,7 @@ class FedExTest < Minitest::Test
|
|
417
417
|
assert_equal 'AR', response.shipment_events.third.type_code
|
418
418
|
assert_equal 'Delivered', response.latest_event.name
|
419
419
|
assert_equal 'DL', response.latest_event.type_code
|
420
|
-
|
420
|
+
assert_nil response.delivery_signature
|
421
421
|
end
|
422
422
|
|
423
423
|
def test_state_degrades_to_unknown
|
@@ -449,13 +449,13 @@ class FedExTest < Minitest::Test
|
|
449
449
|
assert_equal :in_transit, response.status
|
450
450
|
assert_equal 'IT', response.status_code
|
451
451
|
assert_equal "Package available for clearance", response.status_description
|
452
|
-
|
452
|
+
assert_nil response.delivery_signature
|
453
453
|
|
454
454
|
assert_equal Time.parse('2014-11-17T22:39:00+11:00'), response.ship_time
|
455
|
-
|
456
|
-
|
455
|
+
assert_nil response.scheduled_delivery_date
|
456
|
+
assert_nil response.actual_delivery_date
|
457
457
|
|
458
|
-
|
458
|
+
assert_nil response.origin
|
459
459
|
|
460
460
|
destination_address = ActiveShipping::Location.new(
|
461
461
|
city: 'GRAFTON',
|
@@ -481,8 +481,8 @@ class FedExTest < Minitest::Test
|
|
481
481
|
assert_equal "Unable to deliver", response.status_description
|
482
482
|
|
483
483
|
assert_equal Date.parse('2014-01-27'), response.ship_time
|
484
|
-
|
485
|
-
|
484
|
+
assert_nil response.scheduled_delivery_date
|
485
|
+
assert_nil response.actual_delivery_date
|
486
486
|
|
487
487
|
origin_address = ActiveShipping::Location.new(
|
488
488
|
city: 'AUSTIN',
|
@@ -43,7 +43,7 @@ class KunakiTest < Minitest::Test
|
|
43
43
|
|
44
44
|
assert rate = response.rates.first
|
45
45
|
assert_equal "USPS Priority Mail", rate.service_name
|
46
|
-
|
46
|
+
assert_nil rate.service_code
|
47
47
|
assert_equal "USPS", rate.carrier
|
48
48
|
assert_equal 800, rate.total_price
|
49
49
|
assert_equal ["UPS 2nd Day Air", "UPS Ground", "UPS Next Day Air Saver", "USPS Priority Mail"], response.rates.collect(&:service_name).sort
|
@@ -68,7 +68,7 @@ class StampsTest < Minitest::Test
|
|
68
68
|
assert_equal 'ActiveShipping::StampsPurchasePostageResponse', purchase_status.class.name
|
69
69
|
|
70
70
|
assert_equal 'Success', purchase_status.purchase_status
|
71
|
-
|
71
|
+
assert_nil purchase_status.transaction_id
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_validate_address
|
@@ -160,13 +160,13 @@ class USPSTest < Minitest::Test
|
|
160
160
|
# USPS API doesn't tell where it's going
|
161
161
|
@carrier.expects(:commit).returns(@tracking_response)
|
162
162
|
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
163
|
-
|
163
|
+
assert_nil response.destination
|
164
164
|
end
|
165
165
|
|
166
166
|
def test_find_tracking_info_tracking_number
|
167
167
|
@carrier.expects(:commit).returns(@tracking_response)
|
168
168
|
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
169
|
-
assert_equal response.tracking_number
|
169
|
+
assert_equal '9102901000462189604217', response.tracking_number
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_find_tracking_info_should_have_correct_status
|
@@ -118,24 +118,24 @@ class ExternalReturnLabelRequestTest < Minitest::Test
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def test_sanitize
|
121
|
-
assert_equal @external_request_label_req.send(:sanitize,' ')
|
122
|
-
assert_equal @external_request_label_req.send(:sanitize, 'some string ')
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
assert_equal @external_request_label_req.send(:sanitize, (1..100).to_a.join("_")).size
|
121
|
+
assert_equal "", @external_request_label_req.send(:sanitize,' ')
|
122
|
+
assert_equal 'some string', @external_request_label_req.send(:sanitize, 'some string ')
|
123
|
+
assert_nil @external_request_label_req.send(:sanitize, {})
|
124
|
+
assert_nil @external_request_label_req.send(:sanitize, nil)
|
125
|
+
assert_nil @external_request_label_req.send(:sanitize, nil)
|
126
|
+
assert_nil @external_request_label_req.send(:sanitize, [])
|
127
|
+
assert_equal ExternalReturnLabelRequest::CAP_STRING_LEN, @external_request_label_req.send(:sanitize, (1..100).to_a.join("_")).size
|
128
128
|
end
|
129
129
|
|
130
130
|
def test_to_bool
|
131
|
-
assert_equal @external_request_label_req.send(:to_bool, 'yes')
|
132
|
-
assert_equal @external_request_label_req.send(:to_bool, 'true')
|
133
|
-
assert_equal @external_request_label_req.send(:to_bool, true)
|
134
|
-
assert_equal @external_request_label_req.send(:to_bool, '1')
|
135
|
-
assert_equal @external_request_label_req.send(:to_bool, '0')
|
136
|
-
assert_equal @external_request_label_req.send(:to_bool, 'false')
|
137
|
-
assert_equal @external_request_label_req.send(:to_bool, false)
|
138
|
-
assert_equal @external_request_label_req.send(:to_bool, nil, false)
|
131
|
+
assert_equal true, @external_request_label_req.send(:to_bool, 'yes')
|
132
|
+
assert_equal true, @external_request_label_req.send(:to_bool, 'true')
|
133
|
+
assert_equal true, @external_request_label_req.send(:to_bool, true)
|
134
|
+
assert_equal true, @external_request_label_req.send(:to_bool, '1')
|
135
|
+
assert_equal false, @external_request_label_req.send(:to_bool, '0')
|
136
|
+
assert_equal false, @external_request_label_req.send(:to_bool, 'false')
|
137
|
+
assert_equal false, @external_request_label_req.send(:to_bool, false)
|
138
|
+
assert_equal false, @external_request_label_req.send(:to_bool, nil, false)
|
139
139
|
end
|
140
140
|
|
141
141
|
def test_validate_range
|
@@ -176,8 +176,8 @@ class ExternalReturnLabelRequestTest < Minitest::Test
|
|
176
176
|
assert_raises(USPSValidationError) do
|
177
177
|
@external_request_label_req.send(:validate_email, ' ', __method__)
|
178
178
|
end
|
179
|
-
assert_equal @external_request_label_req.send(:validate_email, 'no-reply@example.com', __method__)
|
180
|
-
assert_equal @external_request_label_req.send(:validate_email, ' no-reply@example.com ', __method__)
|
179
|
+
assert_equal 'no-reply@example.com', @external_request_label_req.send(:validate_email, 'no-reply@example.com', __method__)
|
180
|
+
assert_equal 'no-reply@example.com', @external_request_label_req.send(:validate_email, ' no-reply@example.com ', __method__)
|
181
181
|
end
|
182
182
|
|
183
183
|
def test_tag_required
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PackageItemTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@name = "Fancy Pants"
|
6
|
+
@weight = 100
|
7
|
+
@value = 1299
|
8
|
+
@quantity = 3
|
9
|
+
@sku = "1234567890"
|
10
|
+
@hs_code = "1234.56.78"
|
11
|
+
@options = {
|
12
|
+
units: :metric,
|
13
|
+
sku: @sku,
|
14
|
+
hs_code: @hs_code,
|
15
|
+
type: :actual,
|
16
|
+
}
|
17
|
+
|
18
|
+
@item = PackageItem.new(@name, @weight, @value, @quantity, @options)
|
19
|
+
@mass = ::Quantified::Mass.new(@weight, :grams)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initialize_with_all_attributes
|
23
|
+
assert_equal @name, @item.name
|
24
|
+
assert_equal @options, @item.options
|
25
|
+
assert_equal @hs_code, @item.hs_code
|
26
|
+
assert_equal @sku, @item.sku
|
27
|
+
assert_equal @value, @item.value
|
28
|
+
assert_equal @quantity, @item.quantity
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_initialize_assumes_symbol_keys
|
32
|
+
options = {
|
33
|
+
"units" => :imperial,
|
34
|
+
"sku" => @sku,
|
35
|
+
"hs_code" => @hs_code,
|
36
|
+
}
|
37
|
+
@item = PackageItem.new(@name, @weight, @value, @quantity, options)
|
38
|
+
|
39
|
+
assert_nil @item.hs_code
|
40
|
+
assert_nil @item.sku
|
41
|
+
refute_equal @weight, @item.ounces
|
42
|
+
assert_equal @weight, @item.grams
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_initialize_negative_quantity
|
46
|
+
assert_equal 1, PackageItem.new(@name, @weight, @value, -1).quantity
|
47
|
+
assert_equal 1, PackageItem.new(@name, @weight, @value, 0).quantity
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_initialize_weight_mass_object
|
51
|
+
begin
|
52
|
+
@item = PackageItem.new(@name, @mass, @value, @quantity, @options)
|
53
|
+
assert_equal @mass, @item.weight
|
54
|
+
flunk "This code path is broken but passed unexpectedly"
|
55
|
+
rescue NameError
|
56
|
+
skip "This code path is broken"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_initialize_weight_default_metric
|
61
|
+
assert_equal @weight, @item.grams
|
62
|
+
refute_equal @weight, @item.ounces
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_initialize_weight_accepts_imperial
|
66
|
+
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: :imperial))
|
67
|
+
|
68
|
+
assert_equal @weight, @item.ounces
|
69
|
+
refute_equal @weight, @item.grams
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_initialize_weight_accepts_metric
|
73
|
+
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: :metric))
|
74
|
+
|
75
|
+
assert_equal @weight, @item.grams
|
76
|
+
refute_equal @weight, @item.ounces
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_initialize_weight_does_not_accept_strings
|
80
|
+
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: "imperial"))
|
81
|
+
|
82
|
+
assert_equal @weight, @item.grams
|
83
|
+
refute_equal @weight, @item.ounces
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_initialize_value_from_cents
|
87
|
+
@item = PackageItem.new(@name, @weight, "1.23", @quantity, @options)
|
88
|
+
|
89
|
+
assert_equal 123, @item.value
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_weight
|
93
|
+
assert_equal @mass, @item.weight
|
94
|
+
assert_instance_of ::Quantified::Mass, @item.weight
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_weight_actual
|
98
|
+
assert_equal @mass, @item.weight(type: :actual)
|
99
|
+
assert_instance_of ::Quantified::Mass, @item.weight(type: :actual)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_weight_volumetric
|
103
|
+
begin
|
104
|
+
assert_equal :todo, @item.weight(type: :volumetric)
|
105
|
+
assert_instance_of ::Quantified::Mass, @item.weight(type: :volumetric)
|
106
|
+
flunk "This code path is broken but passed unexpectedly"
|
107
|
+
rescue NoMethodError
|
108
|
+
skip "This code path is broken"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_weight_dimensional
|
113
|
+
begin
|
114
|
+
assert_equal :todo, @item.weight(type: :dimensional)
|
115
|
+
assert_instance_of ::Quantified::Mass, @item.weight(type: :dimensional)
|
116
|
+
flunk "This code path is broken but passed unexpectedly"
|
117
|
+
rescue NoMethodError
|
118
|
+
skip "This code path is broken"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_weight_billable_max_weight_and_volumetric
|
123
|
+
begin
|
124
|
+
assert_equal :todo, @item.weight(type: :billable)
|
125
|
+
assert_instance_of ::Quantified::Mass, @item.weight(type: :billable)
|
126
|
+
flunk "This code path is broken but passed unexpectedly"
|
127
|
+
rescue NoMethodError
|
128
|
+
skip "This code path is broken"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_grams_value
|
133
|
+
assert_equal 100, @item.grams
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_grams_accepts_options_with_type
|
137
|
+
begin
|
138
|
+
assert_equal :todo, @item.grams(type: :volumetric)
|
139
|
+
flunk "This code path is broken but passed unexpectedly"
|
140
|
+
rescue NoMethodError
|
141
|
+
skip "This code path is broken"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_grams_converts
|
146
|
+
@item = PackageItem.new(@name, 100, @value, @quantity, @options.merge(units: :imperial))
|
147
|
+
|
148
|
+
assert_in_delta 2834.9, @item.grams, 0.1
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_grams_alias_g
|
152
|
+
assert_equal @item.grams, @item.g
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_ounces_value
|
156
|
+
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: :imperial))
|
157
|
+
|
158
|
+
assert_equal 100, @item.ounces
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_ounces_accepts_options_with_type
|
162
|
+
begin
|
163
|
+
assert_equal :todo, @item.ounces(type: :volumetric)
|
164
|
+
flunk "This code path is broken but passed unexpectedly"
|
165
|
+
rescue NoMethodError
|
166
|
+
skip "This code path is broken"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_ounces_converts
|
171
|
+
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: :metric))
|
172
|
+
|
173
|
+
assert_in_delta 3.5, @item.ounces, 0.1
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_ounces_alias_oz
|
177
|
+
assert_equal @item.ounces, @item.oz
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_pounds_value
|
181
|
+
@item = PackageItem.new(@name, 32, @value, @quantity, @options.merge(units: :imperial))
|
182
|
+
|
183
|
+
assert_equal 2, @item.pounds
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_pounds_accepts_options_with_type
|
187
|
+
begin
|
188
|
+
assert_equal :todo, @item.pounds(type: :volumetric)
|
189
|
+
flunk "This code path is broken but passed unexpectedly"
|
190
|
+
rescue
|
191
|
+
skip "This code path is broken"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_pounds_converts
|
196
|
+
@item = PackageItem.new(@name, 1000, @value, @quantity, @options.merge(units: :metric))
|
197
|
+
|
198
|
+
assert_in_delta 2.2, @item.pounds, 0.1
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_pounds_alias_lb
|
202
|
+
assert_equal @item.pounds, @item.lb
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_pounds_alias_lbs
|
206
|
+
assert_equal @item.pounds, @item.lbs
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_kilograms_value
|
210
|
+
@item = PackageItem.new(@name, 1000, @value, @quantity, @options.merge(units: :metric))
|
211
|
+
|
212
|
+
assert_equal 1, @item.kilograms
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_kilograms_accepts_options_with_type
|
216
|
+
begin
|
217
|
+
assert_equal :todo, @item.kilograms(type: :volumetric)
|
218
|
+
flunk "This code path is broken but passed unexpectedly"
|
219
|
+
rescue
|
220
|
+
skip "This code path is broken"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_kilograms_converts
|
225
|
+
@item = PackageItem.new(@name, 1000, @value, @quantity, @options.merge(units: :imperial))
|
226
|
+
|
227
|
+
assert_in_delta 28.3, @item.kilograms, 0.1
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_kilograms_alias_kg
|
231
|
+
assert_equal @item.kilograms, @item.kg
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_kilograms_alias_kgs
|
235
|
+
assert_equal @item.kilograms, @item.kgs
|
236
|
+
end
|
237
|
+
end
|