Raise an exception when trying to use an :at with the cron shortcuts.
This commit is contained in:
parent
f2307605d8
commit
801c2ad7e1
@ -27,7 +27,7 @@ module Whenever
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def parse_symbol
|
def parse_symbol
|
||||||
case @time
|
shortcut = case @time
|
||||||
when :reboot then '@reboot'
|
when :reboot then '@reboot'
|
||||||
when :year, :yearly then '@annually'
|
when :year, :yearly then '@annually'
|
||||||
when :day, :daily then '@daily'
|
when :day, :daily then '@daily'
|
||||||
@ -35,7 +35,16 @@ module Whenever
|
|||||||
when :month, :monthly then '@monthly'
|
when :month, :monthly then '@monthly'
|
||||||
when :week, :weekly then '@weekly'
|
when :week, :weekly then '@weekly'
|
||||||
when :hour, :hourly then '@hourly'
|
when :hour, :hourly then '@hourly'
|
||||||
else parse_as_string
|
end
|
||||||
|
|
||||||
|
if shortcut
|
||||||
|
if @at > 0
|
||||||
|
raise ArgumentError, "You cannot specify an ':at' when using the shortcuts for times."
|
||||||
|
else
|
||||||
|
return shortcut
|
||||||
|
end
|
||||||
|
else
|
||||||
|
parse_as_string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -167,6 +167,35 @@ class CronTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "When parsing time using the cron shortcuts" do
|
||||||
|
should "parse a :symbol into the correct shortcut" do
|
||||||
|
assert_equal '@reboot', parse_time(:reboot)
|
||||||
|
assert_equal '@annually', parse_time(:year)
|
||||||
|
assert_equal '@annually', parse_time(:yearly)
|
||||||
|
assert_equal '@daily', parse_time(:day)
|
||||||
|
assert_equal '@daily', parse_time(:daily)
|
||||||
|
assert_equal '@midnight', parse_time(:midnight)
|
||||||
|
assert_equal '@monthly', parse_time(:month)
|
||||||
|
assert_equal '@monthly', parse_time(:monthly)
|
||||||
|
assert_equal '@hourly', parse_time(:hour)
|
||||||
|
assert_equal '@hourly', parse_time(:hourly)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "raise an exception if a valid shortcut is given but also an :at" do
|
||||||
|
assert_raises ArgumentError do
|
||||||
|
parse_time(:hour, nil, "1:00 am")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raises ArgumentError do
|
||||||
|
parse_time(:reboot, nil, 5)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raises ArgumentError do
|
||||||
|
parse_time(:day, nil, '4:20pm')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assert_days_and_hours_and_minutes_equals(expected, time)
|
def assert_days_and_hours_and_minutes_equals(expected, time)
|
||||||
|
Loading…
Reference in New Issue
Block a user