Permalink
Browse files

Moved Monit reloading into its own module

  • Loading branch information...
1 parent 76620de commit 002fe791f4dc8d8b9b9c539c26abbb57362d0bfb @cndreisbach cndreisbach committed Oct 23, 2009
Showing with 15 additions and 13 deletions.
  1. +7 −0 app/models/monit.rb
  2. +2 −2 app/models/site.rb
  3. +3 −0 test/test_helper.rb
  4. +3 −11 test/unit/site_test.rb
View
@@ -0,0 +1,7 @@
+module Monit
+ extend self
+
+ def reload
+ system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload"
+ end
+end
View
@@ -52,14 +52,14 @@ def create_monit_check
end
FileUtils.chmod 0700, root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
- system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload"
+ Monit.reload
return true
end
def delete_monit_check
FileUtils.rm_f root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
- system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload"
+ Monit.reload
return true
end
View
@@ -50,3 +50,6 @@ def assert_does_not_contain(collection, x, extra_msg = "")
self.backtrace_silencers << :vendor
end
+Monit.class_eval do
+ def system(*args); args; end
+end
View
@@ -1,6 +1,6 @@
require "test_helper"
-class SiteTest < Test::Unit::TestCase
+class SiteTest < Test::Unit::TestCase
context 'A site' do
setup do
@site = Factory.build(:site)
@@ -70,11 +70,7 @@ class SiteTest < Test::Unit::TestCase
end
should 'reload monit' do
- @site.class_eval do
- def system(*args); end
- end
- @site.expects(:system).with("#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload").returns(true)
-
+ Monit.expects(:reload)
@site.save
end
@@ -89,11 +85,7 @@ def system(*args); end
end
should 'reload monit when destroyed' do
- @site.class_eval do
- def system(*args); end
- end
- @site.expects(:system).with("#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload").returns(true)
-
+ Monit.expects(:reload)
@site.destroy
end
end

0 comments on commit 002fe79

Please sign in to comment.