This repository was archived by the owner on Jun 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add equality operator to ShipmentEvent and TrackingResponse (#372)
added equality operator to ShipmentEvent and TrackingResponse
- Loading branch information
Showing
6 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'test_helper' | ||
|
||
class ShipmentEventTest < Minitest::Test | ||
def test_equality | ||
options1 = [ | ||
'ARRIVED AT UNIT', | ||
DateTime.new(2016, 5, 12, 5, 45), | ||
Location.new(city: 'SAN JOSE', state: 'CA', postal_code: '90001', country: 'US'), | ||
'ARRIVED AT UNIT', | ||
'07' | ||
] | ||
# Copies options to create new DateTime and Location objects to check for similar distinct objects | ||
options2 = options1.dup | ||
|
||
shipment_event_1 = ShipmentEvent.new(*options1) | ||
shipment_event_2 = ShipmentEvent.new(*options2) | ||
|
||
assert_equal shipment_event_1, shipment_event_2 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'test_helper' | ||
|
||
class TrackingResponseTest < Minitest::Test | ||
def test_equality | ||
options1 = { | ||
carrier: 'usps', | ||
status: 'DELIVERED', | ||
status_code: 'I0', | ||
status_description: 'DELIVERED', | ||
actual_delivery_date: DateTime.new(2016, 5, 14, 13, 20), | ||
tracking_number: 'TRACKINGNUMBER1234ABC', | ||
shipment_events: [ | ||
ShipmentEvent.new( | ||
'DELIVERED', | ||
DateTime.new(2016, 5, 14, 13, 20), | ||
Location.new(city: 'LOS ANGELES', state: 'CA', postal_code: '90210', country: 'US'), | ||
'DELIVERED', | ||
'I0' | ||
), | ||
ShipmentEvent.new( | ||
'ARRIVED AT UNIT', | ||
DateTime.new(2016, 5, 12, 5, 45), | ||
Location.new(city: 'SAN JOSE', state: 'CA', postal_code: '90001', country: 'US'), | ||
'ARRIVED AT UNIT', | ||
'07' | ||
) | ||
], | ||
destination: Location.new(postal_code: '90210'), | ||
origin: Location.new(postal_code: '00001') | ||
} | ||
# Deep copies options1 to create new ShipmentEvent, Location, etc. objects to check for similar distinct objects | ||
options2 = Marshal.load(Marshal.dump(options1)) | ||
options2[:shipment_events][0], options2[:shipment_events][1] = | ||
options2[:shipment_events][1], options2[:shipment_events][0] | ||
|
||
tracking_response_1 = TrackingResponse.new(true, nil, {}, options1) | ||
tracking_response_2 = TrackingResponse.new(true, nil, {}, options2) | ||
|
||
assert_equal tracking_response_1, tracking_response_2 | ||
end | ||
end |