From ba779e18d65743e40d609c15219fbfa61b9605b8 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Thu, 17 Feb 2011 13:03:14 -0800 Subject: [PATCH] aspect memberships are now dependant delete_all on contact --- app/models/contact.rb | 2 +- spec/intergration/contact_deleting_spec.rb | 16 ++++++++++++++++ spec/models/contact_spec.rb | 12 ++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/intergration/contact_deleting_spec.rb diff --git a/app/models/contact.rb b/app/models/contact.rb index 53a21b442..a8014f1b8 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -9,7 +9,7 @@ class Contact < ActiveRecord::Base belongs_to :person validates_presence_of :person - has_many :aspect_memberships + has_many :aspect_memberships, :dependent => :delete_all has_many :aspects, :through => :aspect_memberships validate :not_contact_for_self validates_uniqueness_of :person_id, :scope => :user_id diff --git a/spec/intergration/contact_deleting_spec.rb b/spec/intergration/contact_deleting_spec.rb new file mode 100644 index 000000000..1707bd589 --- /dev/null +++ b/spec/intergration/contact_deleting_spec.rb @@ -0,0 +1,16 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe 'disconnecting a contact' do + it 'removes the aspect membership' do + @user = alice + @user2 = bob + + lambda{ + @user.disconnect(@user.contact_for(@user2.person)) + }.should change(AspectMembership, :count).by(-1) + end +end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 1fa36dbe4..8f0699c23 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -5,6 +5,18 @@ require 'spec_helper' describe Contact do + describe 'aspect_memberships' do + before do + @user = alice + @user2 = bob + end + it 'set to dependant delete_all' do + lambda{ + @user.contact_for(@user2.person).destroy + }.should change(AspectMembership, :count).by(-1) + end + end + describe 'validations' do let(:contact){Contact.new}