-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reintroduce hash sorting for expanded content-item and links, but cor…
…rectly this time enforce internal consistency of sym/string keys for ExpandedLinksPresenter and ContentItemPresenter
- Loading branch information
1 parent
2c0e015
commit cc390d0
Showing
8 changed files
with
84 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "deepsort" | ||
|
||
class HashSorter | ||
def self.sort(hash) | ||
# Deepsort by default will sort keys in an array too - | ||
# we don't want that, as (for instance) order of links | ||
# may be important | ||
hash.deep_sort(array: false) | ||
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
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,37 @@ | ||
require "rails_helper" | ||
|
||
describe HashSorter do | ||
describe ".sort" do | ||
let(:links) do | ||
{ | ||
group_2: [ | ||
{ base_path: "/group-1/link-1", api_path: "/api/content/group-1/link-1" }, | ||
{ base_path: "/group-1/link-2", api_path: "/api/content/group-1/link-2" }, | ||
{ base_path: "/group-1/link-3", api_path: "/api/content/group-1/link-3" }, | ||
], | ||
group_1: [ | ||
{ base_path: "/group-2/link-3", api_path: "/api/content/group-2/link-3" }, | ||
{ base_path: "/group-2/link-2", api_path: "/api/content/group-2/link-2" }, | ||
{ base_path: "/group-2/link-1", api_path: "/api/content/group-2/link-1" }, | ||
], | ||
} | ||
end | ||
let(:result) { described_class.sort(links) } | ||
|
||
it "sorts the top-level keys" do | ||
expect(result.keys).to eq(%i[group_1 group_2]) | ||
end | ||
|
||
it "does not sort the arrays" do | ||
expect(result[:group_1].map { |e| e[:base_path] }).to eq(links[:group_1].map { |e| e[:base_path] }) | ||
end | ||
|
||
it "sorts the keys on Hashes within arrays" do | ||
%i[group_1 group_2].each do |group| | ||
result[group].each do |hash| | ||
expect(hash.keys).to eq(hash.keys.sort) | ||
end | ||
end | ||
end | ||
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
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