Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody Fauser committed Mar 27, 2009
2 parents 418aa28 + e270b17 commit d89662c
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
* Fix extra slash in UPS endpoints [cody]
* Add name to Shipwire class [cody]
* Improve FedEx handling of some error conditions [cody]
* Add support for validating credentials to Shipwire [cody]
* Add support for ssl_get to PostsData. Update Carriers to use PostsData module. Turn on retry safety for carriers [cody]
* Add support for Shipwire Shipping Rate API [cody]
Expand Down
12 changes: 8 additions & 4 deletions lib/active_shipping/shipping/carriers/fedex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def build_location_node(name, location)
location_node = XmlNode.new(name) do |xml_node|
xml_node << XmlNode.new('StateOrProvinceCode', location.state)
xml_node << XmlNode.new('PostalCode', location.postal_code)
xml_node << XmlNode.new("CountryCode", location.country_code(:alpha2)) unless location.country_code(:alpha2).blank?
xml_node << XmlNode.new("CountryCode", location.country_code(:alpha2))
end
end

Expand All @@ -181,6 +181,11 @@ def parse_rate_response(origin, destination, packages, response, options)
:packages => packages)
end

if rate_estimates.empty?
success = false
message = "No shipping rates could be found for the destination address" if message.blank?
end

RateResponse.new(success, message, Hash.from_xml(response), :rates => rate_estimates, :xml => response, :request => last_request, :log_xml => options[:log_xml])
end

Expand Down Expand Up @@ -234,7 +239,8 @@ def parse_tracking_response(response, options)
:request => last_request,
:shipment_events => shipment_events,
:destination => destination,
:tracking_number => tracking_number)
:tracking_number => tracking_number
)
end

def response_error_node(document)
Expand All @@ -248,8 +254,6 @@ def response_success?(document)
def response_message(document)
error_node = response_error_node(document)
if error_node

debugger
"FedEx Error Code: #{error_node.get_text('Code').to_s}: #{error_node.get_text('Message').to_s}"
else
''
Expand Down
3 changes: 3 additions & 0 deletions lib/active_shipping/shipping/carriers/shipwire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module Shipping
class Shipwire < Carrier
self.retry_safe = true

cattr_reader :name
@@name = "Shipwire"

URL = 'https://www.shipwire.com/exec/RateServices.php'
SCHEMA_URL = 'http://www.shipwire.com/exec/download/RateRequest.dtd'
WAREHOUSES = { 'CHI' => 'Chicago',
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/xml/fedex/empty_response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
?xml version="1.0" encoding="UTF-8"?><FDXRateAvailableServicesReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><ReplyHeader></ReplyHeader></FDXRateAvailableServicesReply>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><FDXRateAvailableServicesReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><ReplyHeader></ReplyHeader><SoftError><Type>01</Type><Code>61451</Code><Message>Invalid recipient country</Message></SoftError></FDXRateAvailableServicesReply>
60 changes: 53 additions & 7 deletions test/remote/fedex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ def setup
@locations = TestFixtures.locations
@carrier = FedEx.new(fixtures(:fedex))
end

def test_us_to_canada
response = nil
assert_nothing_raised do
response = @carrier.find_rates(
@locations[:beverly_hills],
@locations[:ottawa],
@packages.values_at(:wii),
:test => true
@packages.values_at(:wii)
)
assert !response.rates.blank?
response.rates.each do |rate|
Expand All @@ -25,14 +24,62 @@ def test_us_to_canada
end
end

def test_zip_to_zip_fails
begin
@carrier.find_rates(
Location.new(:zip => 40524),
Location.new(:zip => 40515),
@packages[:wii]
)
rescue ResponseError => e
assert_equal 'FedEx Error Code: 64354: Required element OriginAddress/CountryCode missing.', e.message
end
end

# FedEx requires a valid origin and destination postal code
def test_rates_for_locations_with_only_zip_and_country
response = @carrier.find_rates(
@locations[:bare_beverly_hills],
@locations[:bare_ottawa],
@packages.values_at(:wii)
)

assert response.rates.size > 0
end

def test_rates_for_location_with_only_country_code
begin
response = @carrier.find_rates(
@locations[:bare_beverly_hills],
Location.new(:country => 'CA'),
@packages.values_at(:wii),
:items => @items
)
rescue ResponseError => e
assert_equal 'FedEx Error Code: 61530: Invalid Destination/Address/PostalCode.', e.message
end
end

def test_invalid_recipient_country
begin
response = @carrier.find_rates(
@locations[:bare_beverly_hills],
Location.new(:country => 'JP', :zip => '108-8361'),
@packages.values_at(:wii),
:items => @items
)
rescue ResponseError => e
assert_equal 'FedEx Error Code: 61451: Invalid recipient country', e.message
end
end

def test_canada_to_us
response = nil
assert_nothing_raised do
response = @carrier.find_rates(
@locations[:ottawa],
@locations[:beverly_hills],
@packages.values_at(:wii),
:test => true
@packages.values_at(:wii)
)
assert !response.rates.blank?
response.rates.each do |rate|
Expand All @@ -48,8 +95,7 @@ def test_ottawa_to_beverly_hills
response = @carrier.find_rates(
@locations[:ottawa],
@locations[:beverly_hills],
@packages.values_at(:book, :wii),
:test => true
@packages.values_at(:book, :wii)
)
assert !response.rates.blank?
response.rates.each do |rate|
Expand Down
32 changes: 29 additions & 3 deletions test/unit/carriers/fedex_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require File.dirname(__FILE__) + '/../../test_helper'

class FedExTest < Test::Unit::TestCase
include ActiveMerchant::Shipping

def setup
@packages = TestFixtures.packages
@locations = TestFixtures.locations
Expand All @@ -21,9 +19,37 @@ def test_initialize_options_requirements
assert_nothing_raised { FedEx.new(:login => '999999999', :password => '7777777')}
end

def test_invalid_recipient_country
@carrier.expects(:commit).returns(xml_fixture('fedex/invalid_recipient_country_response'))

begin
@carrier.find_rates(
@locations[:ottawa],
@locations[:beverly_hills],
@packages.values_at(:book, :wii)
)
rescue ResponseError => e
assert_equal "FedEx Error Code: 61451: Invalid recipient country", e.message
end
end

def test_no_rates_response
@carrier.expects(:commit).returns(xml_fixture('fedex/empty_response'))

begin
response = @carrier.find_rates(
@locations[:ottawa],
@locations[:beverly_hills],
@packages.values_at(:book, :wii)
)
rescue ResponseError => e
assert_equal "No shipping rates could be found for the destination address", e.message
end
end

def test_find_tracking_info_should_return_a_tracking_response
@carrier.expects(:commit).returns(@tracking_response)
assert_equal 'ActiveMerchant::Shipping::TrackingResponse', @carrier.find_tracking_info('077973360390581').class.name
assert_instance_of ActiveMerchant::Shipping::TrackingResponse, @carrier.find_tracking_info('077973360390581')
end

def test_find_tracking_info_should_parse_response_into_correct_number_of_shipment_events
Expand Down

0 comments on commit d89662c

Please sign in to comment.