diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2011-03-15 15:29:01 -0700 |
|---|---|---|
| committer | Jesse Wolfe <jes5199@gmail.com> | 2011-03-15 17:46:40 -0700 |
| commit | 4f34dbf206e591614c2fc06ce9bed1628ee85715 (patch) | |
| tree | 6788c517b32c36f1c5e58d239143bca39f0775cb | |
| parent | 9781032736a34f577241828bcf812a648b4f42e9 (diff) | |
| download | puppet-4f34dbf206e591614c2fc06ce9bed1628ee85715.tar.gz puppet-4f34dbf206e591614c2fc06ce9bed1628ee85715.tar.xz puppet-4f34dbf206e591614c2fc06ce9bed1628ee85715.zip | |
Fix #5610: Prevent unnecessary RAL lookups
Reviewed-By: Paul Berry <paul@puppetlabs.com>
| -rw-r--r-- | lib/puppet/type.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/type_spec.rb | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 205d809c1..d24cc8554 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -200,7 +200,7 @@ class Type end def uniqueness_key - to_resource.uniqueness_key + self.class.key_attributes.sort_by { |attribute_name| attribute_name.to_s }.map{ |attribute_name| self[attribute_name] } end # Create a new parameter. Requires a block and a name, stores it in the diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb index b7a08977e..6d9d0b234 100755 --- a/spec/unit/type_spec.rb +++ b/spec/unit/type_spec.rb @@ -434,7 +434,7 @@ describe Puppet::Type do patterns.length.should == 1 patterns[0].length.should == 2 end - + it "should have a regexp that captures the entire string" do patterns = @type_class.title_patterns string = "abc\n\tdef" @@ -570,4 +570,15 @@ describe Puppet::Type.metaparamclass(:audit) do @resource[:audit] = :noop @resource.parameter(:noop).should be_nil end + + describe "when generating the uniqueness key" do + it "should include all of the key_attributes in alphabetical order by attribute name" do + Puppet::Type.type(:file).stubs(:key_attributes).returns [:path, :mode, :owner] + Puppet::Type.type(:file).stubs(:title_patterns).returns( + [ [ /(.*)/, [ [:path, lambda{|x| x} ] ] ] ] + ) + res = Puppet::Type.type(:file).new( :title => '/my/file', :path => '/my/file', :owner => 'root', :content => 'hello' ) + res.uniqueness_key.should == [ nil, 'root', '/my/file'] + end + end end |
