Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

Add equality operator to ShipmentEvent and TrackingResponse #372

Merged
merged 5 commits into from May 18, 2016

Conversation

richardwu
Copy link
Contributor

@richardwu richardwu commented May 17, 2016

Useful for writing tests to compare ShipmentEvent and TrackingResponse objects and future use cases.

cc: @jonathankwok @MalazAlamir

@richardwu richardwu force-pushed the add_equality_operator_to_tracking_response branch 2 times, most recently from 518b209 to 3fdd841 Compare May 17, 2016 18:02

def ==(other)
name == other.name && time == other.time && location == other.location && message == other.message &&
type_code == other.type_code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the number of things you're comparing, I'd prefer it if we separated them by lines, i.e.

name == other.name &&
time == other.time &&
location == other.location &&
...

Alternatively, you could iterate over all of them, like:

attributes = [:name, :time, :location, :message, :type_code]
attributes.all? { |attr| self.public_send(:attr) == other.public_send(:attr) }

@richardwu
Copy link
Contributor Author

richardwu commented May 17, 2016

Changed how distinct TrackingResponse and ShipmentEvent objects are created and tested for (objects as attributes do not copy when copying options hash, therefore deep copying was required). A private method compare_shipment_events was needed to compare :shipment_events between TrackResponse objects such that order inside :shipment_events array would not matter. @jonathankwok @MalazAlamir

@@ -13,5 +13,10 @@ def delivered?
def status
@status ||= name.downcase.gsub("\s", "_").to_sym
end

def ==(other)
attributes = %i(name time location message type_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 👏 👏 👏

@jonathankwok
Copy link
Contributor

🔴 tests aren't your fault, remote APIs are being flaky. Merge when 💚 eventually.

@richardwu richardwu force-pushed the add_equality_operator_to_tracking_response branch from 36822a4 to 7502694 Compare May 18, 2016 14:45
@MalazAlamir
Copy link
Contributor

LGTM 🚀

@richardwu richardwu merged commit 26a0d91 into master May 18, 2016
@richardwu richardwu deleted the add_equality_operator_to_tracking_response branch May 18, 2016 16:29
maartenvg pushed a commit that referenced this pull request Oct 8, 2017
added equality operator to ShipmentEvent and TrackingResponse
maartenvg pushed a commit that referenced this pull request Oct 12, 2017
added equality operator to ShipmentEvent and TrackingResponse
maartenvg pushed a commit that referenced this pull request Nov 9, 2017
added equality operator to ShipmentEvent and TrackingResponse
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants