2010-09-06 17:18:39 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2009-02-17 00:22:37 +00:00
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
2009-02-17 00:22:37 +00:00
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
# command
|
2009-02-17 00:22:37 +00:00
|
|
|
|
2010-10-20 21:12:00 +00:00
|
|
|
context "A plain command with the job template set to nil" do
|
2010-09-07 03:38:11 +00:00
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2010-09-07 03:38:11 +00:00
|
|
|
every 2.hours do
|
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the command" do
|
|
|
|
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-20 21:12:00 +00:00
|
|
|
context "A plain command with no job template set" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
|
|
|
every 2.hours do
|
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the command with the default job template" do
|
2011-03-24 02:03:43 +00:00
|
|
|
assert_match /^.+ .+ .+ .+ \/bin\/bash -l -c 'blahblah'$/, @output
|
2010-10-20 21:12:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A plain command that overrides the job_template set" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
|
|
|
set :job_template, "/bin/bash -l -c ':job'"
|
|
|
|
every 2.hours do
|
|
|
|
command "blahblah", :job_template => "/bin/sh -l -c ':job'"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the command using that job_template" do
|
|
|
|
assert_match /^.+ .+ .+ .+ \/bin\/sh -l -c 'blahblah'$/, @output
|
|
|
|
assert_no_match /bash/, @output
|
|
|
|
end
|
|
|
|
end
|
2010-10-26 01:14:45 +00:00
|
|
|
|
|
|
|
context "A plain command that is conditional on default environent and path" do
|
|
|
|
setup do
|
|
|
|
Whenever.expects(:path).at_least_once.returns('/what/you/want')
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
|
|
|
set :job_template, nil
|
|
|
|
if environment == 'production' && path == '/what/you/want'
|
|
|
|
every 2.hours do
|
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the command" do
|
|
|
|
assert_match /blahblah/, @output
|
|
|
|
end
|
|
|
|
end
|
2010-10-20 21:12:00 +00:00
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
# runner
|
|
|
|
|
|
|
|
context "A runner with path set" do
|
2009-02-17 00:22:37 +00:00
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-02-17 00:22:37 +00:00
|
|
|
set :path, '/my/path'
|
|
|
|
every 2.hours do
|
2010-09-07 03:38:11 +00:00
|
|
|
runner 'blahblah'
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
should "output the runner using that path" do
|
|
|
|
assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
context "A runner that overrides the path set" do
|
2009-02-17 00:22:37 +00:00
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-02-17 00:22:37 +00:00
|
|
|
set :path, '/my/path'
|
|
|
|
every 2.hours do
|
2010-09-07 03:38:11 +00:00
|
|
|
runner "blahblah", :path => '/some/other/path'
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
should "output the runner using that path" do
|
|
|
|
assert_match two_hours + %( cd /some/other/path && script/runner -e production 'blahblah'), @output
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-18 16:08:28 +00:00
|
|
|
context "A runner for a Rails 3 app" do
|
|
|
|
setup do
|
2010-10-19 21:37:10 +00:00
|
|
|
Whenever.expects(:path).at_least_once.returns('/my/path')
|
2011-07-19 08:17:17 +00:00
|
|
|
Whenever.expects(:rails3?).returns(true)
|
2010-10-18 16:08:28 +00:00
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2010-10-18 16:08:28 +00:00
|
|
|
every 2.hours do
|
|
|
|
runner 'blahblah'
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "use the Rails 3 runner job by default" do
|
|
|
|
assert_match two_hours + %( cd /my/path && script/rails runner -e production 'blahblah'), @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
# rake
|
|
|
|
|
|
|
|
context "A rake command with path set" do
|
2009-02-17 00:22:37 +00:00
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-02-17 00:22:37 +00:00
|
|
|
set :path, '/my/path'
|
|
|
|
every 2.hours do
|
|
|
|
rake "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
should "output the rake command using that path" do
|
2010-10-18 14:41:00 +00:00
|
|
|
assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', @output
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
context "A rake command that overrides the path set" do
|
2009-02-17 00:22:37 +00:00
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-02-17 00:22:37 +00:00
|
|
|
set :path, '/my/path'
|
|
|
|
every 2.hours do
|
2010-09-07 03:38:11 +00:00
|
|
|
rake "blahblah", :path => '/some/other/path'
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
should "output the rake command using that path" do
|
2010-10-18 14:41:00 +00:00
|
|
|
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production rake blahblah --silent', @output
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|