diff options
-rw-r--r-- | lib/puppet/resource.rb | 6 | ||||
-rwxr-xr-x | spec/unit/resource_spec.rb | 11 |
2 files changed, 5 insertions, 12 deletions
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 6ffaa2f3b..393211e09 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -213,11 +213,7 @@ class Puppet::Resource end def uniqueness_key - h = {} - key_attributes.each do |attribute| - h[attribute] = self.to_hash[attribute] - end - return h + self.to_hash.values_at(*key_attributes.sort_by { |k| k.to_s }) end def key_attributes diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 4bcfbd3bf..712bc2c8a 100755 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -298,7 +298,7 @@ describe Puppet::Resource do describe "when referring to a resource with name canonicalization" do it "should canonicalize its own name" do res = Puppet::Resource.new("file", "/path/") - res.uniqueness_key.should == {:path => "/path"} + res.uniqueness_key.should == ["/path"] res.ref.should == "File[/path/]" end end @@ -793,16 +793,13 @@ describe Puppet::Resource do end describe "when generating the uniqueness key" do - it "should include all of the key_attributes" do + it "should include all of the key_attributes in alphabetical order by attribute name" do Puppet::Type.type(:file).stubs(:key_attributes).returns [:myvar, :owner, :path] Puppet::Type.type(:file).stubs(:title_patterns).returns( [ [ /(.*)/, [ [:path, lambda{|x| x} ] ] ] ] ) - Puppet::Resource.new("file", "/my/file", :parameters => {:owner => 'root', :content => 'hello'}).uniqueness_key.should == { - :myvar => nil, - :owner => 'root', - :path => '/my/file', - } + res = Puppet::Resource.new("file", "/my/file", :parameters => {:owner => 'root', :content => 'hello'}) + res.uniqueness_key.should == [ nil, 'root', '/my/file'] end end end |