Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

offset the date range for ground shipping transit times

  • Loading branch information...
commit 7c1094fd062cd3b8b85b0913e605691a3a2f1ae4 1 parent baacf74
@peterjm peterjm authored
View
7 lib/active_shipping/shipping/carriers/fedex.rb
@@ -285,7 +285,7 @@ def parse_rate_response(origin, destination, packages, response, options)
#if there's no delivery timestamp but we do have a transit time, use it
if delivery_timestamp.blank? and transit_time.present?
transit_range = parse_transit_times([transit_time,max_transit_time.presence || transit_time])
- delivery_range = [Date.today + transit_range[0], Date.today + transit_range[1]]
+ delivery_range = transit_range.map{|t| ship_date(options[:turn_around_time]) + t.days}
else
delivery_range = [delivery_timestamp,delivery_timestamp]
end
@@ -389,6 +389,11 @@ def ship_timestamp(delay_in_hours)
Time.now + delay_in_hours.hours
end
+ def ship_date(delay_in_hours)
+ delay_in_hours ||= 0
+ Date.today + (delay_in_hours / 24).days
+ end
+
def response_status_node(document)
document.elements['/*/Notifications/']
end
View
12 test/unit/carriers/fedex_test.rb
@@ -16,8 +16,9 @@ def test_initialize_options_requirements
end
def test_turn_around_time_default
- mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response')
+ mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response').gsub('<v6:DeliveryTimestamp>2011-07-29</v6:DeliveryTimestamp>', '')
Timecop.freeze(DateTime.new(2012, 6, 15)) do
+ delivery_date = Date.today + 5.days # FIVE_DAYS in fixture response
timestamp = Time.now.iso8601
@carrier.expects(:commit).with do |request|
parsed_response = Hash.from_xml(request)
@@ -25,13 +26,15 @@ def test_turn_around_time_default
end.returns(mock_response)
destination = ActiveMerchant::Shipping::Location.from(@locations[:beverly_hills].to_hash, :address_type => :commercial)
- @carrier.find_rates @locations[:ottawa], destination, @packages[:book], :test => true
+ response = @carrier.find_rates @locations[:ottawa], destination, @packages[:book], :test => true
+ assert_equal [delivery_date, delivery_date], response.rates.first.delivery_range
end
end
def test_turn_around_time
- mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response')
+ mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response').gsub('<v6:DeliveryTimestamp>2011-07-29</v6:DeliveryTimestamp>', '')
Timecop.freeze(DateTime.new(2012, 6, 15)) do
+ delivery_date = Date.today + 6.days # FIVE_DAYS in fixture response, plus turn_around_time
timestamp = (Time.now + 1.day).iso8601
@carrier.expects(:commit).with do |request|
parsed_response = Hash.from_xml(request)
@@ -39,7 +42,8 @@ def test_turn_around_time
end.returns(mock_response)
destination = ActiveMerchant::Shipping::Location.from(@locations[:beverly_hills].to_hash, :address_type => :commercial)
- @carrier.find_rates @locations[:ottawa], destination, @packages[:book], :turn_around_time => 24, :test => true
+ response = @carrier.find_rates @locations[:ottawa], destination, @packages[:book], :turn_around_time => 24, :test => true
+ assert_equal [delivery_date, delivery_date], response.rates.first.delivery_range
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.