Skip to content

Commit

Permalink
Merge pull request #28 from alpaca-tc/fixed-26
Browse files Browse the repository at this point in the history
When saving module_store, sort by source name.
  • Loading branch information
alpaca-tc authored May 9, 2024
2 parents 1f80961 + 9595c4c commit fbab5e0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/diver_down/web/module_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def get(source_name)

# @return [Hash]
def to_h
@store.dup
sorted_store = {}

@store.keys.sort.each do |key|
sorted_store[key] = @store[key]
end

sorted_store
end

# Write store to file
Expand Down
32 changes: 32 additions & 0 deletions spec/diver_down/web/module_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@
described_class.new(tempfile.path).get('a.rb')
}.from([]).to(['A', 'B'])
end

it 'sorts by source name' do
tempfile = Tempfile.new(['test', '.yaml'])
instance = described_class.new(tempfile.path)

sources = ['a.rb', 'b.rb', 'c.rb']

sources.shuffle.each do |source|
instance.set(source, ['A'])
end

expect {
instance.flush
}.to change {
described_class.new(tempfile.path).instance_variable_get(:@store).keys
}.from([]).to(sources)
end
end

describe '#to_h' do
it 'returns sorted hash' do
tempfile = Tempfile.new(['test', '.yaml'])
instance = described_class.new(tempfile.path)

sources = ['a.rb', 'b.rb', 'c.rb']

sources.shuffle.each do |source|
instance.set(source, ['A'])
end

expect(instance.to_h.keys).to eq(sources)
end
end
end
end

0 comments on commit fbab5e0

Please sign in to comment.