bcarpenter-active_shipping 0.0.2

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.
Files changed (63) hide show
  1. data/CHANGELOG +23 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.markdown +173 -0
  4. data/Rakefile +52 -0
  5. data/VERSION +1 -0
  6. data/lib/active_shipping.rb +50 -0
  7. data/lib/active_shipping/lib/connection.rb +170 -0
  8. data/lib/active_shipping/lib/country.rb +319 -0
  9. data/lib/active_shipping/lib/error.rb +4 -0
  10. data/lib/active_shipping/lib/post_data.rb +22 -0
  11. data/lib/active_shipping/lib/posts_data.rb +47 -0
  12. data/lib/active_shipping/lib/requires_parameters.rb +16 -0
  13. data/lib/active_shipping/lib/utils.rb +18 -0
  14. data/lib/active_shipping/lib/validateable.rb +76 -0
  15. data/lib/active_shipping/shipping/base.rb +15 -0
  16. data/lib/active_shipping/shipping/carrier.rb +70 -0
  17. data/lib/active_shipping/shipping/carriers.rb +17 -0
  18. data/lib/active_shipping/shipping/carriers/bogus_carrier.rb +16 -0
  19. data/lib/active_shipping/shipping/carriers/fedex.rb +315 -0
  20. data/lib/active_shipping/shipping/carriers/shipwire.rb +167 -0
  21. data/lib/active_shipping/shipping/carriers/ups.rb +368 -0
  22. data/lib/active_shipping/shipping/carriers/usps.rb +420 -0
  23. data/lib/active_shipping/shipping/location.rb +100 -0
  24. data/lib/active_shipping/shipping/package.rb +144 -0
  25. data/lib/active_shipping/shipping/rate_estimate.rb +54 -0
  26. data/lib/active_shipping/shipping/rate_response.rb +19 -0
  27. data/lib/active_shipping/shipping/response.rb +49 -0
  28. data/lib/active_shipping/shipping/shipment_event.rb +14 -0
  29. data/lib/active_shipping/shipping/tracking_response.rb +22 -0
  30. data/lib/certs/cacert.pem +7815 -0
  31. data/lib/vendor/quantified/MIT-LICENSE +22 -0
  32. data/lib/vendor/quantified/README.markdown +49 -0
  33. data/lib/vendor/quantified/Rakefile +21 -0
  34. data/lib/vendor/quantified/init.rb +0 -0
  35. data/lib/vendor/quantified/lib/quantified.rb +6 -0
  36. data/lib/vendor/quantified/lib/quantified/attribute.rb +208 -0
  37. data/lib/vendor/quantified/lib/quantified/length.rb +20 -0
  38. data/lib/vendor/quantified/lib/quantified/mass.rb +19 -0
  39. data/lib/vendor/quantified/test/length_test.rb +92 -0
  40. data/lib/vendor/quantified/test/mass_test.rb +88 -0
  41. data/lib/vendor/quantified/test/test_helper.rb +2 -0
  42. data/lib/vendor/test_helper.rb +13 -0
  43. data/lib/vendor/xml_node/README +36 -0
  44. data/lib/vendor/xml_node/Rakefile +21 -0
  45. data/lib/vendor/xml_node/benchmark/bench_generation.rb +32 -0
  46. data/lib/vendor/xml_node/init.rb +1 -0
  47. data/lib/vendor/xml_node/lib/xml_node.rb +222 -0
  48. data/lib/vendor/xml_node/test/test_generating.rb +94 -0
  49. data/lib/vendor/xml_node/test/test_parsing.rb +43 -0
  50. data/test/remote/fedex_test.rb +140 -0
  51. data/test/remote/shipwire_test.rb +88 -0
  52. data/test/remote/ups_test.rb +187 -0
  53. data/test/remote/usps_test.rb +184 -0
  54. data/test/test_helper.rb +167 -0
  55. data/test/unit/base_test.rb +18 -0
  56. data/test/unit/carriers/fedex_test.rb +78 -0
  57. data/test/unit/carriers/shipwire_test.rb +130 -0
  58. data/test/unit/carriers/ups_test.rb +81 -0
  59. data/test/unit/carriers/usps_test.rb +170 -0
  60. data/test/unit/location_test.rb +46 -0
  61. data/test/unit/package_test.rb +65 -0
  62. data/test/unit/response_test.rb +10 -0
  63. metadata +123 -0
@@ -0,0 +1,130 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class ShipwireTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @packages = TestFixtures.packages
7
+ @locations = TestFixtures.locations
8
+ @carrier = Shipwire.new(:login => 'l', :password => 'p')
9
+ @items = [ { :sku => 'AF0001', :quantity => 1 }, { :sku => 'AF0002', :quantity => 2 } ]
10
+ end
11
+
12
+ def test_invalid_credentials
13
+ @carrier.expects(:ssl_post).returns(xml_fixture('shipwire/invalid_credentials_response'))
14
+
15
+ begin
16
+ @carrier.find_rates(
17
+ @locations[:ottawa],
18
+ @locations[:beverly_hills],
19
+ @packages.values_at(:book, :wii),
20
+ :order_id => '#1000',
21
+ :items => @items
22
+ )
23
+ rescue ResponseError => e
24
+ assert_equal "Could not verify e-mail/password combination", e.message
25
+ end
26
+ end
27
+
28
+ def test_response_with_no_rates_is_unsuccessful
29
+ @carrier.expects(:ssl_post).returns(xml_fixture('shipwire/no_rates_response'))
30
+
31
+ assert_raises(ResponseError) do
32
+ response = @carrier.find_rates(
33
+ @locations[:ottawa],
34
+ @locations[:beverly_hills],
35
+ @packages.values_at(:book, :wii),
36
+ :order_id => '#1000',
37
+ :items => @items
38
+ )
39
+ end
40
+ end
41
+
42
+ def test_successfully_get_international_rates
43
+ @carrier.expects(:ssl_post).returns(xml_fixture('shipwire/international_rates_response'))
44
+
45
+ response = @carrier.find_rates(
46
+ @locations[:ottawa],
47
+ @locations[:london],
48
+ @packages.values_at(:book, :wii),
49
+ :order_id => '#1000',
50
+ :items => @items
51
+ )
52
+
53
+ assert response.success?
54
+
55
+ assert_equal 1, response.rates.size
56
+
57
+ assert international = response.rates.first
58
+ assert_equal "INTL", international.service_code
59
+ assert_equal "UPS", international.carrier
60
+ assert_equal "UPS Standard", international.service_name
61
+ assert_equal 2806, international.total_price
62
+ end
63
+
64
+ def test_successfully_get_domestic_rates
65
+ @carrier.expects(:ssl_post).returns(xml_fixture('shipwire/rates_response'))
66
+
67
+ response = @carrier.find_rates(
68
+ @locations[:ottawa],
69
+ @locations[:beverly_hills],
70
+ @packages.values_at(:book, :wii),
71
+ :order_id => '#1000',
72
+ :items => @items
73
+ )
74
+
75
+ assert response.success?
76
+
77
+ assert_equal 3, response.rates.size
78
+
79
+ assert ground = response.rates.find{|r| r.service_code == "GD" }
80
+ assert_equal "UPS", ground.carrier
81
+ assert_equal "UPS Ground", ground.service_name
82
+ assert_equal 773, ground.total_price
83
+
84
+ assert two_day = response.rates.find{|r| r.service_code == "2D" }
85
+ assert_equal "UPS", two_day.carrier
86
+ assert_equal "UPS Second Day Air", two_day.service_name
87
+ assert_equal 1364, two_day.total_price
88
+
89
+ assert one_day = response.rates.find{|r| r.service_code == "1D" }
90
+ assert_equal "USPS", one_day.carrier
91
+ assert_equal "USPS Express Mail", one_day.service_name
92
+ assert_equal 2525, one_day.total_price
93
+ end
94
+
95
+ def test_gracefully_handle_new_carrier
96
+ @carrier.expects(:ssl_post).returns(xml_fixture('shipwire/new_carrier_rate_response'))
97
+
98
+ response = @carrier.find_rates(
99
+ @locations[:ottawa],
100
+ @locations[:beverly_hills],
101
+ @packages.values_at(:book, :wii),
102
+ :order_id => '#1000',
103
+ :items => @items
104
+ )
105
+ assert response.success?
106
+ assert_equal 1, response.rates.size
107
+ assert ground = response.rates.first
108
+ assert_equal "FESCO", ground.carrier
109
+ end
110
+
111
+ def test_find_rates_requires_items_option
112
+ assert_raises(ArgumentError) do
113
+ @carrier.find_rates(
114
+ @locations[:ottawa],
115
+ @locations[:beverly_hills],
116
+ @packages.values_at(:book, :wii)
117
+ )
118
+ end
119
+ end
120
+
121
+ def test_validate_credentials_with_valid_credentials
122
+ @carrier.expects(:ssl_post).returns(xml_fixture('shipwire/no_rates_response'))
123
+ assert @carrier.valid_credentials?
124
+ end
125
+
126
+ def test_validate_credentials_with_invalid_credentials
127
+ @carrier.expects(:ssl_post).returns(xml_fixture('shipwire/invalid_credentials_response'))
128
+ assert !@carrier.valid_credentials?
129
+ end
130
+ end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class UPSTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @packages = TestFixtures.packages
7
+ @locations = TestFixtures.locations
8
+ @carrier = UPS.new(
9
+ :key => 'key',
10
+ :login => 'login',
11
+ :password => 'password'
12
+ )
13
+ @tracking_response = xml_fixture('ups/shipment_from_tiger_direct')
14
+ end
15
+
16
+ def test_initialize_options_requirements
17
+ assert_raises(ArgumentError) { UPS.new }
18
+ assert_raises(ArgumentError) { UPS.new(:login => 'blah', :password => 'bloo') }
19
+ assert_raises(ArgumentError) { UPS.new(:login => 'blah', :key => 'kee') }
20
+ assert_raises(ArgumentError) { UPS.new(:password => 'bloo', :key => 'kee') }
21
+ assert_nothing_raised { UPS.new(:login => 'blah', :password => 'bloo', :key => 'kee') }
22
+ end
23
+
24
+ def test_find_tracking_info_should_return_a_tracking_response
25
+ @carrier.expects(:commit).returns(@tracking_response)
26
+ assert_equal 'ActiveMerchant::Shipping::TrackingResponse', @carrier.find_tracking_info('1Z5FX0076803466397').class.name
27
+ end
28
+
29
+ def test_find_tracking_info_should_parse_response_into_correct_number_of_shipment_events
30
+ @carrier.expects(:commit).returns(@tracking_response)
31
+ response = @carrier.find_tracking_info('1Z5FX0076803466397')
32
+ assert_equal 8, response.shipment_events.size
33
+ end
34
+
35
+ def test_find_tracking_info_should_return_shipment_events_in_ascending_chronological_order
36
+ @carrier.expects(:commit).returns(@tracking_response)
37
+ response = @carrier.find_tracking_info('1Z5FX0076803466397')
38
+ assert_equal response.shipment_events.map(&:time).sort, response.shipment_events.map(&:time)
39
+ end
40
+
41
+ def test_find_tracking_info_should_have_correct_names_for_shipment_events
42
+ @carrier.expects(:commit).returns(@tracking_response)
43
+ response = @carrier.find_tracking_info('1Z5FX0076803466397')
44
+ assert_equal [ "BILLING INFORMATION RECEIVED",
45
+ "IMPORT SCAN",
46
+ "LOCATION SCAN",
47
+ "LOCATION SCAN",
48
+ "DEPARTURE SCAN",
49
+ "ARRIVAL SCAN",
50
+ "OUT FOR DELIVERY",
51
+ "DELIVERED" ], response.shipment_events.map(&:name)
52
+ end
53
+
54
+ def test_add_origin_and_destination_data_to_shipment_events_where_appropriate
55
+ @carrier.expects(:commit).returns(@tracking_response)
56
+ response = @carrier.find_tracking_info('1Z5FX0076803466397')
57
+ assert_equal '175 AMBASSADOR', response.shipment_events.first.location.address1
58
+ assert_equal 'K1N5X8', response.shipment_events.last.location.postal_code
59
+ end
60
+
61
+ def test_response_parsing
62
+ mock_response = xml_fixture('ups/test_real_home_as_residential_destination_response')
63
+ @carrier.expects(:commit).returns(mock_response)
64
+ response = @carrier.find_rates( @locations[:beverly_hills],
65
+ @locations[:real_home_as_residential],
66
+ @packages.values_at(:chocolate_stuff))
67
+ assert_equal [ "UPS Ground",
68
+ "UPS Three-Day Select",
69
+ "UPS Second Day Air",
70
+ "UPS Next Day Air Saver",
71
+ "UPS Next Day Air Early A.M.",
72
+ "UPS Next Day Air"], response.rates.map(&:service_name)
73
+ assert_equal [992, 2191, 3007, 5509, 9401, 6124], response.rates.map(&:price)
74
+ end
75
+
76
+ def test_maximum_weight
77
+ assert Package.new(150 * 16, [5,5,5], :units => :imperial).mass == @carrier.maximum_weight
78
+ assert Package.new((150 * 16) + 0.01, [5,5,5], :units => :imperial).mass > @carrier.maximum_weight
79
+ assert Package.new((150 * 16) - 0.01, [5,5,5], :units => :imperial).mass < @carrier.maximum_weight
80
+ end
81
+ end
@@ -0,0 +1,170 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class USPSTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @packages = TestFixtures.packages
7
+ @locations = TestFixtures.locations
8
+ @carrier = USPS.new(:login => 'login')
9
+ @international_rate_responses = {
10
+ :vanilla => xml_fixture('usps/beverly_hills_to_ottawa_book_rate_response')
11
+ }
12
+
13
+ end
14
+
15
+ # TODO: test_parse_domestic_rate_response
16
+ # TODO: test_build_us_rate_request
17
+ # TODO: test_build_world_rate_request
18
+
19
+ def test_initialize_options_requirements
20
+ assert_raises ArgumentError do USPS.new end
21
+ assert_nothing_raised { USPS.new(:login => 'blah')}
22
+ end
23
+
24
+ def test_parse_international_rate_response
25
+ fixture_xml = @international_rate_responses[:vanilla]
26
+ @carrier.expects(:commit).returns(fixture_xml)
27
+
28
+ response = begin
29
+ @carrier.find_rates(
30
+ @locations[:beverly_hills], # imperial (U.S. origin)
31
+ @locations[:ottawa],
32
+ @packages[:book],
33
+ :test => true
34
+ )
35
+ rescue ResponseError => e
36
+ e.response
37
+ end
38
+
39
+
40
+ expected_xml_hash = Hash.from_xml(fixture_xml)
41
+ actual_xml_hash = Hash.from_xml(response.xml)
42
+
43
+ assert_equal expected_xml_hash, actual_xml_hash
44
+
45
+ assert_not_equal [],response.rates
46
+ assert_equal response.rates.sort_by(&:price), response.rates
47
+ assert_equal ["1", "2", "3", "4", "6", "7", "9"], response.rates.map(&:service_code).sort
48
+
49
+ ordered_service_names = ["USPS Express Mail International (EMS)", "USPS First-Class Mail International", "USPS Global Express Guaranteed", "USPS Global Express Guaranteed Non-Document Non-Rectangular", "USPS Global Express Guaranteed Non-Document Rectangular", "USPS Priority Mail International", "USPS Priority Mail International Flat Rate Box"]
50
+ assert_equal ordered_service_names, response.rates.map(&:service_name).sort
51
+
52
+
53
+ assert_equal [376, 1600, 2300, 2325, 4100, 4100, 4100], response.rates.map(&:total_price)
54
+ end
55
+
56
+ def test_parse_max_dimension_sentences
57
+ limits = {
58
+ "Max. length 46\", width 35\", height 46\" and max. length plus girth 108\"" =>
59
+ [{:length => 46.0, :width => 46.0, :height => 35.0, :length_plus_girth => 108.0}],
60
+ "Max.length 42\", max. length plus girth 79\"" =>
61
+ [{:length => 42.0, :length_plus_girth => 79.0}],
62
+ "9 1/2\" X 12 1/2\"" =>
63
+ [{:length => 12.5, :width => 9.5, :height => 0.75}, "Flat Rate Envelope"],
64
+ "Maximum length and girth combined 108\"" =>
65
+ [{:length_plus_girth => 108.0}],
66
+ "USPS-supplied Priority Mail flat-rate envelope 9 1/2\" x 12 1/2.\" Maximum weight 4 pounds." =>
67
+ [{:length => 12.5, :width => 9.5, :height => 0.75}, "Flat Rate Envelope"],
68
+ "Max. length 24\", Max. length, height, depth combined 36\"" =>
69
+ [{:length => 24.0, :length_plus_width_plus_height => 36.0}]
70
+ }
71
+ p = @packages[:book]
72
+ limits.each do |sentence,hashes|
73
+ dimensions = hashes[0].update(:weight => 50.0)
74
+ service_node = build_service_node(
75
+ :name => hashes[1],
76
+ :max_weight => 50,
77
+ :max_dimensions => sentence )
78
+ @carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions)
79
+ @carrier.send(:package_valid_for_service, p, service_node)
80
+ end
81
+
82
+ service_node = build_service_node(
83
+ :name => "flat-rate box",
84
+ :max_weight => 50,
85
+ :max_dimensions => "USPS-supplied Priority Mail flat-rate box. Maximum weight 20 pounds." )
86
+
87
+ # should test against either kind of flat rate box:
88
+ dimensions = [{:weight => 50.0, :length => 11.0, :width => 8.5, :height => 5.5}, # or...
89
+ {:weight => 50.0, :length => 13.625, :width => 11.875, :height => 3.375}]
90
+ @carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions[0])
91
+ @carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions[1])
92
+ @carrier.send(:package_valid_for_service, p, service_node)
93
+
94
+ end
95
+
96
+ def test_package_valid_for_max_dimensions
97
+ p = Package.new(70 * 16, [10,10,10], :units => :imperial)
98
+ limits = {:weight => 70.0, :length => 10.0, :width => 10.0, :height => 10.0, :length_plus_girth => 50.0, :length_plus_width_plus_height => 30.0}
99
+ assert_equal true, @carrier.send(:package_valid_for_max_dimensions, p, limits)
100
+
101
+ limits.keys.each do |key|
102
+ dimensions = {key => (limits[key] - 1)}
103
+ assert_equal false, @carrier.send(:package_valid_for_max_dimensions, p, dimensions)
104
+ end
105
+
106
+ end
107
+
108
+ def test_strip_9_digit_zip_codes
109
+ request = URI.decode(@carrier.send(:build_us_rate_request, @packages[:book], "90210-1234", "123456789"))
110
+ assert !(request =~ /\>90210-1234\</)
111
+ assert request =~ /\>90210\</
112
+ assert !(request =~ /\>123456789\</)
113
+ assert request =~ /\>12345\</
114
+ end
115
+
116
+ def test_xml_logging_to_file
117
+ mock_response = @international_rate_responses[:vanilla]
118
+ @carrier.expects(:commit).times(2).returns(mock_response)
119
+ @carrier.find_rates(
120
+ @locations[:beverly_hills],
121
+ @locations[:ottawa],
122
+ @packages[:book],
123
+ :test => true
124
+ )
125
+ @carrier.find_rates(
126
+ @locations[:beverly_hills],
127
+ @locations[:ottawa],
128
+ @packages[:book],
129
+ :test => true
130
+ )
131
+ end
132
+
133
+ def test_maximum_weight
134
+ assert Package.new(70 * 16, [5,5,5], :units => :imperial).mass == @carrier.maximum_weight
135
+ assert Package.new((70 * 16) + 0.01, [5,5,5], :units => :imperial).mass > @carrier.maximum_weight
136
+ assert Package.new((70 * 16) - 0.01, [5,5,5], :units => :imperial).mass < @carrier.maximum_weight
137
+ end
138
+
139
+ private
140
+
141
+ def build_service_node(options = {})
142
+ XmlNode.new('Service') do |service_node|
143
+ service_node << XmlNode.new('Pounds', options[:pounds] || "0")
144
+ service_node << XmlNode.new('SvcCommitments', options[:svc_commitments] || "Varies")
145
+ service_node << XmlNode.new('Country', options[:country] || "CANADA")
146
+ service_node << XmlNode.new('ID', options[:id] || "3")
147
+ service_node << XmlNode.new('MaxWeight', options[:max_weight] || "64")
148
+ service_node << XmlNode.new('SvcDescription', options[:name] || "First-Class Mail International")
149
+ service_node << XmlNode.new('MailType', options[:mail_type] || "Package")
150
+ service_node << XmlNode.new('Postage', options[:postage] || "3.76")
151
+ service_node << XmlNode.new('Ounces', options[:ounces] || "9")
152
+ service_node << XmlNode.new('MaxDimensions', options[:max_dimensions] ||
153
+ "Max. length 24\", Max. length, height, depth combined 36\"")
154
+ end.to_xml_element
155
+ end
156
+
157
+ def build_service_hash(options = {})
158
+ {"Pounds"=> options[:pounds] || "0", # 8
159
+ "SvcCommitments"=> options[:svc_commitments] || "Varies",
160
+ "Country"=> options[:country] || "CANADA",
161
+ "ID"=> options[:id] || "3",
162
+ "MaxWeight"=> options[:max_weight] || "64",
163
+ "SvcDescription"=> options[:name] || "First-Class Mail International",
164
+ "MailType"=> options[:mail_type] || "Package",
165
+ "Postage"=> options[:postage] || "3.76",
166
+ "Ounces"=> options[:ounces] || "9",
167
+ "MaxDimensions"=> options[:max_dimensions] ||
168
+ "Max. length 24\", Max. length, height, depth combined 36\""}
169
+ end
170
+ end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class LocationTest < Test::Unit::TestCase
4
+ include ActiveMerchant::Shipping
5
+
6
+ def setup
7
+ @locations = TestFixtures.locations.dup
8
+ end
9
+
10
+ def test_countries
11
+ assert_instance_of ActiveMerchant::Country, @locations[:ottawa].country
12
+ assert_equal 'CA', @locations[:ottawa].country_code(:alpha2)
13
+ end
14
+
15
+ def test_location_from_strange_hash
16
+ hash = { :country => 'CA',
17
+ :zip => '90210',
18
+ :territory_code => 'QC',
19
+ :town => 'Perth',
20
+ :address => '66 Gregory Ave.',
21
+ :phone => '515-555-1212',
22
+ :fax_number => 'none to speak of',
23
+ :address_type => :commercial
24
+ }
25
+ location = Location.from(hash)
26
+
27
+ assert_equal hash[:country], location.country_code(:alpha2)
28
+ assert_equal hash[:zip], location.zip
29
+ assert_equal hash[:territory_code], location.province
30
+ assert_equal hash[:town], location.city
31
+ assert_equal hash[:address], location.address1
32
+ assert_equal hash[:phone], location.phone
33
+ assert_equal hash[:fax_number], location.fax
34
+ assert_equal hash[:address_type].to_s, location.address_type
35
+ end
36
+
37
+ def to_s
38
+ expected = "110 Laurier Avenue West\nOttawa, ON, K1P 1J1\nCanada"
39
+ assert_equal expected, @locations[:ottawa].to_s
40
+ end
41
+
42
+ def test_inspect
43
+ expected = "110 Laurier Avenue West\nOttawa, ON, K1P 1J1\nCanada\nPhone: 1-613-580-2400\nFax: 1-613-580-2495"
44
+ assert_equal expected, @locations[:ottawa].inspect
45
+ end
46
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class PackageTest < Test::Unit::TestCase
4
+
5
+ GRAMS_IN_AN_OUNCE = 28.349523125
6
+ OUNCES_IN_A_GRAM = 0.0352739619495804
7
+ INCHES_IN_A_CM = 0.393700787401575
8
+ CM_IN_AN_INCH = 2.54
9
+
10
+ def setup
11
+ @imperial_package = Package.new(65, [3,6,8.5],
12
+ :units => :imperial,
13
+ :value => 10.65,
14
+ :currency => 'USD'
15
+ )
16
+
17
+ @metric_package = Package.new(100, [5,18.5,40],
18
+ :value => 860,
19
+ :currency => 'CAD'
20
+ )
21
+
22
+ @packages = TestFixtures.packages
23
+ end
24
+
25
+ def test_accessors
26
+ # :wii => Package.new((7.5 * 16), [15, 10, 4.5], :units => :imperial, :value => 269.99, :currency => 'GBP')
27
+ wii = @packages[:wii]
28
+ [:x, :max, :long, :length].each do |sym|
29
+ assert_equal 15, wii.inches(sym)
30
+ assert_equal 15, wii.in(sym)
31
+ assert_equal 15 * CM_IN_AN_INCH, wii.centimetres(sym)
32
+ assert_equal 15 * CM_IN_AN_INCH, wii.cm(sym)
33
+ end
34
+ [:y, :mid, :width, :wide].each do |sym|
35
+ assert_equal 10, wii.inches(sym)
36
+ assert_equal 10, wii.in(sym)
37
+ assert_equal 10 * CM_IN_AN_INCH, wii.centimetres(sym)
38
+ assert_equal 10 * CM_IN_AN_INCH, wii.cm(sym)
39
+ end
40
+ [:z, :min, :height, :high, :depth, :deep].each do |sym|
41
+ assert_equal 4.5, wii.inches(sym)
42
+ assert_equal 4.5, wii.in(sym)
43
+ assert_equal 4.5 * CM_IN_AN_INCH, wii.centimetres(sym)
44
+ assert_equal 4.5 * CM_IN_AN_INCH, wii.cm(sym)
45
+ end
46
+ [:pounds, :lbs, :lb].each do |sym|
47
+ assert_equal 7.5, wii.send(sym)
48
+ end
49
+ [:ounces, :oz].each do |sym|
50
+ assert_equal 120, wii.send(sym)
51
+ end
52
+ [:grams, :g].each do |sym|
53
+ assert_equal 120 * GRAMS_IN_AN_OUNCE, wii.send(sym)
54
+ end
55
+ [:kilograms, :kgs, :kg].each do |sym|
56
+ assert_equal 120 * GRAMS_IN_AN_OUNCE / 1000, wii.send(sym)
57
+ end
58
+ assert_equal 675.0, wii.inches(:volume)
59
+ assert_equal 675.0, wii.inches(:box_volume)
60
+
61
+
62
+ assert_equal 'GBP', wii.currency
63
+ assert_equal 26999, wii.value
64
+ end
65
+ end