Skip to content
This repository has been archived by the owner. It is now read-only.

fix(clients): Always sort the current device first. #4430

Merged
merged 1 commit into from Nov 21, 2016
Merged

Conversation

@rfk
Copy link
Member

@rfk rfk commented Nov 21, 2016

The client sorting logic was only putting the current device first if it happened to appear on the left-hand-side of a comparison. This fixes it to detect the current device on either side. It also fixes what looked like a typo in a later comparison (comparing a and b objects rather than aName and bName strings).

The tests were passing because the order of the input array happened to cause the current device to compare correctly, and I was in two minds about how to fix that issue. We could write a separate test for "puts the current device first when it's in a variety of different positions in the input list" but that felt like a lot of repetition. Randomizing the order of the input list seemed better on balance, because it would not depend on implementation details of the underlying sort, and because it would also capture other edge-cases that we haven't noticed.

But I'm aware that randomizing tests is not everyone's cup of tea, so let me know if you don't like it, and I'll replace it with a separate deterministic test case.

@vladikoff r?

@@ -59,6 +59,9 @@ define(function (require, exports, module) {
if (a.get('isCurrentDevice')) {
return -1;
}
if (b.get('isCurrentDevice')) {

This comment has been minimized.

@vladikoff

vladikoff Nov 21, 2016
Contributor

👍 yessss!

@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Nov 21, 2016

Thanks for the PR, randomized is fine here, if it is wrong we can easily find the issue. 👍

@vladikoff vladikoff merged commit 7ce2bf9 into master Nov 21, 2016
4 checks passed
4 checks passed
ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.01%) to 98.604%
Details
@vladikoff vladikoff deleted the fix-client-sorting branch Nov 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants