diff options
-rw-r--r-- | lib/chef/provider/cron.rb | 6 | ||||
-rw-r--r-- | spec/unit/provider/cron_spec.rb | 34 |
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb index 7d37f34b1a..ec8df36998 100644 --- a/lib/chef/provider/cron.rb +++ b/lib/chef/provider/cron.rb @@ -88,7 +88,11 @@ class Chef def cron_different? CRON_ATTRIBUTES.any? do |cron_var| - new_resource.send(cron_var) != current_resource.send(cron_var) + if new_resource.send(cron_var).class == current_resource.send(cron_var).class + new_resource.send(cron_var) != current_resource.send(cron_var) + else + new_resource.send(cron_var).to_s != current_resource.send(cron_var).to_s + end end end diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb index 76f170312e..3455e3de4f 100644 --- a/spec/unit/provider/cron_spec.rb +++ b/spec/unit/provider/cron_spec.rb @@ -724,6 +724,40 @@ describe Chef::Provider::Cron do end end + context "when integers are provided to the resource to express time values" do + it "should not report any difference" do + @new_resource.minute(1) + @new_resource.hour(1) + @new_resource.day(1) + @new_resource.month(1) + @new_resource.weekday(1) + allow(@provider).to receive(:read_crontab).and_return(<<~CRONTAB) + # Chef Name: cronhole some stuff + 1 1 1 1 1 /bin/true + CRONTAB + + @provider.run_action(:create) + expect(@new_resource).not_to be_updated_by_last_action + end + end + + context "when strings are provided to the resource to express time values" do + it "should not report any difference" do + @new_resource.minute("1") + @new_resource.hour("1") + @new_resource.day("1") + @new_resource.month("1") + @new_resource.weekday("1") + allow(@provider).to receive(:read_crontab).and_return(<<~CRONTAB) + # Chef Name: cronhole some stuff + 1 1 1 1 1 /bin/true + CRONTAB + + @provider.run_action(:create) + expect(@new_resource).not_to be_updated_by_last_action + end + end + context "when environment variable is used" do before :each do @provider.cron_exists = true |