receiving spec is green

This commit is contained in:
ilya 2010-10-11 19:20:00 -07:00
parent 03df0ff716
commit ee2d134cb0
4 changed files with 28 additions and 26 deletions

View file

@ -9,14 +9,15 @@ module Diaspora
end
end
def receive xml, author
def receive xml, salmon_author
object = Diaspora::Parser.from_xml(xml)
Rails.logger.debug("Receiving object for #{self.real_name}:\n#{object.inspect}")
Rails.logger.debug("From: #{object.person.inspect}") if object.person
if (author == sender(object, xml))
sender_in_xml = sender(object, xml)
if (salmon_author == sender_in_xml)
if object.is_a? Retraction
receive_retraction object, xml
elsif object.is_a? Request
@ -29,7 +30,7 @@ module Diaspora
receive_post object, xml
end
else
raise "Possibly Malicious Post, #{author.real_name} with id #{author.id} is sending a #{object.class} as #{sender.real_name} with id #{sender.id} "
raise "Possibly Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
end
end
@ -41,7 +42,7 @@ module Diaspora
elsif object.is_a? Profile
sender = Diaspora::Parser.owner_id_from_xml xml
elsif object.is_a?(Comment)
sender = object.post.person
sender = (owns?(object.post))? object.person : object.post.person
else
sender = object.person
end

View file

@ -86,7 +86,7 @@ describe Aspect do
message = @user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
@user.receive message.to_diaspora_xml
@user.receive message.to_diaspora_xml, @user2.person
aspect.reload
aspect.posts.include?(message).should be true
@ -100,13 +100,14 @@ describe Aspect do
message = @user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
@user.receive message.to_diaspora_xml
@user.receive message.to_diaspora_xml, @user2.person
aspect.reload
aspect.post_ids.include?(message.id).should be true
retraction = @user2.retract(message)
@user.receive retraction.to_diaspora_xml
@user.receive retraction.to_diaspora_xml, @user2.person
aspect.reload
aspect.post_ids.include?(message.id).should be false
@ -151,7 +152,7 @@ describe Aspect do
it 'should move all the by that user to the new aspect' do
message = @user2.post(:status_message, :message => "Hey Dude", :to => @aspect2.id)
@user.receive message.to_diaspora_xml
@user.receive message.to_diaspora_xml, @user2.person
@aspect.reload
@aspect.posts.count.should == 1

View file

@ -73,33 +73,33 @@ describe Comment do
it 'should send a comment a person made on your post to all people' do
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status)
User::QUEUE.should_receive(:add_post_request).twice
@user.receive(comment.to_diaspora_xml)
@user.receive comment.to_diaspora_xml, @person
end
it 'should send a comment a user made on your post to all people' do
comment = @user2.comment( "balls", :on => @user_status)
User::QUEUE.should_receive(:add_post_request).twice
@user.receive(comment.to_diaspora_xml)
@user.receive comment.to_diaspora_xml, @user2.person
end
it 'should not send a comment a person made on his own post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status)
@user.receive(comment.to_diaspora_xml)
@user.receive comment.to_diaspora_xml, @person
end
it 'should not send a comment a person made on a person post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status)
@user.receive(comment.to_diaspora_xml)
@user.receive comment.to_diaspora_xml, @person
end
it 'should not clear the aspect post array on receiving a comment' do
@aspect.post_ids.include?(@user_status.id).should be true
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status)
@user.receive(comment.to_diaspora_xml)
@user.receive comment.to_diaspora_xml, @person
@aspect.reload
@aspect.post_ids.include?(@user_status.id).should be true

View file

@ -28,7 +28,7 @@ describe User do
user2.destroy
status_message.destroy
StatusMessage.all.size.should == 0
user.receive( xml )
user.receive xml , user2.person
Post.all(:person_id => person.id).first.message.should == 'store this!'
StatusMessage.all.size.should == 1
@ -40,7 +40,7 @@ describe User do
(0..5).each{ |n|
status_message = user2.post :status_message, :message => "store this #{n}!", :to => aspect2.id
xml = status_message.to_diaspora_xml
user.receive( xml )
user.receive xml, user2.person
}
user.aspects.size.should == num_aspects
@ -60,7 +60,7 @@ describe User do
it 'should be removed on unfriending' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml
user.receive status_message.to_diaspora_xml, user2.person
user.reload
user.raw_visible_posts.count.should == 1
@ -75,13 +75,13 @@ describe User do
it 'should be remove a post if the noone links to it' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml
user.receive status_message.to_diaspora_xml, user2.person
user.reload
user.raw_visible_posts.count.should == 1
person = user2.person
user2.destroy
user2.delete
user.unfriend(person)
user.reload
@ -92,7 +92,7 @@ describe User do
it 'should keep track of user references for one person ' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml
user.receive status_message.to_diaspora_xml, user2.person
user.reload
user.raw_visible_posts.count.should == 1
@ -116,9 +116,9 @@ describe User do
user3.activate_friend(user2.person, aspect3)
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml
user.receive status_message.to_diaspora_xml, user2.person
user3.receive status_message.to_diaspora_xml
user3.receive status_message.to_diaspora_xml, user2.person
user.reload
user3.reload
@ -145,11 +145,11 @@ describe User do
post = user.post :status_message, :message => "hello", :to => aspect.id
user2.receive post.to_diaspora_xml
user3.receive post.to_diaspora_xml
user2.receive post.to_diaspora_xml, user.person
user3.receive post.to_diaspora_xml, user.person
comment = user2.comment('tada',:on => post)
user.receive comment.to_diaspora_xml
user.receive comment.to_diaspora_xml, user2.person
user.reload
commenter_id = user2.person.id
@ -159,7 +159,7 @@ describe User do
comment_id = comment.id
comment.delete
user3.receive comment.to_diaspora_xml
user3.receive comment.to_diaspora_xml, user.person
user3.reload
new_comment = Comment.find_by_id(comment_id)