From 51a6b3720a37bb1412ae60efeba368c6f81e43e4 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Wed, 15 Jul 2009 15:37:03 -0400 Subject: [PATCH] Sets the PATH automatically unless it's already provided or told not to. --- CHANGELOG.rdoc | 7 ++++++- lib/job_list.rb | 15 +++++++++++++++ lib/version.rb | 2 +- test/output_env_test.rb | 33 +++++++++++++++++++++++++++++++++ whenever.gemspec | 4 ++-- 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 4505d2a1..531221ba 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,6 +1,11 @@ +== 0.3.6 / June 15th, 2009 + +* Setting a PATH in the crontab automatically based on the user's PATH. [Javan Makhmali] + + == 0.3.5 / June 13th, 2009 -* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm, 6am']). [Sam Ruby] +* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm', '6am']). [Sam Ruby] * Fixed issue with new lines. #18 [Javan Makhmali] diff --git a/lib/job_list.rb b/lib/job_list.rb index 60b4ec04..dd437fb3 100644 --- a/lib/job_list.rb +++ b/lib/job_list.rb @@ -57,6 +57,8 @@ def rake(task, options = {}) end def generate_cron_output + set_path_environment_variable + [environment_variables, cron_jobs].compact.join end @@ -77,6 +79,19 @@ def pre_set(variable_string = nil) set(variable.strip, value.strip) unless variable.blank? || value.blank? end end + + def set_path_environment_variable + return if path_should_not_be_set_automatically? + @env[:PATH] = read_path unless read_path.blank? + end + + def read_path + ENV['PATH'] if ENV + end + + def path_should_not_be_set_automatically? + @set_path_automatically === false || @env[:PATH] || @env["PATH"] + end def environment_variables return if @env.empty? diff --git a/lib/version.rb b/lib/version.rb index 54232466..a2b93f04 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -2,7 +2,7 @@ module Whenever module VERSION #:nodoc: MAJOR = 0 MINOR = 3 - TINY = 5 + TINY = 6 STRING = [MAJOR, MINOR, TINY].join('.') end diff --git a/test/output_env_test.rb b/test/output_env_test.rb index 997c53c8..7ecfc60b 100644 --- a/test/output_env_test.rb +++ b/test/output_env_test.rb @@ -19,5 +19,38 @@ class OutputEnvTest < Test::Unit::TestCase assert_match "MAILTO=someone@example.com", @output end end + + context "No PATH environment variable set" do + setup do + Whenever::JobList.any_instance.expects(:read_path).at_least_once.returns('/usr/local/bin') + @output = Whenever.cron "" + end + + should "add a PATH variable based on the user's PATH" do + assert_match "PATH=/usr/local/bin", @output + end + end + + context "A PATH environment variable set" do + setup do + Whenever::JobList.stubs(:read_path).returns('/usr/local/bin') + @output = Whenever.cron "env :PATH, '/my/path'" + end + + should "use that path and the user's PATH" do + assert_match "PATH=/my/path", @output + assert_no_match /local/, @output + end + end + + context "No PATH set and instructed not to automatically load the user's path" do + setup do + @output = Whenever.cron "set :set_path_automatically, false" + end + + should "not have a PATH set" do + assert_no_match /PATH/, @output + end + end end \ No newline at end of file diff --git a/whenever.gemspec b/whenever.gemspec index 8c385020..df80a2ee 100644 --- a/whenever.gemspec +++ b/whenever.gemspec @@ -2,11 +2,11 @@ Gem::Specification.new do |s| s.name = %q{whenever} - s.version = "0.3.5" + s.version = "0.3.6" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= s.authors = ["Javan Makhmali"] - s.date = %q{2009-07-13} + s.date = %q{2009-07-15} s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.} s.email = %q{javan@javan.us} s.executables = ["whenever", "wheneverize"]