automatically escape :task in single or double quotes
This commit is contained in:
parent
3796828fb6
commit
e12d3436d6
@ -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
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user