From b405def42411a81876c3a0ec6cc3e4954ba72211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szajbe?= Date: Tue, 19 Jul 2011 10:17:17 +0200 Subject: [PATCH] encapsulate rails 3 check for easier testing --- lib/whenever.rb | 6 +++++- lib/whenever/setup.rb | 2 +- test/functional/output_default_defined_jobs_test.rb | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/whenever.rb b/lib/whenever.rb index 8fbe7a5..fe23376 100644 --- a/lib/whenever.rb +++ b/lib/whenever.rb @@ -19,4 +19,8 @@ module Whenever Dir.pwd end -end \ No newline at end of file + def self.rails3? + File.exists?(File.join(path, 'script', 'rails')) + end + +end diff --git a/lib/whenever/setup.rb b/lib/whenever/setup.rb index 64e6f33..2e15c1a 100644 --- a/lib/whenever/setup.rb +++ b/lib/whenever/setup.rb @@ -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" diff --git a/test/functional/output_default_defined_jobs_test.rb b/test/functional/output_default_defined_jobs_test.rb index 6dd389d..27691ff 100644 --- a/test/functional/output_default_defined_jobs_test.rb +++ b/test/functional/output_default_defined_jobs_test.rb @@ -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