diff options
-rw-r--r-- | lib/puppet/rails/resource.rb | 6 | ||||
-rw-r--r-- | lib/puppet/resource.rb | 3 | ||||
-rwxr-xr-x | spec/unit/rails/resource_spec.rb | 16 | ||||
-rwxr-xr-x | spec/unit/resource_spec.rb | 6 |
4 files changed, 28 insertions, 3 deletions
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb index a5cdd0c13..582cdd41a 100644 --- a/lib/puppet/rails/resource.rb +++ b/lib/puppet/rails/resource.rb @@ -212,16 +212,16 @@ class Puppet::Rails::Resource < ActiveRecord::Base end hash[:scope] = scope hash[:source] = scope.source - hash[:params] = [] + hash[:parameters] = [] names = [] self.param_names.each do |pname| # We can get the same name multiple times because of how the # db layout works. next if names.include?(pname.name) names << pname.name - hash[:params] << pname.to_resourceparam(self, scope.source) + hash[:parameters] << pname.to_resourceparam(self, scope.source) end - obj = Puppet::Parser::Resource.new(hash) + obj = Puppet::Parser::Resource.new(hash.delete("type"), hash.delete("title"), hash) # Store the ID, so we can check if we're re-collecting the same resource. obj.rails_id = self.id diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index d163d93f0..55874aec8 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -409,6 +409,9 @@ class Puppet::Resource if (argtitle || argtype) =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ] elsif argtitle then [ argtype, argtitle ] elsif argtype.is_a?(Puppet::Type) then [ argtype.class.name, argtype.title ] + elsif argtype.is_a?(Hash) then + raise ArgumentError, "Puppet::Resource.new does not take a hash as the first argument. "+ + "Did you mean (#{(argtype[:type] || argtype["type"]).inspect}, #{(argtype[:title] || argtype["title"]).inspect }) ?" else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference" end end diff --git a/spec/unit/rails/resource_spec.rb b/spec/unit/rails/resource_spec.rb index ac7469355..08deda65e 100755 --- a/spec/unit/rails/resource_spec.rb +++ b/spec/unit/rails/resource_spec.rb @@ -104,4 +104,20 @@ describe "Puppet::Rails::Resource" do @resource.merge_parameters(merge_resource) end end + + describe "#to_resource" do + it "should instantiate a Puppet::Parser::Resource" do + scope = stub "scope", :source => nil + + @resource = Puppet::Rails::Resource.new + @resource.stubs(:attributes).returns({ + "restype" => 'notify', + "title" => 'hello' + }) + @resource.stubs(:param_names).returns([]) + + @resource.to_resource(scope).should be_a(Puppet::Parser::Resource) + + end + end end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 95f0dd04b..204a2b02e 100755 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -98,6 +98,12 @@ describe Puppet::Resource do lambda { Puppet::Resource.new("foo") }.should raise_error(ArgumentError) end + it "should fail if the title is a hash and the type is not a valid resource reference string" do + lambda { Puppet::Resource.new({:type => "foo", :title => "bar"}) }.should raise_error(ArgumentError, + 'Puppet::Resource.new does not take a hash as the first argument. Did you mean ("foo", "bar") ?' + ) + end + it "should be able to produce a backward-compatible reference array" do Puppet::Resource.new("foobar", "/f").to_trans_ref.should == %w{Foobar /f} end |