diff options
-rw-r--r-- | lib/puppet/rails/resource.rb | 13 | ||||
-rwxr-xr-x | spec/unit/rails/resource.rb | 45 |
2 files changed, 56 insertions, 2 deletions
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb index 86a26ee39..758df64b1 100644 --- a/lib/puppet/rails/resource.rb +++ b/lib/puppet/rails/resource.rb @@ -26,7 +26,7 @@ class Puppet::Rails::Resource < ActiveRecord::Base # Determine the basic details on the resource. def self.rails_resource_initial_args(resource) - return [:type, :title, :line, :exported].inject({}) do |hash, param| + result = [:type, :title, :line].inject({}) do |hash, param| # 'type' isn't a valid column name, so we have to use another name. to = (param == :type) ? :restype : param if value = resource.send(param) @@ -34,6 +34,12 @@ class Puppet::Rails::Resource < ActiveRecord::Base end hash end + + # We always want a value here, regardless of what the resource has, + # so we break it out separately. + result[:exported] = resource.exported || false + + result end def add_resource_tag(tag) @@ -84,12 +90,15 @@ class Puppet::Rails::Resource < ActiveRecord::Base accumulate_benchmark("Individual resource merger", :attributes) { merge_attributes(resource) } accumulate_benchmark("Individual resource merger", :parameters) { merge_parameters(resource) } accumulate_benchmark("Individual resource merger", :tags) { merge_tags(resource) } + save() end def merge_attributes(resource) args = self.class.rails_resource_initial_args(resource) args.each do |param, value| - self[param] = value unless resource[param] == value + unless resource[param] == value + self[param] = value + end end # Handle file specially diff --git a/spec/unit/rails/resource.rb b/spec/unit/rails/resource.rb index eaead2e3d..9e2ff8cd2 100755 --- a/spec/unit/rails/resource.rb +++ b/spec/unit/rails/resource.rb @@ -38,5 +38,50 @@ describe "Puppet::Rails::Resource" do Puppet::Rails::Resource.rails_resource_initial_args(resource)[:exported].should be_true end + + it "should set 'exported' to false of the resource is not exported" do + resource = Puppet::Resource.new(:file, "/file") + resource.exported = false + + Puppet::Rails::Resource.rails_resource_initial_args(resource)[:exported].should be_false + + resource = Puppet::Resource.new(:file, "/file") + resource.exported = nil + + Puppet::Rails::Resource.rails_resource_initial_args(resource)[:exported].should be_false + end + end + + describe "when merging in a parser resource" do + before do + @parser = mock 'parser resource' + + @resource = Puppet::Rails::Resource.new + [:merge_attributes, :merge_parameters, :merge_tags, :save].each { |m| @resource.stubs(m) } + end + + it "should merge the attributes" do + @resource.expects(:merge_attributes).with(@parser) + + @resource.merge_parser_resource(@parser) + end + + it "should merge the parameters" do + @resource.expects(:merge_parameters).with(@parser) + + @resource.merge_parser_resource(@parser) + end + + it "should merge the tags" do + @resource.expects(:merge_tags).with(@parser) + + @resource.merge_parser_resource(@parser) + end + + it "should save itself" do + @resource.expects(:save) + + @resource.merge_parser_resource(@parser) + end end end |