Skip to content
Browse files

Fix: Deleting app/app authorization

- delete app_authorizations when deleteing app
- delete notification_subscriptinos when deleting app authorization

fixes #61
  • Loading branch information...
1 parent f3ef4aa commit 27925c079983ea9c4a86152329a6e1633e3dcef0 Jesse Stuart committed Dec 28, 2012
View
5 lib/tentd/model/app.rb
@@ -31,6 +31,11 @@ def before_save
super
end
+ def after_destroy
+ authorizations_dataset.destroy
+ super
+ end
+
def self.create_from_params(params={})
create(params.slice(*public_attributes))
end
View
5 lib/tentd/model/app_authorization.rb
@@ -40,6 +40,11 @@ def after_save
super
end
+ def after_destroy
+ notification_subscriptions_dataset.destroy
+ super
+ end
+
def self.follow_url(entity)
app_auth = qualify.join(:apps, :apps__id => :app_authorizations__app_id).where(:apps__user_id => User.current.id).where(Sequel.~(:app_authorizations__follow_url => nil)).order(:app_authorizations__id.desc).where("app_authorizations.scopes @> ARRAY['follow_ui']").first
return unless app_auth
View
18 spec/integration/model/app_authorization_spec.rb
@@ -43,6 +43,24 @@
expect(auth2.reload.scopes).to eql(['follow_ui'])
end
+ describe '#destroy' do
+ let(:notification_subscription) { Fabricate(:notification_subscription, :app_authorization => app_authorization) }
+
+ it 'should delete app authorization' do
+ app_authorization # create
+ expect(lambda {
+ app_authorization.destroy
+ }).to change(TentD::Model::AppAuthorization, :count).by(-1)
+ end
+
+ it 'should delete notification subscription' do
+ notification_subscription # create
+ expect(lambda {
+ app_authorization.destroy
+ }).to change(TentD::Model::NotificationSubscription, :count).by(-1)
+ end
+ end
+
describe '#as_json' do
let(:app_attributes) do
{
View
20 spec/integration/model/app_spec.rb
@@ -3,6 +3,26 @@
describe TentD::Model::App do
let(:app) { Fabricate(:app) }
+ describe '#destroy' do
+ let!(:app_authorization) { Fabricate(:app_authorization, :app => app) }
+ let(:notification_subscription) { Fabricate(:notification_subscription, :app_authorization => app_authorization) }
+
+ it 'should destroy app authorizations' do
+ expect(lambda {
+ expect(lambda {
+ app.destroy
+ }).to change(described_class, :count).by(-1)
+ }).to change(TentD::Model::AppAuthorization, :count).by(-1)
+ end
+
+ it 'should destroy notification subscriptions' do
+ notification_subscription # create
+ expect(lambda {
+ app.destroy
+ }).to change(TentD::Model::NotificationSubscription, :count).by(-1)
+ end
+ end
+
describe '#as_json' do
let(:public_attributes) do
{

0 comments on commit 27925c0

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