summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-02-06 11:31:52 -0800
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commitad93d0e442d4e4eff69bb3f444b2eee70a95dfa8 (patch)
tree64f34fee1ffc11d3253cf6a6bacf5a4f3c051d64 /spec
parent6e4db8261af6372c6acad4e8ff3f7a32e7a074fb (diff)
downloadpuppet-ad93d0e442d4e4eff69bb3f444b2eee70a95dfa8.tar.gz
puppet-ad93d0e442d4e4eff69bb3f444b2eee70a95dfa8.tar.xz
puppet-ad93d0e442d4e4eff69bb3f444b2eee70a95dfa8.zip
Forcing parent evaluation in resource types
When a class is evaluated, its parent class needs to be evaluated first. This forces that evaluation. We somehow lost it when we converted the resource types out of AST. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/resource/type.rb45
1 files changed, 44 insertions, 1 deletions
diff --git a/spec/unit/resource/type.rb b/spec/unit/resource/type.rb
index 1a19cf4f0..d1ee024ef 100755
--- a/spec/unit/resource/type.rb
+++ b/spec/unit/resource/type.rb
@@ -329,7 +329,7 @@ describe Puppet::Resource::Type do
before do
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
@scope = Puppet::Parser::Scope.new :compiler => @compiler
- @resource = stub 'resource', :title => "yay", :name => "yea", :ref => "Foo[bar]", :scope => @scope
+ @resource = Puppet::Parser::Resource.new(:foo, "yay", :scope => @scope)
@type = Puppet::Resource::Type.new(:hostclass, "foo")
@type.stubs(:set_resource_parameters)
end
@@ -350,6 +350,15 @@ describe Puppet::Resource::Type do
@type.evaluate_code(@resource)
end
+ it "should still create a scope but not store it if the type is a definition" do
+ subscope = stub 'subscope', :compiler => @compiler, :setvar => nil
+
+ @type = Puppet::Resource::Type.new(:definition, "foo")
+ @type.expects(:subscope).with(@scope, @resource).returns subscope
+ @type.evaluate_code(@resource)
+ @compiler.class_scope(@type).should be_nil
+ end
+
it "should evaluate the code if any is provided" do
code = stub 'code'
@type.stubs(:code).returns code
@@ -364,6 +373,40 @@ describe Puppet::Resource::Type do
@type.evaluate_code(@resource)
end
+
+ describe "and it has a parent class" do
+ before do
+ @parent_type = Puppet::Resource::Type.new(:hostclass, "parent")
+ @compiler
+ @type.parent = "parent"
+ @parent_resource = Puppet::Parser::Resource.new(:class, "parent", :scope => @scope)
+
+ @compiler.add_resource @scope, @parent_resource
+
+ @type.code_collection = @scope.known_resource_types
+ @type.code_collection.add @parent_type
+ end
+
+ it "should evaluate the parent's resource" do
+ @type.evaluate_code(@resource)
+
+ @compiler.class_scope(@parent_type).should_not be_nil
+ end
+
+ it "should not evaluate the parent's resource if it has already been evaluated" do
+ @parent_resource.evaluate
+
+ @parent_resource.expects(:evaluate).never
+
+ @type.evaluate_code(@resource)
+ end
+
+ it "should use the parent's scope as its base scope" do
+ @type.evaluate_code(@resource)
+
+ @scope.compiler.class_scope(@type).parent.object_id.should == @scope.compiler.class_scope(@parent_type).object_id
+ end
+ end
end
describe "when creating a resource" do