Skip to content

Commit

Permalink
update USPS size code classification
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmacaulay committed Apr 25, 2011
1 parent 3783265 commit eff4603
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 4 additions & 7 deletions lib/active_shipping/shipping/carriers/usps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,10 @@ class USPS < Carrier
}

def self.size_code_for(package)
total = package.inches(:length) + package.inches(:girth)
if total <= 84
return 'REGULAR'
elsif total <= 108
return 'LARGE'
else # <= 130
return 'OVERSIZE'
if package.inches(:max) <= 12
'REGULAR'
else
'LARGE'
end
end

Expand Down
8 changes: 7 additions & 1 deletion test/unit/carriers/usps_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ def setup
@carrier = USPS.new(:login => 'login')
end

def test_size_codes
assert_equal 'REGULAR', USPS.size_code_for(Package.new(2, [1,12,1], :units => :imperial))
assert_equal 'LARGE', USPS.size_code_for(Package.new(2, [12.1,1,1], :units => :imperial))
assert_equal 'LARGE', USPS.size_code_for(Package.new(2, [1000,1000,1000], :units => :imperial))
end

# TODO: test_parse_domestic_rate_response
# TODO: test_build_us_rate_request

Expand All @@ -19,7 +25,7 @@ def test_build_world_rate_request
end

def test_build_world_rate_request_with_package_value
expected_request = "<IntlRateV2Request USERID='login'><Package ID='0'><Pounds>0</Pounds><Ounces>120</Ounces><MailType>Package</MailType><GXG><POBoxFlag>N</POBoxFlag><GiftFlag>N</GiftFlag></GXG><ValueOfContents>269.99</ValueOfContents><Country><![CDATA[Canada]]></Country><Container>RECTANGULAR</Container><Size>REGULAR</Size><Width>10.00</Width><Length>15.00</Length><Height>4.50</Height><Girth>29.00</Girth></Package></IntlRateV2Request>"
expected_request = "<IntlRateV2Request USERID='login'><Package ID='0'><Pounds>0</Pounds><Ounces>120</Ounces><MailType>Package</MailType><GXG><POBoxFlag>N</POBoxFlag><GiftFlag>N</GiftFlag></GXG><ValueOfContents>269.99</ValueOfContents><Country><![CDATA[Canada]]></Country><Container>RECTANGULAR</Container><Size>LARGE</Size><Width>10.00</Width><Length>15.00</Length><Height>4.50</Height><Girth>29.00</Girth></Package></IntlRateV2Request>"
@carrier.expects(:commit).with(:world_rates, URI.encode(expected_request), false).returns(expected_request)
@carrier.expects(:parse_rate_response)
@carrier.find_rates(@locations[:beverly_hills], @locations[:ottawa], @packages[:american_wii], :test => true)
Expand Down

0 comments on commit eff4603

Please sign in to comment.