Skip to content

Commit

Permalink
Sets the PATH automatically unless it's already provided or told not to.
Browse files Browse the repository at this point in the history
  • Loading branch information
javan committed Jul 15, 2009
1 parent ed86aeb commit 51a6b37
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
7 changes: 6 additions & 1 deletion 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]

Expand Down
15 changes: 15 additions & 0 deletions lib/job_list.rb
Expand Up @@ -57,6 +57,8 @@ def rake(task, options = {})
end

def generate_cron_output
set_path_environment_variable

[environment_variables, cron_jobs].compact.join
end

Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Expand Up @@ -2,7 +2,7 @@ module Whenever
module VERSION #:nodoc:
MAJOR = 0
MINOR = 3
TINY = 5
TINY = 6

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
33 changes: 33 additions & 0 deletions test/output_env_test.rb
Expand Up @@ -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
4 changes: 2 additions & 2 deletions whenever.gemspec
Expand Up @@ -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"]
Expand Down

0 comments on commit 51a6b37

Please sign in to comment.