Resource array should be flattened before it is handled by the collector (which needs a flattened array).
Added unit test covering the realize function Signed-off-by: Brice Figureau <brice-pup...@daysofwonder.com> --- lib/puppet/parser/functions/realize.rb | 2 +- spec/unit/parser/functions/realize.rb | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletions(-) create mode 100755 spec/unit/parser/functions/realize.rb diff --git a/lib/puppet/parser/functions/realize.rb b/lib/puppet/parser/functions/realize.rb index 1bdde23..6aff19d 100644 --- a/lib/puppet/parser/functions/realize.rb +++ b/lib/puppet/parser/functions/realize.rb @@ -8,7 +8,7 @@ Puppet::Parser::Functions::newfunction(:realize, :doc => "Make a virtual object reference; e.g.: ``realize User[luke]``." ) do |vals| coll = Puppet::Parser::Collector.new(self, :nomatter, nil, nil, :virtual) vals = [vals] unless vals.is_a?(Array) - coll.resources = vals + coll.resources = vals.flatten compiler.add_collection(coll) end diff --git a/spec/unit/parser/functions/realize.rb b/spec/unit/parser/functions/realize.rb new file mode 100755 index 0000000..d9c94b1 --- /dev/null +++ b/spec/unit/parser/functions/realize.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe "the realize function" do + + before :each do + @collector = stub_everything 'collector' + @scope = Puppet::Parser::Scope.new() + @compiler = stub 'compiler' + @compiler.stubs(:add_collection).with(@collector) + @scope.stubs(:compiler).returns(@compiler) + end + + it "should exist" do + Puppet::Parser::Functions.function("realize").should == "function_realize" + end + + it "should create a Collector when called" do + + Puppet::Parser::Collector.expects(:new).returns(@collector) + + @scope.function_realize("test") + end + + it "should assign the passed-in resources to the collector" do + Puppet::Parser::Collector.stubs(:new).returns(@collector) + + @collector.expects(:resources=).with(["test"]) + + @scope.function_realize("test") + end + + it "should flatten the resources assigned to the collector" do + Puppet::Parser::Collector.stubs(:new).returns(@collector) + + @collector.expects(:resources=).with(["test"]) + + @scope.function_realize([["test"]]) + end + + it "should let the compiler know this collector" do + Puppet::Parser::Collector.stubs(:new).returns(@collector) + @collector.stubs(:resources=).with(["test"]) + + @compiler.expects(:add_collection).with(@collector) + + @scope.function_realize("test") + end + +end -- 1.6.0.2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---