Skip to content

Commit

Permalink
Merge pull request voxpupuli#1019 from tylerjl/hash-each-pair-return
Browse files Browse the repository at this point in the history
Properly return objects in sorted hash each_pair
  • Loading branch information
tylerjl authored Feb 26, 2019
2 parents 38c4ae0 + 5a98781 commit 7fabc13
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Puppet 4.10.0 is the new minimum required version of Puppet.
#### Fixes
* The Elasticsearch log directory is no longer recursively managed to avoid stomping on the user/mode settings that Elasticsearch prefers.
* Package management on apt-based systems no longer encounters dependency errors when `manage_repo => false`.
* An error related to elasticsearch_roles and `yield` errors has been fixed
* Correctly permit instances to be set to `absent` without errors.

#### Features
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet_x/elastic/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ def self.extended(base)
# Override each_pair with a method that yields key/values in
# sorted order.
def each_pair
return to_enum(:each_pair) unless block_given?
keys.sort.each do |key|
yield key, self[key]
end
self
end
end
end
Expand Down
25 changes: 25 additions & 0 deletions spec/unit/puppet_x/elastic/hash_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))

require 'spec_helper_rspec'
require 'puppet_x/elastic/hash'

describe Puppet_X::Elastic::SortedHash do
subject { { 'foo' => 1, 'bar' => 2 } }

describe 'each_pair' do
it { is_expected.to respond_to :each_pair }

it 'yields values' do
expect { |b| subject.each_pair(&b) }.to yield_control.exactly(2).times
end

it 'returns an Enumerator if not passed a block' do
expect(subject.each_pair).to be_an_instance_of(Enumerator)
end

it 'returns values' do
subject.each_pair.map { |k, v| [k, v] }.should == subject.to_a
end
end
end

0 comments on commit 7fabc13

Please sign in to comment.