From 0055c36aef642f8574b22eb2149102e5a8035967 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Mon, 18 Oct 2010 12:08:28 -0400 Subject: [PATCH] runners for Rails 3 --- lib/whenever/job_types/rails3.rb | 8 +++++++ .../output_default_defined_jobs_test.rb | 22 +++++++++++++++++++ test/functional/output_defined_job_test.rb | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 lib/whenever/job_types/rails3.rb diff --git a/lib/whenever/job_types/rails3.rb b/lib/whenever/job_types/rails3.rb new file mode 100644 index 0000000..c16c0c0 --- /dev/null +++ b/lib/whenever/job_types/rails3.rb @@ -0,0 +1,8 @@ +# Determine if this is a Rails 3 app by looking for a script/rails file. +# If it is, preserve the Rails 2 runner job as rails2_runner and then +# define a new job for Rails 3 as the default runner. + +if File.exists?(File.join(Whenever.path, 'script', 'rails')) + class_eval { alias_method :rails2_runner, :runner } + job_type :runner, "cd :path && script/rails runner -e :environment ':task'" +end \ No newline at end of file diff --git a/test/functional/output_default_defined_jobs_test.rb b/test/functional/output_default_defined_jobs_test.rb index 95ce6a9..df83f90 100644 --- a/test/functional/output_default_defined_jobs_test.rb +++ b/test/functional/output_default_defined_jobs_test.rb @@ -53,6 +53,28 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase end end + context "A runner for a Rails 3 app" do + setup do + Whenever.stubs(:path).returns('/my/path') + File.expects(:exists?).with('/my/path/script/rails').returns(true) + @output = Whenever.cron \ + <<-file + every 2.hours do + runner 'blahblah' + rails2_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 + + should "have the Rails 2 runner job redefined as rails2_runner" do + assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output + end + end + # rake context "A rake command with path set" do diff --git a/test/functional/output_defined_job_test.rb b/test/functional/output_defined_job_test.rb index 322dd37..d220893 100644 --- a/test/functional/output_defined_job_test.rb +++ b/test/functional/output_defined_job_test.rb @@ -86,7 +86,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase context "A defined job that uses a :path where none is explicitly set" do setup do - Whenever.expects(:path).returns('/my/path') + Whenever.stubs(:path).returns('/my/path') @output = Whenever.cron \ <<-file