From 57c4d2a54f854cb48a983d45b3f2491428892a33 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 20 Jan 2018 14:33:36 -0600 Subject: [PATCH] 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. --- app/logical/related_tag_calculator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/logical/related_tag_calculator.rb b/app/logical/related_tag_calculator.rb index 9905d21aa..2818bb961 100644 --- a/app/logical/related_tag_calculator.rb +++ b/app/logical/related_tag_calculator.rb @@ -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)