related tag calculator: fix unstable sorting of related tags.

Fix this test failure:

    1) Failure:
    RelatedTagCalculatorTest#test_: A related tag calculator should convert a hash into string format.
    [test/unit/related_tag_calculator_test.rb:65]:
    Expected: "aaa 3 bbb 3 ccc 2 ddd 1"
      Actual: "bbb 3 aaa 3 ccc 2 ddd 1"

The related tag string didn't use a stable sort. Sort first by tag
count, then by tag name.
This commit is contained in:
evazion
2018-01-20 14:33:36 -06:00
parent e596a7fd0f
commit 57c4d2a54f

View File

@@ -69,7 +69,7 @@ class RelatedTagCalculator
end
def self.convert_hash_to_array(hash, limit = MAX_RESULTS)
hash.to_a.sort_by {|x| -x[1]}.slice(0, limit)
hash.to_a.sort_by {|x| [-x[1], x[0]] }.slice(0, limit)
end
def self.convert_hash_to_string(hash)