Permalink
Browse files

Generate stop billing event for a deleted app.

The stop billing event was earlier not created when the app was deleted
without being stopped first.

Change-Id: Ia58e61cc51ceffa4245648a9437cf383a8bf59d5
  • Loading branch information...
1 parent 0bed9b1 commit 5ee59faecf14ffc64f80f39a3cd1c2d26052dda3 @kowshik kowshik committed Jan 2, 2013
Showing with 18 additions and 0 deletions.
  1. +1 −0 lib/cloud_controller/models/app.rb
  2. +17 −0 spec/models/app_spec.rb
@@ -100,6 +100,7 @@ def after_destroy_commit
VCAP::CloudController::DeaClient.stop(self) if started?
VCAP::CloudController::AppStager.delete_droplet(self)
VCAP::CloudController::AppPackage.delete_package(self.guid)
+ AppStopEvent.create_from_app(self) unless stopped?
end
def command=(cmd)
View
@@ -498,6 +498,23 @@ module VCAP::CloudController
app.update(:state => "STARTED")
end
end
+
+ context "deleting a started app" do
+ it "should call AppStopEvent.create_from_app" do
+ app = Models::App.make(:state => "STARTED")
+ VCAP::CloudController::DeaClient.stub(:stop)
+ Models::AppStopEvent.should_receive(:create_from_app).with(app)
+ app.destroy
+ end
+ end
+
+ context "deleting a stopped app" do
+ it "should not call AppStopEvent.create_from_app" do
+ app = Models::App.make(:state => "STOPPED")
+ Models::AppStopEvent.should_not_receive(:create_from_app)
+ app.destroy
+ end
+ end
end
end
end

0 comments on commit 5ee59fa

Please sign in to comment.