diff --git a/app/models/person.rb b/app/models/person.rb index 84edbed3d..8003e8520 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -6,6 +6,7 @@ class Person xml_accessor :email xml_accessor :url xml_accessor :profile, :as => Profile + xml_reader :serialized_key key :email, String, :unique => true @@ -51,6 +52,12 @@ class Person serialized_key = new_key.export end + def serialized_key= new_key + raise "Don't change a key" if serialized_key + + @serialized_key = new_key + end + def public_key_hash Base64.encode64 OpenSSL::Digest::SHA256.new(self.export_key).to_s end @@ -59,7 +66,6 @@ class Person encryption_key.public_key.export end - def owns?(post) self.id == post.person.id end diff --git a/lib/diaspora/parser.rb b/lib/diaspora/parser.rb index 40c439f86..51523724d 100644 --- a/lib/diaspora/parser.rb +++ b/lib/diaspora/parser.rb @@ -9,7 +9,6 @@ module Diaspora def self.parse_or_find_person_from_xml(xml) doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } person_xml = doc.xpath("//person").to_s - Rails.logger.debug("We're in the parser: #{person_xml}") person_id = doc.xpath("//person/_id").text.to_s person = Person.first(:_id => person_id) person ? person : Person.from_xml( person_xml) diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index d57ccc8ce..5197080dc 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -18,7 +18,7 @@ describe Diaspora::Parser do @xml = Factory.build(:status_message).to_diaspora_xml end - it 'should be able to correctly handle comments' do + it 'should be able to correctly handle comments with person in db' do person = Factory.create(:person, :email => "test@testing.com") post = Factory.create(:status_message, :person => @user.person) comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!") @@ -29,6 +29,23 @@ describe Diaspora::Parser do comment.person.should == person comment.post.should == post end + + it 'should be able to correctly handle person on a comment with person not in db' do + commenter = Factory.create(:user) + commenter_group = commenter.group :name => "bruisers" + friend_users(@user, @group, commenter, commenter_group) + post = @user.post :status_message, :message => "hello", :to => @group.id + comment = commenter.comment "Fool!", :on => post + + xml = comment.to_diaspora_xml + commenter.delete + commenter.person.delete + + parsed_person = Diaspora::Parser::parse_or_find_person_from_xml(xml) + parsed_person.save.should be true + parsed_person.email.should == commenter.person.email + parsed_person.profile.should_not be_nil + end it 'should marshal retractions' do person = Factory.create(:person) diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index a9066f6d0..95d2c977c 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -4,7 +4,10 @@ describe Comment do describe "user" do before do @user = Factory.create :user - @user.person.save + @group = @user.group(:name => "Doofuses") + + @user2 = Factory.create(:user) + @group2 = @user2.group(:name => "Lame-faces") end it "should be able to comment on his own status" do status = Factory.create(:status_message, :person => @user.person) @@ -31,10 +34,7 @@ describe Comment do describe 'comment propagation' do before do - @group = @user.group(:name => "Doofuses") - @user2 = Factory.create(:user) - @group2 = @user2.group(:name => "Lame-faces") request = @user.send_friend_request_to(@user2.receive_url, @group.id) reversed_request = @user2.accept_friend_request( request.id, @group2.id ) @@ -79,5 +79,16 @@ describe Comment do @user.receive(comment.to_diaspora_xml) end end + describe 'serialization' do + it 'should serialize the commenter' do + commenter = Factory.create(:user) + commenter_group = commenter.group :name => "bruisers" + friend_users(@user, @group, commenter, commenter_group) + post = @user.post :status_message, :message => "hello", :to => @group.id + comment = commenter.comment "Fool!", :on => post + comment.person.should_not == @user.person + comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true + end + end end end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 9480dd60c..46943512f 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -136,34 +136,30 @@ describe User do describe 'comments' do it 'should correctly marshal to the downstream user' do + + friend_users(@user, @group, @user3, @group3) + post = @user.post :status_message, :message => "hello", :to => @group.id - - @user3 = Factory.create(:user) - @group3 = @user3.group(:name => 'heroes') + @user2.receive post.to_diaspora_xml + @user3.receive post.to_diaspora_xml - puts @user.inspect - puts @group.inspect - friend_users(@user, @group, @user3, @group3) + comment = @user2.comment('tada',:on => post) + @user.receive comment.to_diaspora_xml + @user.reload + @user2.person.delete + @user2.delete + comment_id = comment.id - status_message = @user.post :status_message, :message => 'store this!', :to => @group.id - - @user2.receive status_message.to_diaspora_xml - @user3.receive status_message.to_diaspora_xml - - comment = @user2.comment('tada',:on => status_message) - @user.receive comment.to_diaspora_xml - @user.reload - - @user.raw_visible_posts.first.comments.first.nil?.should be false - upstream_comment = @user.raw_visible_posts.first.comments.first - - @user2.person.delete - @user3.receive upstream_comment.to_diaspora_xml - @user3.reload - - @user3.raw_visible_posts.first.comments.first.nil?.should be false + comment.delete + @user3.receive comment.to_diaspora_xml + @user3.reload + new_comment = Comment.find_by_id(comment_id) + new_comment.should_not be_nil + new_comment.person.should_not be_nil + new_comment.person.profile.should_not be_nil + end end end