Removing posts relation from person
This commit is contained in:
parent
98a0a3032a
commit
539316a235
5 changed files with 10 additions and 29 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -25,15 +25,13 @@ 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) ||
|
||||
this.profile.first_name.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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue