automatically escape :task in single or double quotes

This commit is contained in:
Javan Makhmali 2010-07-01 17:04:11 -04:00
parent 3796828fb6
commit e12d3436d6
2 changed files with 39 additions and 1 deletions

View File

@ -13,7 +13,14 @@ module Whenever
end
def output
@options[:template].gsub(/:\w+/) do |key|
template = @options[:template].dup
unless @options[:escape_quotes] === false
template.sub!("':task'", %Q('#{@options[:task].gsub(/'/) { "'\''" }}'))
template.sub!('":task"', %Q("#{@options[:task].gsub(/"/) { '\"' }}"))
end
template.gsub(/:\w+/) do |key|
@options[key.sub(':', '').to_sym]
end
end

View File

@ -84,4 +84,35 @@ class OutputDefinedJobTest < Test::Unit::TestCase
end
end
context "A defined job with a task in single quotes" do
setup do
@output = Whenever.cron \
<<-file
job_type :some_job, "happy ':task'"
every 2.hours do
some_job "first 'birthday'"
end
file
end
should "output the defined job with the single quotes escaped" do
assert_match two_hours + %Q( happy 'first '\''birthday'\''), @output
end
end
context "A defined job with a task in double quotes" do
setup do
@output = Whenever.cron \
<<-file
job_type :some_job, 'happy ":task"'
every 2.hours do
some_job 'first "birthday"'
end
file
end
should "output the defined job with the single quotes escaped" do
assert_match two_hours + ' happy "first \"birthday\""', @output
end
end
end