Permalink
Browse files

Fix parsing FedEx responses for events without address details

  • Loading branch information...
Soleone committed Mar 30, 2011
1 parent b3894d0 commit 26e777a71027a11cd94f0d0ddf132f041ee93244
@@ -277,11 +277,15 @@ def parse_tracking_response(response, options)
)
tracking_details.elements.each('Events') do |event|
- location = Location.new(
- :city => event.elements['Address'].get_text('City').to_s,
- :state => event.elements['Address'].get_text('StateOrProvinceCode').to_s,
- :postal_code => event.elements['Address'].get_text('PostalCode').to_s,
- :country => event.elements['Address'].get_text('CountryCode').to_s)
+ address = event.elements['Address']
+
+ city = address.get_text('City').to_s
+ state = address.get_text('StateOrProvinceCode').to_s
+ zip_code = address.get_text('PostalCode').to_s
+ country = address.get_text('CountryCode').to_s
+ next if country.blank?
+
+ location = Location.new(:city => city, :state => state, :postal_code => zip_code, :country => country)
description = event.get_text('EventDescription').to_s
# for now, just assume UTC, even though it probably isn't
@@ -144,8 +144,6 @@
<v3:EventType>OC</v3:EventType>
<v3:EventDescription>Shipment information sent to FedEx</v3:EventDescription>
<v3:Address>
- <v3:PostalCode>37211</v3:PostalCode>
- <v3:CountryCode>US</v3:CountryCode>
<v3:Residential>false</v3:Residential>
</v3:Address>
</v3:Events>
@@ -33,7 +33,7 @@ def test_find_tracking_info_should_return_a_tracking_response
def test_find_tracking_info_should_parse_response_into_correct_number_of_shipment_events
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response'))
response = @carrier.find_tracking_info('077973360403984', :test => true)
- assert_equal 7, response.shipment_events.size
+ assert_equal 6, response.shipment_events.size
end
def test_find_tracking_info_should_return_shipment_events_in_ascending_chronological_order
@@ -42,6 +42,14 @@ def test_find_tracking_info_should_return_shipment_events_in_ascending_chronolog
assert_equal response.shipment_events.map(&:time).sort, response.shipment_events.map(&:time)
end
+ def test_find_tracking_info_should_not_include_events_without_an_address
+ @carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response'))
+ assert_nothing_raised do
+ response = @carrier.find_tracking_info('077973360403984', :test => true)
+ assert_nil response.shipment_events.find{|event| event.name == 'Shipment information sent to FedEx' }
+ end
+ end
+
def test_building_request_and_parsing_response
expected_request = xml_fixture('fedex/ottawa_to_beverly_hills_rate_request')
mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response')

0 comments on commit 26e777a

Please sign in to comment.