From 539316a235cc2aaf72a0546e6ed3bffe60fae689 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 23:50:07 -0700 Subject: [PATCH] Removing posts relation from person --- app/controllers/groups_controller.rb | 2 +- app/models/person.rb | 8 +++++--- spec/models/person_spec.rb | 6 +++--- spec/models/post_spec.rb | 21 --------------------- spec/models/user/receive_spec.rb | 2 +- 5 files changed, 10 insertions(+), 29 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 11ded0064..88b8235f2 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -2,7 +2,7 @@ class GroupsController < ApplicationController before_filter :authenticate_user! def index - @posts = current_user.posts.paginate :page => params[:page], :order => 'created_at DESC' + @posts = current_user.raw_visible_posts.paginate :page => params[:page], :order => 'created_at DESC' end def create diff --git a/app/models/person.rb b/app/models/person.rb index 9b8740e1b..f966a4070 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -25,14 +25,12 @@ class Person timestamps! + after_destroy :remove_all_traces before_validation :clean_url validates_presence_of :email, :url, :profile, :serialized_key validates_format_of :url, :with => /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix - - after_destroy :remove_all_traces - def self.search(query) Person.all('$where' => "function() { return this.email.match(/^#{query}/i) || @@ -91,4 +89,8 @@ class Person self.url = self.url + '/' if self.url[-1,1] != '/' end end + private + def remove_all_traces + Post.all(:person_id => id).each{|p| p.delete} + end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index a571e0582..ad4d00e2b 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -32,7 +32,7 @@ describe Person do person_message = Factory.create(:status_message, :person => @person) person_two = Factory.create(:person) - @person.owns? (person_message).should be true + @person.owns?(person_message).should be true person_two.owns?(person_message).should be false end @@ -53,7 +53,7 @@ describe Person do person.destroy - Post.count.should == 1 + Post.count.should == 1 Comment.all.count.should == 4 status_message.comments.count.should == 4 end @@ -77,7 +77,7 @@ describe Person do request = @user.send_friend_request_to @person.receive_url, @group.id request2 = @user2.send_friend_request_to @person.receive_url, @group2.id - @user.activate_friend (@person, @group) + @user.activate_friend(@person, @group) @user2.activate_friend(@person, @group2) @user.reload diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 9ec8ccb19..c6196b0f0 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -27,27 +27,6 @@ describe Post do end - describe "stream" do - before do - @owner = Factory.build(:user) - @person_one = Factory.create(:person, :email => "some@dudes.com") - @person_two = Factory.create(:person, :email => "other@dudes.com") - - Factory.create(:status_message, :message => "puppies", :created_at => Time.now+1, :person => @owner.person) - Factory.create(:status_message, :message => "http://reddit.com", :created_at => Time.now+2, :person => @person_one) - Factory.create(:status_message, :message => "kittens", :created_at => Time.now+3, :person => @person_two) - Factory.create(:status_message, :message => "Bear's body", :created_at => Time.now+4, :person => @owner.person) - Factory.create(:status_message, :message => "Google", :created_at => Time.now+5, :person => @person_two) - end - - it "should get all posts for a specified user" do - person_posts = @person_one.posts - person_posts.count.should == 1 - - person_posts = @person_two.posts - person_posts.count.should == 2 - end - end describe 'xml' do it 'should serialize to xml with its person' do message = Factory.create(:status_message, :person => @user.person) diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 7e850c490..4919e66f4 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -22,7 +22,7 @@ describe User do StatusMessage.all.size.should == 0 @user.receive( xml ) - person.posts.first.message.should == 'store this!' + Post.all(:person_id => person.id).first.message.should == 'store this!' StatusMessage.all.size.should == 1 end