Attempting to make comments from unknown users save
This commit is contained in:
parent
84e2800c7d
commit
2dd2f38442
5 changed files with 59 additions and 30 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue