diff --git a/lib/whenever/job.rb b/lib/whenever/job.rb index e41cc4b..c4be4fb 100644 --- a/lib/whenever/job.rb +++ b/lib/whenever/job.rb @@ -9,7 +9,7 @@ module Whenever @template = options.delete(:template) @job_template = options.delete(:job_template) || ":job" @options[:output] = Whenever::Output::Redirection.new(options[:output]).to_s if options.has_key?(:output) - #@options[:environment] ||= :production + @options[:environment] ||= :production @options[:path] ||= Whenever.path end diff --git a/lib/whenever/job_types/default.rb b/lib/whenever/job_types/default.rb index 1395e13..2b2a4a4 100644 --- a/lib/whenever/job_types/default.rb +++ b/lib/whenever/job_types/default.rb @@ -1,9 +1,13 @@ +set :environment, "production" +set :path, Whenever.path + # http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production set :job_template, "/bin/bash -l -c ':job'" 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(Whenever.path, 'script', 'rails')) job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output" else diff --git a/test/functional/output_default_defined_jobs_test.rb b/test/functional/output_default_defined_jobs_test.rb index 95de17c..6dd389d 100644 --- a/test/functional/output_default_defined_jobs_test.rb +++ b/test/functional/output_default_defined_jobs_test.rb @@ -51,6 +51,25 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase assert_no_match /bash/, @output end end + + 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 # runner