Don't leave Whenever comments when clearing
This commit is contained in:
parent
2060cb95fa
commit
20faaa266d
@ -30,7 +30,6 @@ module Whenever
|
||||
exit(1)
|
||||
end
|
||||
@options[:cut] = @options[:cut].to_i
|
||||
|
||||
end
|
||||
|
||||
def run
|
||||
@ -51,7 +50,8 @@ module Whenever
|
||||
end
|
||||
|
||||
def whenever_cron
|
||||
@whenever_cron ||= [comment_open, (Whenever.cron(@options) unless @options[:clear]), comment_close].compact.join("\n") + "\n"
|
||||
return '' if @options[:clear]
|
||||
@whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].compact.join("\n") + "\n"
|
||||
end
|
||||
|
||||
def read_crontab
|
||||
@ -102,7 +102,7 @@ module Whenever
|
||||
read_crontab.gsub(Regexp.new("^#{comment_open}$.+^#{comment_close}$", Regexp::MULTILINE), whenever_cron.chomp.gsub('\\', '\\\\\\'))
|
||||
else # Otherwise, append the new cron entries after any existing ones
|
||||
[read_crontab, whenever_cron].join("\n\n")
|
||||
end
|
||||
end.gsub(/\n{3,}/, "\n\n") # More than two newlines becomes just two.
|
||||
end
|
||||
|
||||
def prepare(contents)
|
||||
|
@ -120,35 +120,18 @@ NEW_CRON
|
||||
end
|
||||
|
||||
should "append the similarly named command" do
|
||||
assert_equal @existing + "\n\n" + @new, @command.send(:updated_crontab)
|
||||
assert_equal @existing + "\n" + @new, @command.send(:updated_crontab)
|
||||
end
|
||||
end
|
||||
|
||||
context "A command line delete" do
|
||||
context "A command line clear" do
|
||||
setup do
|
||||
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
||||
@command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')
|
||||
@task = "#{two_hours} /my/command"
|
||||
end
|
||||
|
||||
should "add an empty identifier block if there is no existing one" do
|
||||
existing = '# Existing crontab'
|
||||
@command.expects(:read_crontab).at_least_once.returns(existing)
|
||||
|
||||
new_cron = <<-EXPECTED
|
||||
#{existing}
|
||||
|
||||
# Begin Whenever generated tasks for: My identifier
|
||||
# End Whenever generated tasks for: My identifier
|
||||
EXPECTED
|
||||
|
||||
assert_equal new_cron, @command.send(:updated_crontab)
|
||||
|
||||
@command.expects(:write_crontab).with(new_cron).returns(true)
|
||||
assert @command.run
|
||||
end
|
||||
|
||||
should "delete an existing block if the identifier matches" do
|
||||
should "clear an existing block if the identifier matches" do
|
||||
existing = <<-EXISTING_CRON
|
||||
# Something
|
||||
|
||||
@ -166,9 +149,6 @@ EXISTING_CRON
|
||||
new_cron = <<-NEW_CRON
|
||||
# Something
|
||||
|
||||
# Begin Whenever generated tasks for: My identifier
|
||||
# End Whenever generated tasks for: My identifier
|
||||
|
||||
# Begin Whenever generated tasks for: Other identifier
|
||||
This shouldn't get replaced
|
||||
# End Whenever generated tasks for: Other identifier
|
||||
|
Loading…
Reference in New Issue
Block a user