summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantima-gupta <agupta@msystechnologies.com>2020-05-11 13:19:08 +0530
committerantima-gupta <agupta@msystechnologies.com>2020-06-10 10:51:40 +0530
commit33d608179372fed46c1c5a88f214677748b8de8c (patch)
tree2c0907f280730b4d1b7333b005d91adb501f8ad0
parent578a69011eadda14e51c2ca83f9206f58b9a6243 (diff)
downloadchef-33d608179372fed46c1c5a88f214677748b8de8c.tar.gz
Added freeze for WEEKDAYS constant.
Fixed chefstyle spec failure. Made changes as per review comment. Signed-off-by: antima-gupta <agupta@msystechnologies.com>
-rw-r--r--lib/chef/resource/helpers/cron.rb14
-rw-r--r--spec/functional/resource/cron_spec.rb8
-rw-r--r--spec/unit/resource/helpers/cron_spec.rb2
3 files changed, 13 insertions, 11 deletions
diff --git a/lib/chef/resource/helpers/cron.rb b/lib/chef/resource/helpers/cron.rb
index dcf50e0f94..78c3e09b38 100644
--- a/lib/chef/resource/helpers/cron.rb
+++ b/lib/chef/resource/helpers/cron.rb
@@ -1,19 +1,21 @@
class Chef
module ResourceHelpers
module Cron
- WEEKDAYS = { sunday: '0', monday: '1', tuesday: '2', wednesday: '3', thursday: '4', friday: '5', saturday: '6',
- sun: '0', mon: '1', tue: '2', wed: '3', thu: '4', fri: '5', sat: '6'
- }
+
+ WEEKDAYS = {
+ sunday: "0", monday: "1", tuesday: "2", wednesday: "3", thursday: "4", friday: "5", saturday: "6",
+ sun: "0", mon: "1", tue: "2", wed: "3", thu: "4", fri: "5", sat: "6"
+ }.freeze
# Convert weekday input value into crontab format that
# could be written in the crontab
# @return [Integer, String] A weekday formed as per the user inputs.
def weekday_in_crontab(wday)
- weekday = wday.to_s.downcase
- weekday_in_crontab = WEEKDAYS[weekday.to_sym] || wday
+ weekday = wday.to_s.downcase.to_sym
+ weekday_in_crontab = WEEKDAYS[weekday] || wday
end
extend self
end
end
-end \ No newline at end of file
+end
diff --git a/spec/functional/resource/cron_spec.rb b/spec/functional/resource/cron_spec.rb
index 3a26226115..ed4905b980 100644
--- a/spec/functional/resource/cron_spec.rb
+++ b/spec/functional/resource/cron_spec.rb
@@ -80,13 +80,13 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
5.times { new_resource.run_action(:create) }
cron_should_exists(new_resource.name, new_resource.command)
end
-
+
# Test cron for day of week
weekdays = { Mon: 1, tuesday: 2, '3': 3, 'thursday': 4, 'Fri': 5, 6 => 6 }
- weekdays.each do|key, value|
- it "should create crontab entry and set #{value} for mon as weekday" do
+ weekdays.each do |key, value|
+ it "should create crontab entry and set #{value} for #{key} as weekday" do
new_resource.weekday key
- expect{ new_resource.run_action(:create) }.not_to raise_error
+ expect { new_resource.run_action(:create) }.not_to raise_error
cron_should_exists(new_resource.name, new_resource.command)
end
end
diff --git a/spec/unit/resource/helpers/cron_spec.rb b/spec/unit/resource/helpers/cron_spec.rb
index 758827e4ca..f1e3457a2c 100644
--- a/spec/unit/resource/helpers/cron_spec.rb
+++ b/spec/unit/resource/helpers/cron_spec.rb
@@ -28,4 +28,4 @@ describe Chef::ResourceHelpers::Cron do
end
end
end
-end \ No newline at end of file
+end