active_shipping 1.0.0.pre2 → 1.0.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +12 -0
- data/.travis.yml +14 -0
- data/.yardopts +14 -0
- data/Gemfile +3 -0
- data/Gemfile.activesupport32 +4 -0
- data/Gemfile.activesupport40 +4 -0
- data/Gemfile.activesupport41 +4 -0
- data/Gemfile.activesupport42 +4 -0
- data/Rakefile +23 -0
- data/active_shipping.gemspec +32 -0
- data/lib/active_shipping.rb +1 -1
- data/lib/active_shipping/carrier.rb +1 -1
- data/lib/active_shipping/carriers/shipwire.rb +32 -35
- data/lib/active_shipping/carriers/ups.rb +2 -2
- data/lib/active_shipping/carriers/usps.rb +103 -101
- data/lib/active_shipping/label_response.rb +1 -1
- data/lib/active_shipping/rate_estimate.rb +76 -15
- data/lib/active_shipping/rate_response.rb +20 -0
- data/lib/active_shipping/response.rb +17 -0
- data/lib/active_shipping/shipment_packer.rb +2 -2
- data/lib/active_shipping/shipping_response.rb +24 -2
- data/lib/active_shipping/tracking_response.rb +65 -17
- data/lib/active_shipping/version.rb +1 -1
- data/shipit.rubygems.yml +1 -0
- data/test/credentials.yml +47 -0
- data/test/fixtures/files/label1.pdf +0 -0
- data/test/fixtures/files/ups-shipping-label.gif +0 -0
- data/test/fixtures/json/newzealandpost/domestic_book.json +1 -0
- data/test/fixtures/json/newzealandpost/domestic_default.json +1 -0
- data/test/fixtures/json/newzealandpost/domestic_error.json +1 -0
- data/test/fixtures/json/newzealandpost/domestic_poster.json +1 -0
- data/test/fixtures/json/newzealandpost/domestic_small_half_pound.json +1 -0
- data/test/fixtures/json/newzealandpost/international_book.json +1 -0
- data/test/fixtures/json/newzealandpost/international_new_zealand_wii.json +1 -0
- data/test/fixtures/json/newzealandpost/international_small_half_pound.json +1 -0
- data/test/fixtures/json/newzealandpost/international_wii.json +1 -0
- data/test/fixtures/xml/canadapost/example_request.xml +25 -0
- data/test/fixtures/xml/canadapost/example_response.xml +130 -0
- data/test/fixtures/xml/canadapost/example_response_error.xml +16 -0
- data/test/fixtures/xml/canadapost/example_response_french.xml +122 -0
- data/test/fixtures/xml/canadapost/example_response_with_nil_value.xml +164 -0
- data/test/fixtures/xml/canadapost/example_response_with_postal_outlet.xml +155 -0
- data/test/fixtures/xml/canadapost/example_response_with_postal_outlet_french.xml +274 -0
- data/test/fixtures/xml/canadapost/example_response_with_strange_delivery_date.xml +130 -0
- data/test/fixtures/xml/canadapost_pws/dnc_tracking_details_en.xml +112 -0
- data/test/fixtures/xml/canadapost_pws/merchant_details_error.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/merchant_details_response.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/option_response.xml +13 -0
- data/test/fixtures/xml/canadapost_pws/option_response_no_conflicts.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/rates_info.xml +190 -0
- data/test/fixtures/xml/canadapost_pws/rates_info_error.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/receipt_response.xml +42 -0
- data/test/fixtures/xml/canadapost_pws/receipt_response_no_priced_options.xml +36 -0
- data/test/fixtures/xml/canadapost_pws/register_token_error.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/register_token_response.xml +3 -0
- data/test/fixtures/xml/canadapost_pws/service_options_response.xml +42 -0
- data/test/fixtures/xml/canadapost_pws/services_error.xml +6 -0
- data/test/fixtures/xml/canadapost_pws/services_response.xml +32 -0
- data/test/fixtures/xml/canadapost_pws/shipment_domestic.xml +69 -0
- data/test/fixtures/xml/canadapost_pws/shipment_response.xml +20 -0
- data/test/fixtures/xml/canadapost_pws/shipment_us.xml +69 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_en.xml +152 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_en_error.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_en_undelivered.xml +116 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_fr.xml +156 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_no_expected_delivery_date.xml +40 -0
- data/test/fixtures/xml/fedex/freight_rate_request.xml +82 -0
- data/test/fixtures/xml/fedex/freight_rate_response.xml +506 -0
- data/test/fixtures/xml/fedex/invalid_fedex_reply.xml +27 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_commercial_rate_request.xml +79 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_request.xml +80 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_response.xml +214 -0
- data/test/fixtures/xml/fedex/raterequest_reply.xml +213 -0
- data/test/fixtures/xml/fedex/reply_without_notifications.xml +185 -0
- data/test/fixtures/xml/fedex/tracking_request.xml +27 -0
- data/test/fixtures/xml/fedex/tracking_response.xml +151 -0
- data/test/fixtures/xml/fedex/tracking_response_empty_destination.xml +76 -0
- data/test/fixtures/xml/fedex/tracking_response_no_destination.xml +139 -0
- data/test/fixtures/xml/fedex/tracking_response_no_ship_time.xml +150 -0
- data/test/fixtures/xml/fedex/tracking_response_with_estimated_delivery_date.xml +95 -0
- data/test/fixtures/xml/fedex/tracking_response_with_shipper_address.xml +71 -0
- data/test/fixtures/xml/fedex/unknown_fedex_document_reply.xml +3 -0
- data/test/fixtures/xml/kunaki/invalid_state_response.xml +3 -0
- data/test/fixtures/xml/kunaki/no_valid_items_response.xml +3 -0
- data/test/fixtures/xml/kunaki/successful_rates_response.xml +3 -0
- data/test/fixtures/xml/kunaki/unsuccessful_rates_response.xml +9 -0
- data/test/fixtures/xml/shipwire/international_rates_response.xml +17 -0
- data/test/fixtures/xml/shipwire/new_carrier_rate_response.xml +18 -0
- data/test/fixtures/xml/shipwire/no_rates_response.xml +7 -0
- data/test/fixtures/xml/shipwire/rates_response.xml +36 -0
- data/test/fixtures/xml/shipwire/rates_response_no_estimate.xml +14 -0
- data/test/fixtures/xml/stamps/authenticate_user_request.xml +15 -0
- data/test/fixtures/xml/stamps/authenticate_user_response.xml +10 -0
- data/test/fixtures/xml/stamps/cleanse_address_request.xml +19 -0
- data/test/fixtures/xml/stamps/cleanse_address_response.xml +27 -0
- data/test/fixtures/xml/stamps/create_indicium_request.xml +69 -0
- data/test/fixtures/xml/stamps/create_indicium_response.xml +40 -0
- data/test/fixtures/xml/stamps/expired_authenticator_response.xml +15 -0
- data/test/fixtures/xml/stamps/get_account_info_request.xml +11 -0
- data/test/fixtures/xml/stamps/get_account_info_response.xml +36 -0
- data/test/fixtures/xml/stamps/get_purchase_status_request.xml +12 -0
- data/test/fixtures/xml/stamps/get_purchase_status_response.xml +16 -0
- data/test/fixtures/xml/stamps/get_rates_request.xml +19 -0
- data/test/fixtures/xml/stamps/get_rates_response.xml +351 -0
- data/test/fixtures/xml/stamps/purchase_postage_request.xml +13 -0
- data/test/fixtures/xml/stamps/purchase_postage_response.xml +17 -0
- data/test/fixtures/xml/stamps/track_shipment_request.xml +12 -0
- data/test/fixtures/xml/stamps/track_shipment_response.xml +45 -0
- data/test/fixtures/xml/ups/delivered_shipment_with_refund.xml +290 -0
- data/test/fixtures/xml/ups/delivered_shipment_without_events_tracking_response.xml +62 -0
- data/test/fixtures/xml/ups/example_tracking_response.xml +53 -0
- data/test/fixtures/xml/ups/in_transit_shipment.xml +183 -0
- data/test/fixtures/xml/ups/out_for_delivery_shipment.xml +165 -0
- data/test/fixtures/xml/ups/shipment_accept_response.xml +42 -0
- data/test/fixtures/xml/ups/shipment_confirm_response.xml +33 -0
- data/test/fixtures/xml/ups/shipment_from_tiger_direct.xml +222 -0
- data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response.xml +1 -0
- data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response_with_insured.xml +289 -0
- data/test/fixtures/xml/ups/test_real_home_as_residential_destination_with_origin_account_response.xml +311 -0
- data/test/fixtures/xml/ups/triple_accept_response.xml +72 -0
- data/test/fixtures/xml/ups/triple_confirm_response.xml +32 -0
- data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_base_rate_response.xml +2 -0
- data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_plus_rate_response.xml +258 -0
- data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_rate_response.xml +108 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_base_rate_response.xml +84 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_plus_rate_response.xml +212 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_rate_response.xml +230 -0
- data/test/fixtures/xml/usps/delivered_tracking_response.xml +11 -0
- data/test/fixtures/xml/usps/first_class_packages_with_invalid_mail_type_response.xml +12 -0
- data/test/fixtures/xml/usps/first_class_packages_with_mail_type_response.xml +16 -0
- data/test/fixtures/xml/usps/first_class_packages_without_mail_type_response.xml +12 -0
- data/test/fixtures/xml/usps/invalid_xml_tracking_response_error.xml +2 -0
- data/test/fixtures/xml/usps/tracking_request.xml +3 -0
- data/test/fixtures/xml/usps/tracking_response.xml +13 -0
- data/test/fixtures/xml/usps/tracking_response_failure.xml +3 -0
- data/test/fixtures/xml/usps/tracking_response_not_available.xml +12 -0
- data/test/fixtures/xml/usps/tracking_response_test_error.xml +8 -0
- data/test/fixtures/xml/usps/us_rate_request.xml +18 -0
- data/test/fixtures/xml/usps/world_rate_request_with_value.xml +20 -0
- data/test/fixtures/xml/usps/world_rate_request_without_value.xml +20 -0
- data/test/remote/canada_post_pws_platform_test.rb +246 -0
- data/test/remote/canada_post_pws_test.rb +171 -0
- data/test/remote/canada_post_test.rb +53 -0
- data/test/remote/fedex_test.rb +216 -0
- data/test/remote/kunaki_test.rb +36 -0
- data/test/remote/new_zealand_post_test.rb +147 -0
- data/test/remote/shipwire_test.rb +82 -0
- data/test/remote/stamps_test.rb +394 -0
- data/test/remote/ups_test.rb +257 -0
- data/test/remote/usps_test.rb +235 -0
- data/test/test_helper.rb +220 -0
- data/test/unit/carriers/benchmark_test.rb +18 -0
- data/test/unit/carriers/canada_post_pws_rating_test.rb +349 -0
- data/test/unit/carriers/canada_post_pws_register_test.rb +75 -0
- data/test/unit/carriers/canada_post_pws_shipping_test.rb +244 -0
- data/test/unit/carriers/canada_post_pws_tracking_test.rb +154 -0
- data/test/unit/carriers/canada_post_test.rb +145 -0
- data/test/unit/carriers/fedex_test.rb +408 -0
- data/test/unit/carriers/kunaki_test.rb +52 -0
- data/test/unit/carriers/new_zealand_post_test.rb +174 -0
- data/test/unit/carriers/shipwire_test.rb +187 -0
- data/test/unit/carriers/stamps_test.rb +241 -0
- data/test/unit/carriers/ups_test.rb +311 -0
- data/test/unit/carriers/usps_test.rb +484 -0
- data/test/unit/carriers_test.rb +17 -0
- data/test/unit/label_response_test.rb +15 -0
- data/test/unit/location_test.rb +138 -0
- data/test/unit/package_test.rb +68 -0
- data/test/unit/rate_estimate_test.rb +34 -0
- data/test/unit/response_test.rb +14 -0
- data/test/unit/shipment_packer_test.rb +174 -0
- metadata +331 -35
- metadata.gz.sig +0 -0
- data/lib/vendor/quantified/MIT-LICENSE +0 -22
- data/lib/vendor/quantified/README.markdown +0 -49
- data/lib/vendor/quantified/Rakefile +0 -13
- data/lib/vendor/quantified/init.rb +0 -0
- data/lib/vendor/quantified/lib/quantified.rb +0 -6
- data/lib/vendor/quantified/lib/quantified/attribute.rb +0 -211
- data/lib/vendor/quantified/lib/quantified/length.rb +0 -20
- data/lib/vendor/quantified/lib/quantified/mass.rb +0 -19
- data/lib/vendor/quantified/test/length_test.rb +0 -94
- data/lib/vendor/quantified/test/mass_test.rb +0 -96
- data/lib/vendor/quantified/test/test_helper.rb +0 -19
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CarriersTest < Minitest::Test
|
4
|
+
|
5
|
+
def test_get_usps_by_string
|
6
|
+
assert_equal ActiveShipping::USPS, ActiveShipping::Carriers.find('usps')
|
7
|
+
assert_equal ActiveShipping::USPS, ActiveShipping::Carriers.find('USPS')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_get_usps_by_name
|
11
|
+
assert_equal ActiveShipping::USPS, ActiveShipping::Carriers.find(:usps)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_unknown_carrier
|
15
|
+
assert_raises(NameError) { ActiveShipping::Carriers.find(:polar_north) }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LabelResponseTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def test_build_label_from_xml_response
|
7
|
+
str = xml_fixture('ups/shipment_accept_response')
|
8
|
+
mapping = Hash.from_xml(str).values.first
|
9
|
+
response = LabelResponse.new(true, nil, mapping)
|
10
|
+
|
11
|
+
assert_equal 1, response.labels.count
|
12
|
+
assert_equal '1ZA03R691591538440', response.labels.first[:tracking_number]
|
13
|
+
assert response.labels.first[:image]
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocationTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def test_countries
|
7
|
+
assert_instance_of ActiveUtils::Country, location_fixtures[:ottawa].country
|
8
|
+
assert_equal 'CA', location_fixtures[:ottawa].country_code(:alpha2)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_location_from_strange_hash
|
12
|
+
hash = { :country => 'CA',
|
13
|
+
:zip => '90210',
|
14
|
+
:territory_code => 'QC',
|
15
|
+
:town => 'Perth',
|
16
|
+
:address => '66 Gregory Ave.',
|
17
|
+
:phone => '515-555-1212',
|
18
|
+
:fax_number => 'none to speak of',
|
19
|
+
:address_type => :commercial
|
20
|
+
}
|
21
|
+
location = Location.from(hash)
|
22
|
+
|
23
|
+
assert_equal hash[:country], location.country_code(:alpha2)
|
24
|
+
assert_equal hash[:zip], location.zip
|
25
|
+
assert_equal hash[:territory_code], location.province
|
26
|
+
assert_equal hash[:town], location.city
|
27
|
+
assert_equal hash[:address], location.address1
|
28
|
+
assert_equal hash[:phone], location.phone
|
29
|
+
assert_equal hash[:fax_number], location.fax
|
30
|
+
assert_equal hash[:address_type].to_s, location.address_type
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_pretty_print
|
34
|
+
expected = "110 Laurier Avenue West\nOttawa, ON, K1P 1J1\nCanada"
|
35
|
+
assert_equal expected, location_fixtures[:ottawa].prettyprint
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_to_s
|
39
|
+
expected = "110 Laurier Avenue West Ottawa, ON, K1P 1J1 Canada"
|
40
|
+
assert_equal expected, location_fixtures[:ottawa].to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_inspect
|
44
|
+
expected = "110 Laurier Avenue West\nOttawa, ON, K1P 1J1\nCanada\nPhone: 1-613-580-2400\nFax: 1-613-580-2495"
|
45
|
+
assert_equal expected, location_fixtures[:ottawa].inspect
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_includes_name
|
49
|
+
location = Location.from(:name => "Bob Bobsen")
|
50
|
+
assert_equal "Bob Bobsen", location.name
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_name_is_nil_if_not_provided
|
54
|
+
location = Location.from({})
|
55
|
+
assert_nil location.name
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_location_with_company_name
|
59
|
+
location = Location.from(:company => "Mine")
|
60
|
+
assert_equal "Mine", location.company_name
|
61
|
+
|
62
|
+
location = Location.from(:company_name => "Mine")
|
63
|
+
assert_equal "Mine", location.company_name
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_set_address_type
|
67
|
+
location = location_fixtures[:ottawa]
|
68
|
+
assert !location.commercial?
|
69
|
+
|
70
|
+
location.address_type = :commercial
|
71
|
+
assert location.commercial?
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_set_address_type_invalid
|
75
|
+
location = location_fixtures[:ottawa]
|
76
|
+
|
77
|
+
assert_raises(ArgumentError) do
|
78
|
+
location.address_type = :new_address_type
|
79
|
+
end
|
80
|
+
|
81
|
+
refute_equal "new_address_type", location.address_type
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_to_hash_attributes
|
85
|
+
assert_equal %w(address1 address2 address3 address_type city company_name country fax name phone postal_code province), location_fixtures[:ottawa].to_hash.stringify_keys.keys.sort
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_to_json
|
89
|
+
location_json = location_fixtures[:ottawa].to_json
|
90
|
+
assert_equal location_fixtures[:ottawa].to_hash, JSON.parse(location_json).symbolize_keys
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_default_to_xml
|
94
|
+
location_xml = location_fixtures[:ottawa].to_xml
|
95
|
+
assert_equal location_fixtures[:ottawa].to_hash, Hash.from_xml(location_xml)["location"].symbolize_keys
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_custom_root_to_xml
|
99
|
+
location_xml = location_fixtures[:ottawa].to_xml(:root => "destination")
|
100
|
+
assert_equal location_fixtures[:ottawa].to_hash, Hash.from_xml(location_xml)["destination"].symbolize_keys
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_zip_plus_4_with_no_dash
|
104
|
+
zip = "33333"
|
105
|
+
plus_4 = "1234"
|
106
|
+
zip_plus_4 = "#{zip}-#{plus_4}"
|
107
|
+
location = Location.from(:zip => "#{zip}#{plus_4}")
|
108
|
+
assert_equal zip_plus_4, location.zip_plus_4
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_zip_plus_4_with_dash
|
112
|
+
zip = "33333"
|
113
|
+
plus_4 = "1234"
|
114
|
+
zip_plus_4 = "#{zip}-#{plus_4}"
|
115
|
+
location = Location.from(:zip => zip_plus_4)
|
116
|
+
assert_equal zip_plus_4, location.zip_plus_4
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_address2_and_3_is_nil
|
120
|
+
location = location_fixtures[:ottawa]
|
121
|
+
assert_nil location.address2
|
122
|
+
assert_nil location.address3
|
123
|
+
assert location.address2_and_3.blank?
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_address2_and_3
|
127
|
+
address2 = 'Apt 613'
|
128
|
+
address3 = 'Victory Lane'
|
129
|
+
location = Location.from(:address2 => address2)
|
130
|
+
assert_equal 'Apt 613', location.address2_and_3
|
131
|
+
|
132
|
+
location = Location.from(:address2 => address2, :address3 => address3)
|
133
|
+
assert_equal 'Apt 613, Victory Lane', location.address2_and_3
|
134
|
+
|
135
|
+
location = Location.from(:address3 => address3)
|
136
|
+
assert_equal 'Victory Lane', location.address2_and_3
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PackageTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
GRAMS_IN_AN_OUNCE = 28.349523125
|
7
|
+
OUNCES_IN_A_GRAM = 0.0352739619495804
|
8
|
+
INCHES_IN_A_CM = 0.393700787401575
|
9
|
+
CM_IN_AN_INCH = 2.54
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@imperial_package = Package.new(65, [3, 6, 8.5],
|
13
|
+
:units => :imperial,
|
14
|
+
:value => 10.65,
|
15
|
+
:currency => 'USD'
|
16
|
+
)
|
17
|
+
|
18
|
+
@metric_package = Package.new(100, [5, 18.5, 40],
|
19
|
+
:value => 860,
|
20
|
+
:currency => 'CAD'
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_accessors
|
25
|
+
# :wii => Package.new((7.5 * 16), [15, 10, 4.5], :units => :imperial, :value => 269.99, :currency => 'GBP')
|
26
|
+
wii = package_fixtures[:wii]
|
27
|
+
[:x, :max, :long, :length].each do |sym|
|
28
|
+
assert_equal 15, wii.inches(sym)
|
29
|
+
assert_equal 15, wii.in(sym)
|
30
|
+
assert_equal 15 * CM_IN_AN_INCH, wii.centimetres(sym)
|
31
|
+
assert_equal 15 * CM_IN_AN_INCH, wii.cm(sym)
|
32
|
+
end
|
33
|
+
[:y, :mid, :width, :wide].each do |sym|
|
34
|
+
assert_equal 10, wii.inches(sym)
|
35
|
+
assert_equal 10, wii.in(sym)
|
36
|
+
assert_equal 10 * CM_IN_AN_INCH, wii.centimetres(sym)
|
37
|
+
assert_equal 10 * CM_IN_AN_INCH, wii.cm(sym)
|
38
|
+
end
|
39
|
+
[:z, :min, :height, :high, :depth, :deep].each do |sym|
|
40
|
+
assert_equal 4.5, wii.inches(sym)
|
41
|
+
assert_equal 4.5, wii.in(sym)
|
42
|
+
assert_equal 4.5 * CM_IN_AN_INCH, wii.centimetres(sym)
|
43
|
+
assert_equal 4.5 * CM_IN_AN_INCH, wii.cm(sym)
|
44
|
+
end
|
45
|
+
[:pounds, :lbs, :lb].each do |sym|
|
46
|
+
assert_equal 7.5, wii.send(sym)
|
47
|
+
end
|
48
|
+
[:ounces, :oz].each do |sym|
|
49
|
+
assert_equal 120, wii.send(sym)
|
50
|
+
end
|
51
|
+
[:grams, :g].each do |sym|
|
52
|
+
assert_equal 120 * GRAMS_IN_AN_OUNCE, wii.send(sym)
|
53
|
+
end
|
54
|
+
[:kilograms, :kgs, :kg].each do |sym|
|
55
|
+
assert_equal 120 * GRAMS_IN_AN_OUNCE / 1000, wii.send(sym)
|
56
|
+
end
|
57
|
+
assert_equal 675.0, wii.inches(:volume)
|
58
|
+
assert_equal 675.0, wii.inches(:box_volume)
|
59
|
+
|
60
|
+
assert_equal 'GBP', wii.currency
|
61
|
+
assert_equal 26999, wii.value
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_package_from_mass
|
65
|
+
pkg = Package.new(Quantified::Mass.new(10, :pounds), [])
|
66
|
+
assert_equal 10, pkg.weight
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RateEstimateTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Credentials
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@origin = {:address1 => "61A York St", :city => "Ottawa", :province => "ON", :country => "Canada", :postal_code => "K1N 5T2"}
|
8
|
+
@destination = {:city => "Beverly Hills", :state => "CA", :country => "United States", :postal_code => "90210"}
|
9
|
+
@line_items = [Package.new(500, [2, 3, 4], :description => "a box full of stuff", :value => 2500)]
|
10
|
+
@carrier = CanadaPost.new(credentials(:canada_post))
|
11
|
+
@options = {:currency => 'USD'}
|
12
|
+
|
13
|
+
@rate_estimate = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_date_for_nil_string
|
17
|
+
assert_nil @rate_estimate.send(:date_for, nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_date_for_invalid_string_in_ruby_19
|
21
|
+
assert_nil @rate_estimate.send(:date_for, "Up to 2 weeks") if RUBY_VERSION.include?('1.9')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_rate_estimate_converts_noniso_to_iso
|
25
|
+
rate_estimate = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(:currency => 'UKL'))
|
26
|
+
assert_equal 'GBP', rate_estimate.currency
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_creating_an_estimate_with_an_invalid_currency_raises
|
30
|
+
assert_raises(ActiveUtils::InvalidCurrencyCodeError) do
|
31
|
+
RateEstimate.new(nil, nil, nil, nil, :currency => 'FAKE')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ResponseTest < Minitest::Test
|
4
|
+
def test_initialize_success
|
5
|
+
response = RateResponse.new(true, "success!", {:rate => 'Free!'}, :rates => [stub(:service_name => 'Free!', :total_price => 0)], :xml => "<rate>Free!</rate>")
|
6
|
+
assert response.success?
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_initialize_failure
|
10
|
+
assert_raises(ActiveShipping::ResponseError) do
|
11
|
+
RateResponse.new(false, "fail!", {:rate => 'Free!'}, :rates => [stub(:service_name => 'Free!', :total_price => 0)], :xml => "<rate>Free!</rate>")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ShipmentPackerTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@dimensions = [5.1, 15.2, 30.5]
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_pack_divide_order_into_a_single_package
|
9
|
+
items = [{:grams => 1, :quantity => 1, :price => 1.0}]
|
10
|
+
|
11
|
+
packages = ShipmentPacker.pack(items, @dimensions, 1, 'USD')
|
12
|
+
assert_equal 1, packages.size
|
13
|
+
|
14
|
+
package = packages.first
|
15
|
+
assert_equal 1, package.weight
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_divide_order_with_multiple_lines_into_a_single_package
|
19
|
+
items = [{:grams => 1, :quantity => 2, :price => 1.0}]
|
20
|
+
|
21
|
+
packages = ShipmentPacker.pack(items, @dimensions, 2, 'USD')
|
22
|
+
assert_equal 1, packages.size
|
23
|
+
|
24
|
+
package = packages.first
|
25
|
+
assert_equal 2, package.weight
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_divide_order_with_single_line_into_two_packages
|
29
|
+
items = [{:grams => 1, :quantity => 2, :price => 1.0}]
|
30
|
+
|
31
|
+
packages = ShipmentPacker.pack(items, @dimensions, 1, 'USD')
|
32
|
+
assert_equal 2, packages.size
|
33
|
+
|
34
|
+
packages.each do |package|
|
35
|
+
assert_equal 1, package.weight
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_divide_order_with_multiple_lines_into_two_packages
|
40
|
+
items = [
|
41
|
+
{:grams => 1, :quantity => 1, :price => 1.0},
|
42
|
+
{:grams => 1, :quantity => 1, :price => 1.0}
|
43
|
+
]
|
44
|
+
|
45
|
+
packages = ShipmentPacker.pack(items, @dimensions, 1, 'USD')
|
46
|
+
assert_equal 2, packages.size
|
47
|
+
|
48
|
+
packages.each do |package|
|
49
|
+
assert_equal 1, package.weight
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_divide_order_into_two_packages_mixing_line_items
|
54
|
+
items = [
|
55
|
+
{:grams => 1, :quantity => 1, :price => 1.0},
|
56
|
+
{:grams => 1, :quantity => 1, :price => 1.0},
|
57
|
+
{:grams => 1, :quantity => 1, :price => 1.0}
|
58
|
+
]
|
59
|
+
|
60
|
+
packages = ShipmentPacker.pack(items, @dimensions, 2, 'USD')
|
61
|
+
assert_equal 2, packages.size
|
62
|
+
|
63
|
+
assert_equal 2, packages[0].weight
|
64
|
+
assert_equal 1, packages[1].weight
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_raise_overweight_exception_when_a_single_item_exceeds_the_maximum_weight_of_a_package
|
68
|
+
assert_raises(ShipmentPacker::OverweightItem) do
|
69
|
+
items = [{:grams => 2, :quantity => 1, :price => 1.0}]
|
70
|
+
ShipmentPacker.pack(items, @dimensions, 1, 'USD')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_raise_over_weight_exceptions_before_over_package_limit_exceptions
|
75
|
+
assert_raises(ShipmentPacker::OverweightItem) do
|
76
|
+
items = [{:grams => 5, :quantity => ShipmentPacker::EXCESS_PACKAGE_QUANTITY_THRESHOLD + 1, :price => 1.0}]
|
77
|
+
ShipmentPacker.pack(items, @dimensions, 4, 'USD')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_returns_an_empty_list_when_no_items_provided
|
82
|
+
assert_equal [], ShipmentPacker.pack([], @dimensions, 1, 'USD')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_add_summarized_prices_for_all_items_and_currency_to_package
|
86
|
+
items = [
|
87
|
+
{:grams => 1, :quantity => 3, :price => 1.0},
|
88
|
+
{:grams => 2, :quantity => 1, :price => 2.0}
|
89
|
+
]
|
90
|
+
packages = ShipmentPacker.pack(items, @dimensions, 5, 'USD')
|
91
|
+
assert_equal 1, packages.size
|
92
|
+
assert_equal 500, packages.first.value
|
93
|
+
assert_equal 'USD', packages.first.currency
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_divide_items_and_prices_accordingly_when_splitting_into_two_packages
|
97
|
+
items = [
|
98
|
+
{:grams => 1, :quantity => 1, :price => 1.0},
|
99
|
+
{:grams => 1, :quantity => 1, :price => 1.0},
|
100
|
+
{:grams => 1, :quantity => 1, :price => 1.0}
|
101
|
+
]
|
102
|
+
|
103
|
+
packages = ShipmentPacker.pack(items, @dimensions, 2, 'USD')
|
104
|
+
assert_equal 2, packages.size
|
105
|
+
|
106
|
+
assert_equal 200, packages[0].value
|
107
|
+
assert_equal 100, packages[1].value
|
108
|
+
assert_equal 'USD', packages[0].currency
|
109
|
+
assert_equal 'USD', packages[1].currency
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_symbolize_item_keys
|
113
|
+
string_key_items = [{'grams' => 1, 'quantity' => 1, 'price' => 1.0}]
|
114
|
+
indifferent_access_items = [{'grams' => 1, 'quantity' => 1, 'price' => 1.0}.with_indifferent_access]
|
115
|
+
|
116
|
+
[string_key_items, indifferent_access_items].each do |items|
|
117
|
+
packages = ShipmentPacker.pack(items, @dimensions, 1, 'USD')
|
118
|
+
assert_equal 1, packages.size
|
119
|
+
|
120
|
+
package = packages.first
|
121
|
+
assert_equal 1, package.weight
|
122
|
+
assert_equal 100, package.value
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_cast_quantity_and_grams_to_int
|
127
|
+
items = [{:grams => '1', :quantity => '1', :price => '1.0'}]
|
128
|
+
|
129
|
+
packages = ShipmentPacker.pack(items, @dimensions, 1, 'USD')
|
130
|
+
|
131
|
+
package = packages.first
|
132
|
+
assert_equal 1, package.weight
|
133
|
+
assert_equal 100, package.value
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_excess_packages
|
137
|
+
assert_raises(ShipmentPacker::ExcessPackageQuantity) do
|
138
|
+
items = [{:grams => 1, :quantity => ShipmentPacker::EXCESS_PACKAGE_QUANTITY_THRESHOLD + 1, :price => 1.0}]
|
139
|
+
ShipmentPacker.pack(items, @dimensions, 1, 'USD')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_lots_of_zero_weight_items
|
144
|
+
items = [{:grams => 0, :quantity => 1_000_000, :price => 1.0}]
|
145
|
+
packages = ShipmentPacker.pack(items, @dimensions, 1, 'USD')
|
146
|
+
|
147
|
+
assert_equal 1, packages.size
|
148
|
+
assert_equal 0, packages[0].grams
|
149
|
+
assert_equal 100_000_000, packages[0].value
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_dont_destroy_input_items
|
153
|
+
items = [{:grams => 1, :quantity => 5, :price => 1.0}]
|
154
|
+
|
155
|
+
packages = ShipmentPacker.pack(items, @dimensions, 10, 'USD')
|
156
|
+
|
157
|
+
assert_equal 1, items.size
|
158
|
+
assert_equal 1, packages.size
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_dont_modify_input_item_quantities
|
162
|
+
items = [{:grams => 1, :quantity => 5, :price => 1.0}]
|
163
|
+
|
164
|
+
ShipmentPacker.pack(items, @dimensions, 10, 'USD')
|
165
|
+
assert_equal 5, items.first[:quantity]
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_items_with_negative_weight
|
169
|
+
items = [{:grams => -1, :quantity => 5, :price => 1.0}]
|
170
|
+
|
171
|
+
ShipmentPacker.pack(items, @dimensions, 10, 'USD')
|
172
|
+
assert_equal 5, items.first[:quantity]
|
173
|
+
end
|
174
|
+
end
|