From e648042b15af12bc3eebec0831be32e36252c4b8 Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 18 Oct 2010 10:26:45 -0700 Subject: [PATCH] the user destroy now deletes the aspects --- app/models/user.rb | 8 ++++++-- spec/models/user_spec.rb | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7d29fd7df..fe03e20fc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,11 +52,11 @@ class User many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go many :pending_requests, :in => :pending_request_ids, :class_name => 'Request' many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' - many :aspects, :class_name => 'Aspect' + many :aspects, :class_name => 'Aspect', :dependent => :destroy after_create :seed_aspects - before_destroy :unfriend_everyone, :remove_person + before_destroy :unfriend_everyone, :remove_person, :remove_all_aspects def strip_username if username.present? @@ -400,4 +400,8 @@ class User end } end + + def remove_all_aspects + aspects.destroy_all + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5296fbeaf..61e37b3aa 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -130,11 +130,11 @@ describe User do it 'should remove all aspects' do - pending "this should use :dependant => :destroy on the many assoc...but that screws this test suite..." aspects = user.aspects + aspects.count.should > 0 user.destroy - proc { aspects.reload }.should raise_error /does not exist/ - + aspects.reload + aspects.count.should == 0 end