diff options
author | Luke Kanies <luke@madstop.com> | 2009-06-01 17:50:55 -0500 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-06-03 07:33:33 +1000 |
commit | 650029e3730431dcc21863d92fd50c74665cea38 (patch) | |
tree | e0c4b77c10a6a199ffc8331b2ac29df731b4bd2a | |
parent | f1dba91bbde7919cb0a0fd412faacb1f7dd2c84d (diff) | |
download | puppet-650029e3730431dcc21863d92fd50c74665cea38.tar.gz puppet-650029e3730431dcc21863d92fd50c74665cea38.tar.xz puppet-650029e3730431dcc21863d92fd50c74665cea38.zip |
Always providing a value for 'exported' on Rails resources
We often didn't set a value, unless it was true, which
meant that if it had previously been true but was now
false, we didn't fix it.
We also were not always saving modified resources, which
in some cases resulted in work not getting saved.
Signed-off-by: Luke Kanies <luke@madstop.com>
-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 |