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!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
def index
|
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
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,13 @@ class Person
|
||||||
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
|
after_destroy :remove_all_traces
|
||||||
before_validation :clean_url
|
before_validation :clean_url
|
||||||
validates_presence_of :email, :url, :profile, :serialized_key
|
validates_presence_of :email, :url, :profile, :serialized_key
|
||||||
validates_format_of :url, :with =>
|
validates_format_of :url, :with =>
|
||||||
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
|
/^(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)
|
def self.search(query)
|
||||||
Person.all('$where' => "function() { return this.email.match(/^#{query}/i) ||
|
Person.all('$where' => "function() { return this.email.match(/^#{query}/i) ||
|
||||||
this.profile.first_name.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] != '/'
|
self.url = self.url + '/' if self.url[-1,1] != '/'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
private
|
||||||
|
def remove_all_traces
|
||||||
|
Post.all(:person_id => id).each{|p| p.delete}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ describe Person do
|
||||||
person_message = Factory.create(:status_message, :person => @person)
|
person_message = Factory.create(:status_message, :person => @person)
|
||||||
person_two = Factory.create(: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
|
person_two.owns?(person_message).should be false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ describe Person do
|
||||||
request = @user.send_friend_request_to @person.receive_url, @group.id
|
request = @user.send_friend_request_to @person.receive_url, @group.id
|
||||||
request2 = @user2.send_friend_request_to @person.receive_url, @group2.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)
|
@user2.activate_friend(@person, @group2)
|
||||||
|
|
||||||
@user.reload
|
@user.reload
|
||||||
|
|
|
||||||
|
|
@ -27,27 +27,6 @@ describe Post do
|
||||||
|
|
||||||
end
|
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
|
describe 'xml' do
|
||||||
it 'should serialize to xml with its person' do
|
it 'should serialize to xml with its person' do
|
||||||
message = Factory.create(:status_message, :person => @user.person)
|
message = Factory.create(:status_message, :person => @user.person)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ describe User do
|
||||||
StatusMessage.all.size.should == 0
|
StatusMessage.all.size.should == 0
|
||||||
@user.receive( xml )
|
@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
|
StatusMessage.all.size.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue