Fix stack level too deep error on reshares
This commit is contained in:
parent
31b55aef0b
commit
8b743e7e3b
4 changed files with 20 additions and 7 deletions
|
|
@ -86,7 +86,7 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
local_post = Post.where(:guid => self.guid).first
|
local_post = Post.where(:guid => self.guid).first
|
||||||
if local_post && local_post.author_id == self.author_id
|
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
|
||||||
if known_post.mutable?
|
if known_post.mutable?
|
||||||
known_post.update_attributes(self.attributes)
|
known_post.update_attributes(self.attributes)
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,9 @@ class Reshare < Post
|
||||||
def receive(recipient, sender)
|
def receive(recipient, sender)
|
||||||
local_reshare = Reshare.where(:guid => self.guid).first
|
local_reshare = Reshare.where(:guid => self.guid).first
|
||||||
if local_reshare && local_reshare.root.author_id == recipient.person.id
|
if local_reshare && local_reshare.root.author_id == recipient.person.id
|
||||||
if recipient.contact_for(sender)
|
return unless recipient.has_contact_for?(sender)
|
||||||
local_reshare.receive(recipient, sender)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
super(recipient, sender)
|
|
||||||
end
|
end
|
||||||
|
super(recipient, sender)
|
||||||
end
|
end
|
||||||
|
|
||||||
def comment_email_subject
|
def comment_email_subject
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,12 @@ module Diaspora
|
||||||
Contact.where(:user_id => self.id, :person_id => person_id).includes(:person => :profile).first
|
Contact.where(:user_id => self.id, :person_id => person_id).includes(:person => :profile).first
|
||||||
end
|
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={})
|
def people_in_aspects(requested_aspects, opts={})
|
||||||
allowed_aspects = self.aspects & requested_aspects
|
allowed_aspects = self.aspects & requested_aspects
|
||||||
person_ids = contacts_in_aspects(allowed_aspects).collect{|contact| contact.person_id}
|
person_ids = contacts_in_aspects(allowed_aspects).collect{|contact| contact.person_id}
|
||||||
|
|
|
||||||
|
|
@ -26,19 +26,29 @@ describe Reshare do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#receive" do
|
describe "#receive" do
|
||||||
|
let(:receive) {@reshare.receive(@root.author.owner, @reshare.author)}
|
||||||
before do
|
before do
|
||||||
@reshare = Factory.create(:reshare, :root => Factory(:status_message, :author => bob.person, :public => true))
|
@reshare = Factory.create(:reshare, :root => Factory(:status_message, :author => bob.person, :public => true))
|
||||||
@root = @reshare.root
|
@root = @reshare.root
|
||||||
@reshare.receive(@root.author.owner, @reshare.author)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'increments the reshare count' do
|
it 'increments the reshare count' do
|
||||||
|
receive
|
||||||
@root.resharers.count.should == 1
|
@root.resharers.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds the resharer to the re-sharers of the post' do
|
it 'adds the resharer to the re-sharers of the post' do
|
||||||
|
receive
|
||||||
@root.resharers.should include(@reshare.author)
|
@root.resharers.should include(@reshare.author)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "XML" do
|
describe "XML" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue