diff --git a/spec/defines/rule_spec.rb b/spec/defines/rule_spec.rb index 78115c4b..aa080416 100644 --- a/spec/defines/rule_spec.rb +++ b/spec/defines/rule_spec.rb @@ -1171,4 +1171,19 @@ end end end + context 'template should not inherit variables from other scopes' do + let(:title) { 'foo' } + let(:params) { + {:path => '/var/log/foo.log',:ifempty => true} + } + let(:facts) { + { + :osfamily => 'RedHat', + :operatingsystemmajrelease => 7 + } + } + it do + should contain_file('/etc/logrotate.d/btmp').without_content(/ifempty/) + end + end end diff --git a/templates/etc/logrotate.d/rule.erb b/templates/etc/logrotate.d/rule.erb index 67ca0148..24c641ae 100644 --- a/templates/etc/logrotate.d/rule.erb +++ b/templates/etc/logrotate.d/rule.erb @@ -10,7 +10,7 @@ rpath = @path end - if scope.to_hash.has_key?('sane_create') + if has_variable?('sane_create') if @sane_create == 'create' opts << [@sane_create, @create_mode, @create_owner, @create_group].reject { |r| r == 'undef' @@ -20,7 +20,7 @@ end end - if scope.to_hash.has_key?('sane_su') + if has_variable('sane_su') if @sane_su == 'su' opts << [@sane_su, @su_owner, @su_group].reject { |r| r == 'undef' @@ -33,7 +33,7 @@ 'mail', 'missingok', 'olddir', 'sharedscripts', 'ifempty', 'maillast', 'mailfirst', 'shred', 'rotate_every' ].each do |bool| - opts << scope.to_hash["sane_#{bool}"] if scope.to_hash.has_key?("sane_#{bool}") + opts << instance_variable_get("@sane_#{bool}") if has_variable?("sane_#{bool}") end [ @@ -41,7 +41,7 @@ 'maxage', 'minsize', 'rotate', 'size', 'shredcycles', 'start', 'uncompresscmd' ].each do |key| - value = scope.to_hash[key] + value = instance_variable_get(key) opts << "#{key} #{value}" if value != 'undef' end -%>