whenever/test/job_test.rb
Jay Adkisson dd15137e41 escape quotes for bash, furrealz this time
Any parameter in a job type template which is surrounded by quotes
will now be auto-escaped.

Examples:

job_type :foo, :template => "/my/cool/bin ':bar'"

every :day do
  foo %(single quote! -> ' <-)
end

will render to

@daily /my/cool/bin 'single quote! -> '\'' <-'
2010-07-03 22:55:32 +08:00

45 lines
1.2 KiB
Ruby

require File.expand_path(File.dirname(__FILE__) + "/test_helper")
class JobTest < Test::Unit::TestCase
context "A Job" do
should "output the :task" do
job = new_job(:template => ":task", :task => 'abc123')
assert_equal %q(abc123), job.output
end
should "output the :task if it's in single quotes" do
job = new_job(:template => "':task'", :task => 'abc123')
assert_equal %q('abc123'), job.output
end
should "output the :task if it's in double quotes" do
job = new_job(:template => '":task"', :task => 'abc123')
assert_equal %q("abc123"), job.output
end
should "output escaped single quotes in when it's wrapped in them" do
job = new_job(
:template => "before ':foo' after",
:foo => "quote -> ' <- quote"
)
assert_equal %q(before 'quote -> '\'' <- quote' after), job.output
end
should "output escaped double quotes when it's wrapped in them" do
job = new_job(
:template => 'before ":foo" after',
:foo => 'quote -> " <- quote'
)
assert_equal %q(before "quote -> \" <- quote" after), job.output
end
end
private
def new_job(options)
Whenever::Job.new(options)
end
end