Permalink
Browse files

Merge pull request #3 from nature/fix_for_correctness

Some Bug Fixes!
  • Loading branch information...
2 parents 9675957 + 646fa86 commit dfc397fa5a00a07d5a49994da385736abc7c5195 @alexspeller alexspeller committed Jan 19, 2012
Showing with 38 additions and 1 deletion.
  1. +10 −1 lib/foreman/export/nature_runit/service.rb
  2. +28 −0 spec/foreman/export/nature_runit/service_spec.rb
@@ -31,15 +31,24 @@ def activate!
def export_environment!
create_if_missing(environment_target)
+ clean_old_environment!
environment.each do |key, value|
write_file(environment_target.join(key), value)
end
end
def export_run_script!
+ run_script_path = target.join('run')
+
create_if_missing(target)
- write_file(target.join('run'), run_script)
+ write_file(run_script_path, run_script)
+ FileUtils.chmod(0755, run_script_path.to_s)
+ end
+
+ def clean_old_environment!
+ glob = environment_target.join('*').to_s
+ FileUtils.rm(Dir[glob])
end
private
@@ -11,6 +11,10 @@
before(:each) do
subject.stub!(:create_if_missing)
subject.stub!(:write_file)
+ FileUtils.stub!(:chmod)
+ FileUtils.stub!(:symlink)
+ FileUtils.stub!(:rm)
+ Dir.stub!(:[] => [])
end
describe ".new" do
@@ -57,6 +61,12 @@
subject.export_run_script!
end
+ it "chmod '0755'" do
+ FileUtils.should_receive(:chmod).with(0755, subject.target.join('run').to_s)
+
+ subject.export_run_script!
+ end
+
end
describe "#run_script" do
@@ -93,5 +103,23 @@
subject.export_environment!
end
+ it "cleans the environment_target" do
+ subject.should_receive(:clean_old_environment!)
+ subject.export_environment!
+ end
+ end
+
+ describe "clean_old_environment!" do
+ let(:env_glob) { "#{subject.environment_target.to_s}/*" }
+ let(:env_foo) { target.join('env', 'FOO').to_s }
+ let(:env_bar) { target.join('env', 'BAR').to_s }
+ let(:fake_files) { [env_foo, env_bar] }
+
+ it "clears all the files out of the environment_target" do
+ Dir.should_receive(:[]).with(env_glob).and_return(fake_files)
+ FileUtils.should_receive(:rm).with(fake_files)
+
+ subject.clean_old_environment!
+ end
end
end

0 comments on commit dfc397f

Please sign in to comment.