Fix stack level too deep error on reshares

This commit is contained in:
Raphael Sofaer 2011-08-12 13:11:23 -07:00
parent 31b55aef0b
commit 8b743e7e3b
4 changed files with 20 additions and 7 deletions

View file

@ -86,7 +86,7 @@ class Post < ActiveRecord::Base
local_post = Post.where(:guid => self.guid).first
if local_post && local_post.author_id == self.author_id
known_post = user.visible_posts.where(:guid => self.guid).first
known_post = user.find_visible_post_by_id(self.guid, :key => :guid)
if known_post
if known_post.mutable?
known_post.update_attributes(self.attributes)

View file

@ -20,13 +20,10 @@ class Reshare < Post
def receive(recipient, sender)
local_reshare = Reshare.where(:guid => self.guid).first
if local_reshare && local_reshare.root.author_id == recipient.person.id
if recipient.contact_for(sender)
local_reshare.receive(recipient, sender)
return unless recipient.has_contact_for?(sender)
end
else
super(recipient, sender)
end
end
def comment_email_subject
I18n.t('reshares.comment_email_subject', :resharer => author.name, :author => root.author.name)

View file

@ -66,6 +66,12 @@ module Diaspora
Contact.where(:user_id => self.id, :person_id => person_id).includes(:person => :profile).first
end
# @param [Person] person
# @return [Boolean] whether person is a contact of this user
def has_contact_for?(person)
Contact.exists?(:user_id => self.id, :person_id => person.id)
end
def people_in_aspects(requested_aspects, opts={})
allowed_aspects = self.aspects & requested_aspects
person_ids = contacts_in_aspects(allowed_aspects).collect{|contact| contact.person_id}

View file

@ -26,19 +26,29 @@ describe Reshare do
end
describe "#receive" do
let(:receive) {@reshare.receive(@root.author.owner, @reshare.author)}
before do
@reshare = Factory.create(:reshare, :root => Factory(:status_message, :author => bob.person, :public => true))
@root = @reshare.root
@reshare.receive(@root.author.owner, @reshare.author)
end
it 'increments the reshare count' do
receive
@root.resharers.count.should == 1
end
it 'adds the resharer to the re-sharers of the post' do
receive
@root.resharers.should include(@reshare.author)
end
it 'does not error if the root author has a contact for the resharer' do
bob.share_with @reshare.author, bob.aspects.first
proc {
Timeout.timeout(5) do
receive #This doesn't ever terminate on my machine before it was fixed.
end
}.should_not raise_error
end
end
describe "XML" do