Skip to content
Browse files

Remove monit files when site is destroyed.

  • Loading branch information...
1 parent 1bbf3ee commit ea4b903b8d5202c55ba6483a6a8b14da54ff0cfb @brianjlandau brianjlandau committed Oct 22, 2009
Showing with 29 additions and 1 deletion.
  1. +8 −0 app/models/site.rb
  2. +1 −1 app/routes/sites.rb
  3. +20 −0 test/unit/site_test.rb
View
8 app/models/site.rb
@@ -23,6 +23,7 @@ def self.http_url
end
after_save :create_monit_check
+ after_destroy :delete_monit_check
validates_presence_of :name
validates_presence_of :url
@@ -55,4 +56,11 @@ def create_monit_check
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"
+
+ return true
+ end
end
View
2 app/routes/sites.rb
@@ -37,7 +37,7 @@ class Main
end
delete "/sites/:id" do
- Site.find(params[:id]).delete
+ Site.find(params[:id]).destroy
redirect '/'
end
end
View
20 test/unit/site_test.rb
@@ -77,6 +77,26 @@ def system(*args); end
@site.save
end
+
+ context 'that has been saved' do
+ setup do
+ @site.save
+ end
+
+ should 'remove monitrc file when destroyed' do
+ @site.destroy
+ assert !File.exist?(root_path('monitrc', RACK_ENV, "#{@site.id}.monitrc"))
+ 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)
+
+ @site.destroy
+ end
+ end
teardown do
unless @site.new_record?

0 comments on commit ea4b903

Please sign in to comment.
Something went wrong with that request. Please try again.