DG MS; upon friend deletion, all connected posts and comments are purged

This commit is contained in:
maxwell 2010-07-09 16:08:00 -07:00
parent cf352b6f8d
commit f5fd0b011a
3 changed files with 50 additions and 18 deletions

View file

@ -17,32 +17,29 @@ class Person
timestamps!
validates_presence_of :url
before_validation :clean_url
validates_presence_of :email, :url
validates_format_of :url, :with =>
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
#validates_uniqueness_of :url
validates_true_for :url, :logic => lambda { self.url_unique?}
scope :friends, where(:_type => "Person", :active => true)
validates_presence_of :email
before_validation :clean_url
after_destroy :remove_all_traces
scope :friends, where(:_type => "Person", :active => true)
def real_name
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
end
def key
GPGME::Ctx.new.get_key key_fingerprint
end
protected
def url_unique?
same_url = Person.first(:url => self.url)
return same_url.nil? || same_url.id == self.id
@ -55,4 +52,14 @@ class Person
self.url = self.url + '/' if self.url[-1,1] != '/'
end
end
private
def remove_all_traces
self.posts.delete_all
Comment.delete_all(:person_id => self.id)
end
end

View file

@ -36,11 +36,6 @@ class User < Person
end
end
def do_bad_things
self.password_confirmation = self.password
end
def accept_friend_request(friend_request_id)
request = Request.where(:id => friend_request_id).first
request.activate_friend
@ -53,7 +48,6 @@ class User < Person
def ignore_friend_request(friend_request_id)
request = Request.where(:id => friend_request_id).first
person = request.person
person.destroy unless person.active
request.destroy
end
@ -67,10 +61,17 @@ class User < Person
end
end
###Helpers############
def mine?(post)
self == post.person
end
def do_bad_things
self.password_confirmation = self.password
end
protected
def assign_key

View file

@ -34,4 +34,28 @@ describe Person do
end
it 'should delete all of user upon user deletion' do
Factory.create(:user)
f = Factory.create(:person)
p = Factory.create(:person)
Factory.create(:status_message, :person => f)
Factory.create(:blog, :person => f)
Factory.create(:bookmark, :person => f)
Factory.create(:status_message, :person => f)
s = Factory.create(:status_message, :person => p)
Factory.create(:comment, :person_id => f.id, :text => "yes i do", :post => s)
Factory.create(:comment, :person_id => f.id, :text => "i love you", :post => s)
Factory.create(:comment, :person_id => f.id, :text => "hello", :post => s)
Factory.create(:comment, :person_id => p.id, :text => "you are creepy", :post => s)
f.destroy
Post.count.should == 1
Comment.all.count.should == 1
s.comments.count.should == 1
end
end