summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/cron.rb12
-rw-r--r--lib/chef/resource/cron.rb2
-rw-r--r--spec/unit/provider/cron_spec.rb19
3 files changed, 31 insertions, 2 deletions
diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb
index 87452b4872..e80f70d8bb 100644
--- a/lib/chef/provider/cron.rb
+++ b/lib/chef/provider/cron.rb
@@ -29,6 +29,7 @@ class Chef
ENV_PATTERN = /\A(\S+)=(\S*)/
CRON_ATTRIBUTES = [:minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home, :environment]
+ WEEKDAY_SYMBOLS = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
def initialize(new_resource, run_context)
super(new_resource, run_context)
@@ -220,9 +221,18 @@ class Chef
@new_resource.environment.each do |name, value|
newcron << "#{name}=#{value}\n"
end
- newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
+ newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{weekday_in_crontab} #{@new_resource.command}\n"
newcron
end
+
+ def weekday_in_crontab
+ weekday_in_crontab = WEEKDAY_SYMBOLS.index(@new_resource.weekday)
+ if weekday_in_crontab.nil?
+ @new_resource.weekday
+ else
+ weekday_in_crontab.to_s
+ end
+ end
end
end
end
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index dfbb91f80c..248f0038b5 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -127,7 +127,7 @@ class Chef
set_or_return(
:weekday,
converted_arg,
- :kind_of => String
+ :kind_of => [String, Symbol]
)
end
diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb
index 3a7a96c549..181ab23d7e 100644
--- a/spec/unit/provider/cron_spec.rb
+++ b/spec/unit/provider/cron_spec.rb
@@ -833,4 +833,23 @@ MAILTO=foo@example.com
end
end
+
+ describe "weekday_in_crontab" do
+ context "when weekday is symbol" do
+ before do
+ @new_resource.weekday :wednesday
+ end
+ it "should return weekday in crontab format" do
+ @provider.send(:weekday_in_crontab).should eq("3")
+ end
+ end
+ context "when weekday is string" do
+ before do
+ @new_resource.weekday "3"
+ end
+ it "should return the string" do
+ @provider.send(:weekday_in_crontab).should eq("3")
+ end
+ end
+ end
end