encapsulate rails 3 check for easier testing

This commit is contained in:
Michał Szajbe 2011-07-19 10:17:17 +02:00
parent 42061be142
commit b405def424
3 changed files with 7 additions and 3 deletions

View File

@ -19,4 +19,8 @@ module Whenever
Dir.pwd
end
def self.rails3?
File.exists?(File.join(path, 'script', 'rails'))
end
end

View File

@ -11,7 +11,7 @@ job_type :command, ":task :output"
job_type :rake, "cd :path && RAILS_ENV=:environment rake :task --silent :output"
# Create a runner job that's appropriate for the Rails version,
if File.exists?(File.join(path, 'script', 'rails'))
if Whenever.rails3?
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
else
job_type :runner, "cd :path && script/runner -e :environment ':task' :output"

View File

@ -110,7 +110,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
context "A runner for a Rails 3 app" do
setup do
Whenever.expects(:path).at_least_once.returns('/my/path')
File.expects(:exists?).with('/my/path/script/rails').returns(true)
Whenever.expects(:rails3?).returns(true)
@output = Whenever.cron \
<<-file
set :job_template, nil