diff options
| -rw-r--r-- | lib/puppet/resource/reference.rb | 15 | ||||
| -rwxr-xr-x | spec/unit/resource/reference.rb | 10 |
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/puppet/resource/reference.rb b/lib/puppet/resource/reference.rb index d254254aa..d17b3e558 100644 --- a/lib/puppet/resource/reference.rb +++ b/lib/puppet/resource/reference.rb @@ -21,12 +21,17 @@ class Puppet::Resource::Reference builtin_type ? true : false end - def initialize(type, title) - # This will set @type if it looks like a resource reference. - self.title = title + def initialize(argtype, argtitle = nil) + if argtitle.nil? + self.title = argtype + raise ArgumentError, "No title provided and title '%s' is not a valid resource reference" % argtype if self.title == argtype + else + # This will set @type if it looks like a resource reference. + self.title = argtitle - # Don't override whatever was done by setting the title. - self.type = type if self.type.nil? + # Don't override whatever was done by setting the title. + self.type ||= argtype + end @builtin_type = nil end diff --git a/spec/unit/resource/reference.rb b/spec/unit/resource/reference.rb index 001aa0395..fa2d87bd5 100755 --- a/spec/unit/resource/reference.rb +++ b/spec/unit/resource/reference.rb @@ -47,6 +47,16 @@ describe Puppet::Resource::Reference do ref.title.should =="baz[yay]" end + it "should interpret the type as a reference and assign appropriately if the title is nil and the type contains square brackets" do + ref = Puppet::Resource::Reference.new("foo::bar[baz]") + ref.type.should == "Foo::Bar" + ref.title.should =="baz" + end + + it "should fail if the title is nil and the type is not a valid resource reference string" do + lambda { Puppet::Resource::Reference.new("foo") }.should raise_error(ArgumentError) + end + it "should be considered builtin if an existing resource type matches the type" do Puppet::Resource::Reference.new("file", "/f").should be_builtin_type end |
