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/location_test.rb
CHANGED
@@ -1,135 +1,231 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class LocationTest <
|
3
|
+
class LocationTest < ActiveSupport::TestCase
|
4
4
|
include ActiveShipping::Test::Fixtures
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
assert_equal
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
assert_equal
|
6
|
+
setup do
|
7
|
+
@location = location_fixtures[:ottawa]
|
8
|
+
@address2 = 'Apt 613'
|
9
|
+
@address3 = 'Victory Lane'
|
10
|
+
@attributes_hash = {
|
11
|
+
country: 'CA',
|
12
|
+
zip: '90210',
|
13
|
+
territory_code: 'QC',
|
14
|
+
town: 'Perth',
|
15
|
+
address: '66 Gregory Ave.',
|
16
|
+
phone: '515-555-1212',
|
17
|
+
fax_number: 'none to speak of',
|
18
|
+
address_type: :commercial,
|
19
|
+
name: "Bob Bobsen",
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
test "#initialize sets a country object" do
|
24
|
+
assert_instance_of ActiveUtils::Country, @location.country
|
25
|
+
assert_equal 'CA', @location.country_code(:alpha2)
|
26
|
+
end
|
27
|
+
|
28
|
+
test ".from sets up the location from a hash" do
|
29
|
+
location = Location.from(@attributes_hash)
|
30
|
+
|
31
|
+
assert_equal @attributes_hash[:country], location.country_code(:alpha2)
|
32
|
+
assert_equal @attributes_hash[:zip], location.zip
|
33
|
+
assert_equal @attributes_hash[:territory_code], location.province
|
34
|
+
assert_equal @attributes_hash[:town], location.city
|
35
|
+
assert_equal @attributes_hash[:address], location.address1
|
36
|
+
assert_equal @attributes_hash[:phone], location.phone
|
37
|
+
assert_equal @attributes_hash[:fax_number], location.fax
|
38
|
+
assert_equal @attributes_hash[:address_type].to_s, location.address_type
|
39
|
+
assert_equal @attributes_hash[:name], location.name
|
40
|
+
end
|
41
|
+
|
42
|
+
test ".from sets from an object with properties" do
|
43
|
+
object = Class.new do
|
44
|
+
def initialize(hash)
|
45
|
+
@hash = hash
|
46
|
+
end
|
47
|
+
def method_missing(method)
|
48
|
+
@hash[method]
|
49
|
+
end
|
50
|
+
def respond_to?(method)
|
51
|
+
return false if method == :[]
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end.new(@attributes_hash)
|
55
|
+
|
56
|
+
location = Location.from(object)
|
57
|
+
|
58
|
+
assert_equal @attributes_hash[:country], location.country_code(:alpha2)
|
59
|
+
assert_equal @attributes_hash[:zip], location.zip
|
60
|
+
assert_equal @attributes_hash[:territory_code], location.province
|
61
|
+
assert_equal @attributes_hash[:town], location.city
|
62
|
+
assert_equal @attributes_hash[:address], location.address1
|
63
|
+
assert_equal @attributes_hash[:phone], location.phone
|
64
|
+
assert_equal @attributes_hash[:fax_number], location.fax
|
65
|
+
assert_equal @attributes_hash[:address_type].to_s, location.address_type
|
66
|
+
assert_equal @attributes_hash[:name], location.name
|
67
|
+
end
|
68
|
+
|
69
|
+
test ".from adheres to propery order even if hash access is available" do
|
70
|
+
object = Class.new do
|
71
|
+
def [](index)
|
72
|
+
{ province: "California" }[index]
|
73
|
+
end
|
74
|
+
|
75
|
+
def province_code
|
76
|
+
"CA"
|
77
|
+
end
|
78
|
+
end.new
|
79
|
+
assert_equal "CA", Location.from(object).province
|
80
|
+
end
|
81
|
+
|
82
|
+
test ".from sets the name to nil if it is not provided" do
|
83
|
+
location = Location.from({})
|
84
|
+
assert_nil location.name
|
36
85
|
end
|
37
86
|
|
38
|
-
|
39
|
-
|
40
|
-
|
87
|
+
test ".from sets company and company_name from company" do
|
88
|
+
location = Location.from(company: "Mine")
|
89
|
+
|
90
|
+
assert_equal "Mine", location.company
|
91
|
+
assert_equal "Mine", location.company_name
|
41
92
|
end
|
42
93
|
|
43
|
-
|
44
|
-
|
45
|
-
|
94
|
+
test ".from sets company and company_name from company_name" do
|
95
|
+
location = Location.from(company_name: "Mine")
|
96
|
+
|
97
|
+
assert_equal "Mine", location.company
|
98
|
+
assert_equal "Mine", location.company_name
|
46
99
|
end
|
47
100
|
|
48
|
-
|
49
|
-
location = Location.from(:
|
50
|
-
|
101
|
+
test ".from prioritizes company" do
|
102
|
+
location = Location.from(company_name: "from company_name", company: "from company")
|
103
|
+
|
104
|
+
assert_equal "from company", location.company
|
105
|
+
assert_equal "from company", location.company_name
|
51
106
|
end
|
52
107
|
|
53
|
-
|
54
|
-
|
55
|
-
|
108
|
+
test "#prettyprint outputs a readable string" do
|
109
|
+
expected = "110 Laurier Avenue West\nOttawa, ON, K1P 1J1\nCanada"
|
110
|
+
assert_equal expected, @location.prettyprint
|
56
111
|
end
|
57
112
|
|
58
|
-
|
59
|
-
|
60
|
-
assert_equal
|
113
|
+
test "#to_s outputs a readable string without newlines" do
|
114
|
+
expected = "110 Laurier Avenue West Ottawa, ON, K1P 1J1 Canada"
|
115
|
+
assert_equal expected, @location.to_s
|
116
|
+
end
|
61
117
|
|
62
|
-
|
63
|
-
|
118
|
+
test "#inspect returns a readable string" do
|
119
|
+
expected = "110 Laurier Avenue West\nOttawa, ON, K1P 1J1\nCanada\nPhone: 1-613-580-2400\nFax: 1-613-580-2495"
|
120
|
+
assert_equal expected, @location.inspect
|
64
121
|
end
|
65
122
|
|
66
|
-
|
67
|
-
location
|
68
|
-
assert !location.commercial?
|
123
|
+
test "#address_type= assigns a type of address as commercial" do
|
124
|
+
refute @location.commercial?
|
69
125
|
|
70
|
-
location.address_type = :commercial
|
71
|
-
assert location.commercial?
|
126
|
+
@location.address_type = :commercial
|
127
|
+
assert @location.commercial?
|
128
|
+
refute @location.residential?
|
129
|
+
assert_equal "commercial", @location.address_type
|
72
130
|
end
|
73
131
|
|
74
|
-
|
75
|
-
location
|
132
|
+
test "#address_type= assigns a type of address as residential" do
|
133
|
+
refute @location.residential?
|
76
134
|
|
135
|
+
@location.address_type = :residential
|
136
|
+
assert @location.residential?
|
137
|
+
refute @location.commercial?
|
138
|
+
assert_equal "residential", @location.address_type
|
139
|
+
end
|
140
|
+
|
141
|
+
test "#address_type= raises on an invalid assignment" do
|
77
142
|
assert_raises(ArgumentError) do
|
78
|
-
location.address_type = :new_address_type
|
143
|
+
@location.address_type = :new_address_type
|
79
144
|
end
|
80
145
|
|
81
|
-
|
146
|
+
assert_nil @location.address_type
|
82
147
|
end
|
83
148
|
|
84
|
-
|
85
|
-
|
149
|
+
test "#address_type= cannot blank out the value as nil" do
|
150
|
+
@location.address_type = :residential
|
151
|
+
assert @location.residential?
|
152
|
+
|
153
|
+
@location.address_type = nil
|
154
|
+
assert @location.residential?
|
155
|
+
assert_equal "residential", @location.address_type
|
86
156
|
end
|
87
157
|
|
88
|
-
|
89
|
-
|
90
|
-
|
158
|
+
test "#address_type= cannot blank out the value as empty string" do
|
159
|
+
@location.address_type = :residential
|
160
|
+
assert @location.residential?
|
161
|
+
|
162
|
+
@location.address_type = ""
|
163
|
+
assert @location.residential?
|
164
|
+
assert_equal "residential", @location.address_type
|
91
165
|
end
|
92
166
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
location = Location.from(:zip => "#{zip}#{plus_4}")
|
98
|
-
assert_equal zip_plus_4, location.zip_plus_4
|
167
|
+
test "#to_hash has the expected attributes" do
|
168
|
+
expected = %w(address1 address2 address3 address_type city company_name country fax name phone postal_code province)
|
169
|
+
|
170
|
+
assert_equal expected, @location.to_hash.stringify_keys.keys.sort
|
99
171
|
end
|
100
172
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
location = Location.from(:zip => zip_plus_4)
|
106
|
-
assert_equal zip_plus_4, location.zip_plus_4
|
173
|
+
test "#to_json returns the JSON values" do
|
174
|
+
expected = JSON.parse(@location.to_json).symbolize_keys
|
175
|
+
|
176
|
+
assert_equal @location.to_hash, expected
|
107
177
|
end
|
108
178
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
179
|
+
test "#zip_plus_4 nil without the extra four" do
|
180
|
+
zip = "12345"
|
181
|
+
location = Location.from(zip: zip)
|
182
|
+
|
183
|
+
assert_nil location.zip_plus_4
|
184
|
+
assert_equal zip, location.zip
|
114
185
|
end
|
115
186
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
location = Location.from(:
|
187
|
+
test "#zip_plus_4 parses without the dash" do
|
188
|
+
zip = "12345-9999"
|
189
|
+
zip_without_dash = "123459999"
|
190
|
+
location = Location.from(zip: zip_without_dash)
|
191
|
+
|
192
|
+
assert_equal zip, location.zip_plus_4
|
193
|
+
assert_equal zip_without_dash, location.zip
|
194
|
+
end
|
195
|
+
|
196
|
+
test "#zip_plus_4 parses with the dash" do
|
197
|
+
zip = "12345-9999"
|
198
|
+
location = Location.from(zip: zip)
|
199
|
+
|
200
|
+
assert_equal zip, location.zip_plus_4
|
201
|
+
assert_equal zip, location.zip
|
202
|
+
end
|
203
|
+
|
204
|
+
test "#address2_and_3 shows just address2" do
|
205
|
+
location = Location.from(address2: @address2)
|
120
206
|
assert_equal 'Apt 613', location.address2_and_3
|
207
|
+
end
|
208
|
+
|
209
|
+
test "#address2_and_3 shows just address3" do
|
210
|
+
location = Location.from(address3: @address3)
|
211
|
+
assert_equal @address3, location.address2_and_3
|
212
|
+
end
|
121
213
|
|
122
|
-
|
123
|
-
|
214
|
+
test "#address2_and_3 shows both address2 and address3" do
|
215
|
+
location = Location.from(address2: @address2, address3: @address3)
|
216
|
+
assert_equal "#{@address2}, #{@address3}", location.address2_and_3
|
217
|
+
end
|
124
218
|
|
125
|
-
|
126
|
-
|
219
|
+
test "#address2_and_3 shows an empty string when address2 and address3 are both blank" do
|
220
|
+
assert_nil @location.address2
|
221
|
+
assert_nil @location.address3
|
222
|
+
assert_equal "", @location.address2_and_3
|
127
223
|
end
|
128
224
|
|
129
|
-
|
130
|
-
|
131
|
-
location_2 = Location.from(location_1.to_hash)
|
225
|
+
test "#== compares locations by attributes" do
|
226
|
+
another_location = Location.from(@location.to_hash)
|
132
227
|
|
133
|
-
assert_equal
|
228
|
+
assert_equal @location, another_location
|
229
|
+
refute_equal @location, Location.new({})
|
134
230
|
end
|
135
231
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class PackageItemTest <
|
4
|
-
|
3
|
+
class PackageItemTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
5
|
@name = "Fancy Pants"
|
6
6
|
@weight = 100
|
7
7
|
@value = 1299
|
@@ -16,10 +16,10 @@ class PackageItemTest < Minitest::Test
|
|
16
16
|
}
|
17
17
|
|
18
18
|
@item = PackageItem.new(@name, @weight, @value, @quantity, @options)
|
19
|
-
@mass = ::
|
19
|
+
@mass = Measured::Weight.new(@weight, :grams)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
test "#initialize with all attributes" do
|
23
23
|
assert_equal @name, @item.name
|
24
24
|
assert_equal @options, @item.options
|
25
25
|
assert_equal @hs_code, @item.hs_code
|
@@ -28,7 +28,7 @@ class PackageItemTest < Minitest::Test
|
|
28
28
|
assert_equal @quantity, @item.quantity
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
test "#initialize assumes symbol keys" do
|
32
32
|
options = {
|
33
33
|
"units" => :imperial,
|
34
34
|
"sku" => @sku,
|
@@ -42,98 +42,93 @@ class PackageItemTest < Minitest::Test
|
|
42
42
|
assert_equal @weight, @item.grams
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
test "#initialize with a negative quantity" do
|
46
46
|
assert_equal 1, PackageItem.new(@name, @weight, @value, -1).quantity
|
47
47
|
assert_equal 1, PackageItem.new(@name, @weight, @value, 0).quantity
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
50
|
+
test "#initialize weight mass object" do
|
51
|
+
@item = PackageItem.new(@name, @mass, @value, @quantity, @options)
|
52
|
+
assert_equal @mass, @item.weight
|
58
53
|
end
|
59
54
|
|
60
|
-
|
55
|
+
test "#initialize weight default metric" do
|
61
56
|
assert_equal @weight, @item.grams
|
62
57
|
refute_equal @weight, @item.ounces
|
63
58
|
end
|
64
59
|
|
65
|
-
|
60
|
+
test "#initialize weight accepts imperial" do
|
66
61
|
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: :imperial))
|
67
62
|
|
68
63
|
assert_equal @weight, @item.ounces
|
69
64
|
refute_equal @weight, @item.grams
|
70
65
|
end
|
71
66
|
|
72
|
-
|
67
|
+
test "#initialize_weight accepts metric" do
|
73
68
|
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: :metric))
|
74
69
|
|
75
70
|
assert_equal @weight, @item.grams
|
76
71
|
refute_equal @weight, @item.ounces
|
77
72
|
end
|
78
73
|
|
79
|
-
|
74
|
+
test "#initialize weight does not accept strings" do
|
80
75
|
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: "imperial"))
|
81
76
|
|
82
77
|
assert_equal @weight, @item.grams
|
83
78
|
refute_equal @weight, @item.ounces
|
84
79
|
end
|
85
80
|
|
86
|
-
|
81
|
+
test "#initialize value from cents" do
|
87
82
|
@item = PackageItem.new(@name, @weight, "1.23", @quantity, @options)
|
88
83
|
|
89
84
|
assert_equal 123, @item.value
|
90
85
|
end
|
91
86
|
|
92
|
-
|
87
|
+
test "#weight default lookup" do
|
93
88
|
assert_equal @mass, @item.weight
|
94
|
-
assert_instance_of ::
|
89
|
+
assert_instance_of Measured::Weight, @item.weight
|
95
90
|
end
|
96
91
|
|
97
|
-
|
92
|
+
test "#weight type: actual" do
|
98
93
|
assert_equal @mass, @item.weight(type: :actual)
|
99
|
-
assert_instance_of ::
|
94
|
+
assert_instance_of Measured::Weight, @item.weight(type: :actual)
|
100
95
|
end
|
101
96
|
|
102
|
-
|
97
|
+
test "#weight type: volumetric" do
|
103
98
|
begin
|
104
99
|
assert_equal :todo, @item.weight(type: :volumetric)
|
105
|
-
assert_instance_of ::
|
100
|
+
assert_instance_of Measured::Weight, @item.weight(type: :volumetric)
|
106
101
|
flunk "This code path is broken but passed unexpectedly"
|
107
102
|
rescue NoMethodError
|
108
103
|
skip "This code path is broken"
|
109
104
|
end
|
110
105
|
end
|
111
106
|
|
112
|
-
|
107
|
+
test "#weight type: dimensional" do
|
113
108
|
begin
|
114
109
|
assert_equal :todo, @item.weight(type: :dimensional)
|
115
|
-
assert_instance_of ::
|
110
|
+
assert_instance_of Measured::Weight, @item.weight(type: :dimensional)
|
116
111
|
flunk "This code path is broken but passed unexpectedly"
|
117
112
|
rescue NoMethodError
|
118
113
|
skip "This code path is broken"
|
119
114
|
end
|
120
115
|
end
|
121
116
|
|
122
|
-
|
117
|
+
test "#weight type: billable is the max of weight and volumetric" do
|
123
118
|
begin
|
124
119
|
assert_equal :todo, @item.weight(type: :billable)
|
125
|
-
assert_instance_of ::
|
120
|
+
assert_instance_of Measured::Weight, @item.weight(type: :billable)
|
126
121
|
flunk "This code path is broken but passed unexpectedly"
|
127
122
|
rescue NoMethodError
|
128
123
|
skip "This code path is broken"
|
129
124
|
end
|
130
125
|
end
|
131
126
|
|
132
|
-
|
127
|
+
test "#grams is the value" do
|
133
128
|
assert_equal 100, @item.grams
|
134
129
|
end
|
135
130
|
|
136
|
-
|
131
|
+
test "#grams accepts options with type" do
|
137
132
|
begin
|
138
133
|
assert_equal :todo, @item.grams(type: :volumetric)
|
139
134
|
flunk "This code path is broken but passed unexpectedly"
|
@@ -142,23 +137,23 @@ class PackageItemTest < Minitest::Test
|
|
142
137
|
end
|
143
138
|
end
|
144
139
|
|
145
|
-
|
140
|
+
test "#grams converts to another unit" do
|
146
141
|
@item = PackageItem.new(@name, 100, @value, @quantity, @options.merge(units: :imperial))
|
147
142
|
|
148
143
|
assert_in_delta 2834.9, @item.grams, 0.1
|
149
144
|
end
|
150
145
|
|
151
|
-
|
146
|
+
test "#grams aliases to g" do
|
152
147
|
assert_equal @item.grams, @item.g
|
153
148
|
end
|
154
149
|
|
155
|
-
|
150
|
+
test "#ounces is the value" do
|
156
151
|
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: :imperial))
|
157
152
|
|
158
153
|
assert_equal 100, @item.ounces
|
159
154
|
end
|
160
155
|
|
161
|
-
|
156
|
+
test "#ounces accepts options with type" do
|
162
157
|
begin
|
163
158
|
assert_equal :todo, @item.ounces(type: :volumetric)
|
164
159
|
flunk "This code path is broken but passed unexpectedly"
|
@@ -167,23 +162,23 @@ class PackageItemTest < Minitest::Test
|
|
167
162
|
end
|
168
163
|
end
|
169
164
|
|
170
|
-
|
165
|
+
test "#ounces converts to another unit" do
|
171
166
|
@item = PackageItem.new(@name, @weight, @value, @quantity, @options.merge(units: :metric))
|
172
167
|
|
173
168
|
assert_in_delta 3.5, @item.ounces, 0.1
|
174
169
|
end
|
175
170
|
|
176
|
-
|
171
|
+
test "#ounces aliases to oz" do
|
177
172
|
assert_equal @item.ounces, @item.oz
|
178
173
|
end
|
179
174
|
|
180
|
-
|
175
|
+
test "#pounds is the value" do
|
181
176
|
@item = PackageItem.new(@name, 32, @value, @quantity, @options.merge(units: :imperial))
|
182
177
|
|
183
178
|
assert_equal 2, @item.pounds
|
184
179
|
end
|
185
180
|
|
186
|
-
|
181
|
+
test "#pounds accepts options with type" do
|
187
182
|
begin
|
188
183
|
assert_equal :todo, @item.pounds(type: :volumetric)
|
189
184
|
flunk "This code path is broken but passed unexpectedly"
|
@@ -192,27 +187,27 @@ class PackageItemTest < Minitest::Test
|
|
192
187
|
end
|
193
188
|
end
|
194
189
|
|
195
|
-
|
190
|
+
test "#pounds converts to another unit" do
|
196
191
|
@item = PackageItem.new(@name, 1000, @value, @quantity, @options.merge(units: :metric))
|
197
192
|
|
198
193
|
assert_in_delta 2.2, @item.pounds, 0.1
|
199
194
|
end
|
200
195
|
|
201
|
-
|
196
|
+
test "#pounds aliases to lb" do
|
202
197
|
assert_equal @item.pounds, @item.lb
|
203
198
|
end
|
204
199
|
|
205
|
-
|
200
|
+
test "#pounds aliases to lbs" do
|
206
201
|
assert_equal @item.pounds, @item.lbs
|
207
202
|
end
|
208
203
|
|
209
|
-
|
204
|
+
test "#kilograms is the value" do
|
210
205
|
@item = PackageItem.new(@name, 1000, @value, @quantity, @options.merge(units: :metric))
|
211
206
|
|
212
207
|
assert_equal 1, @item.kilograms
|
213
208
|
end
|
214
209
|
|
215
|
-
|
210
|
+
test "#kilograms accepts options with type" do
|
216
211
|
begin
|
217
212
|
assert_equal :todo, @item.kilograms(type: :volumetric)
|
218
213
|
flunk "This code path is broken but passed unexpectedly"
|
@@ -221,17 +216,17 @@ class PackageItemTest < Minitest::Test
|
|
221
216
|
end
|
222
217
|
end
|
223
218
|
|
224
|
-
|
219
|
+
test "#kilograms converts to another unit" do
|
225
220
|
@item = PackageItem.new(@name, 1000, @value, @quantity, @options.merge(units: :imperial))
|
226
221
|
|
227
222
|
assert_in_delta 28.3, @item.kilograms, 0.1
|
228
223
|
end
|
229
224
|
|
230
|
-
|
225
|
+
test "#kilograms aliases to kg" do
|
231
226
|
assert_equal @item.kilograms, @item.kg
|
232
227
|
end
|
233
228
|
|
234
|
-
|
229
|
+
test "#kilograms aliases to kgs" do
|
235
230
|
assert_equal @item.kilograms, @item.kgs
|
236
231
|
end
|
237
232
|
end
|