33 failures left in mysql
This commit is contained in:
parent
55492535c6
commit
d01fbeac04
5 changed files with 52 additions and 35 deletions
|
|
@ -57,7 +57,7 @@ module SocketsHelper
|
||||||
if object.is_a? Comment
|
if object.is_a? Comment
|
||||||
post = object.post
|
post = object.post
|
||||||
action_hash[:comment_id] = object.id
|
action_hash[:comment_id] = object.id
|
||||||
action_hash[:my_post?] = (post.person.owner.id == uid)
|
action_hash[:my_post?] = (post.person.owner_id == uid)
|
||||||
action_hash[:notification] = notification(object)
|
action_hash[:notification] = notification(object)
|
||||||
action_hash[:post_guid] = post.id
|
action_hash[:post_guid] = post.id
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@ class Comment < ActiveRecord::Base
|
||||||
include Diaspora::Guid
|
include Diaspora::Guid
|
||||||
|
|
||||||
xml_attr :text
|
xml_attr :text
|
||||||
xml_accessor :diaspora_handle
|
xml_attr :diaspora_handle
|
||||||
xml_accessor :post_guid
|
xml_attr :post_guid
|
||||||
|
xml_attr :creator_signature
|
||||||
|
xml_attr :post_creator_signature
|
||||||
|
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
belongs_to :person
|
belongs_to :person
|
||||||
|
|
@ -31,7 +33,7 @@ class Comment < ActiveRecord::Base
|
||||||
self.person = Person.where(:diaspora_handle => nh).first
|
self.person = Person.where(:diaspora_handle => nh).first
|
||||||
end
|
end
|
||||||
def post_guid
|
def post_guid
|
||||||
post.guid
|
self.post.guid
|
||||||
end
|
end
|
||||||
def post_guid= new_post_guid
|
def post_guid= new_post_guid
|
||||||
self.post = Post.where(:guid => new_post_guid).first
|
self.post = Post.where(:guid => new_post_guid).first
|
||||||
|
|
@ -47,8 +49,6 @@ class Comment < ActiveRecord::Base
|
||||||
|
|
||||||
#ENCRYPTION
|
#ENCRYPTION
|
||||||
|
|
||||||
xml_reader :creator_signature
|
|
||||||
xml_reader :post_creator_signature
|
|
||||||
|
|
||||||
def signable_accessors
|
def signable_accessors
|
||||||
accessors = self.class.roxml_attrs.collect{|definition|
|
accessors = self.class.roxml_attrs.collect{|definition|
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ module Encryptable
|
||||||
|
|
||||||
def verify_signature(signature, person)
|
def verify_signature(signature, person)
|
||||||
if person.nil?
|
if person.nil?
|
||||||
Rails.logger.info("event=verify_signature status=abort reason=no_person model_id=#{id}")
|
Rails.logger.info("event=verify_signature status=abort reason=no_person guid=#{self.guid} model_id=#{self.id}")
|
||||||
return false
|
return false
|
||||||
elsif person.public_key.nil?
|
elsif person.public_key.nil?
|
||||||
Rails.logger.info("event=verify_signature status=abort reason=no_key model_id=#{id}")
|
Rails.logger.info("event=verify_signature status=abort reason=no_key guid=#{self.guid} model_id=#{self.id}")
|
||||||
return false
|
return false
|
||||||
elsif signature.nil?
|
elsif signature.nil?
|
||||||
Rails.logger.info("event=verify_signature status=abort reason=no_signature model_id=#{id}")
|
Rails.logger.info("event=verify_signature status=abort reason=no_signature guid=#{self.guid} model_id=#{self.id}")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
log_string = "event=verify_signature status=complete model_id=#{id}"
|
log_string = "event=verify_signature status=complete model_id=#{id}"
|
||||||
|
|
|
||||||
|
|
@ -67,5 +67,7 @@ Factory.define :service do |service|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Factory.define(:comment) {}
|
Factory.define(:comment) do |comment|
|
||||||
|
comment.sequence(:text) {|n| "#{n} cats"}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,10 @@ describe Comment do
|
||||||
user.activate_contact(@person, aspect)
|
user.activate_contact(@person, aspect)
|
||||||
|
|
||||||
@person2 = Factory.create(:person)
|
@person2 = Factory.create(:person)
|
||||||
@person_status = Factory.build(:status_message, :person => @person)
|
@person3 = Factory.create(:person)
|
||||||
|
user.activate_contact(@person3, aspect)
|
||||||
|
|
||||||
|
@person_status = Factory.create(:status_message, :person => @person)
|
||||||
|
|
||||||
user.reload
|
user.reload
|
||||||
@user_status = user.post :status_message, :message => "hi", :to => aspect.id
|
@user_status = user.post :status_message, :message => "hi", :to => aspect.id
|
||||||
|
|
@ -118,24 +121,18 @@ describe Comment do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send a user comment on his own post to lots of people' do
|
it 'should send a user comment on his own post to lots of people' do
|
||||||
MessageHandler.should_receive(:add_post_request).once
|
MessageHandler.should_receive(:add_post_request).twice
|
||||||
|
|
||||||
user2.raw_visible_posts.count.should == 0
|
|
||||||
|
|
||||||
user.comment "yo", :on => @user_status
|
user.comment "yo", :on => @user_status
|
||||||
|
|
||||||
user2.reload
|
|
||||||
user2.raw_visible_posts.count.should == 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send a comment a person made on your post to all people' do
|
it 'should send a comment a person made on your post to all people' do
|
||||||
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status)
|
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status)
|
||||||
MessageHandler.should_receive(:add_post_request).once
|
MessageHandler.should_receive(:add_post_request).twice
|
||||||
user.receive comment.to_diaspora_xml, @person
|
user.receive comment.to_diaspora_xml, @person
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send a comment a user made on your post to all people' do
|
it 'should send a comment a user made on your post to all people' do
|
||||||
MessageHandler.should_receive(:add_post_request).once
|
MessageHandler.should_receive(:add_post_request).twice
|
||||||
comment = user2.comment( "balls", :on => @user_status)
|
comment = user2.comment( "balls", :on => @user_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -146,13 +143,13 @@ describe Comment do
|
||||||
|
|
||||||
it 'should not send a comment a person made on his own post to anyone' do
|
it 'should not send a comment a person made on his own post to anyone' do
|
||||||
MessageHandler.should_not_receive(:add_post_request)
|
MessageHandler.should_not_receive(:add_post_request)
|
||||||
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
|
comment = Factory.build(:comment, :person => @person, :post => @person_status)
|
||||||
user.receive comment.to_diaspora_xml, @person
|
user.receive comment.to_diaspora_xml, @person
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not send a comment a person made on a person post to anyone' do
|
it 'should not send a comment a person made on a person post to anyone' do
|
||||||
MessageHandler.should_not_receive(:add_post_request)
|
MessageHandler.should_not_receive(:add_post_request)
|
||||||
comment = Comment.new(:person_id => @person2.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
|
comment = Comment.new(:person_id => @person2.id, :text => "cats", :post => @person_status)
|
||||||
user.receive comment.to_diaspora_xml, @person
|
user.receive comment.to_diaspora_xml, @person
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -163,7 +160,7 @@ describe Comment do
|
||||||
|
|
||||||
it 'should not clear the aspect post array on receiving a comment' do
|
it 'should not clear the aspect post array on receiving a comment' do
|
||||||
aspect.post_ids.include?(@user_status.id).should be_true
|
aspect.post_ids.include?(@user_status.id).should be_true
|
||||||
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status)
|
comment = Comment.new(:person_id => @person.id, :text => "cats", :post => @user_status)
|
||||||
|
|
||||||
user.receive comment.to_diaspora_xml, @person
|
user.receive comment.to_diaspora_xml, @person
|
||||||
|
|
||||||
|
|
@ -171,17 +168,31 @@ describe Comment do
|
||||||
aspect.post_ids.include?(@user_status.id).should be_true
|
aspect.post_ids.include?(@user_status.id).should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe 'serialization' do
|
describe 'xml' do
|
||||||
it 'should serialize the handle and not the sender' do
|
before do
|
||||||
commenter = Factory.create(:user)
|
@commenter = Factory.create(:user)
|
||||||
commenter_aspect = commenter.aspects.create(:name => "bruisers")
|
@commenter_aspect = @commenter.aspects.create(:name => "bruisers")
|
||||||
connect_users(user, aspect, commenter, commenter_aspect)
|
connect_users(user, aspect, @commenter, @commenter_aspect)
|
||||||
post = user.post :status_message, :message => "hello", :to => aspect.id
|
@post = user.post :status_message, :message => "hello", :to => aspect.id
|
||||||
comment = commenter.comment "Fool!", :on => post
|
@comment = @commenter.comment "Fool!", :on => @post
|
||||||
comment.person.should_not == user.person
|
@xml = @comment.to_xml.to_s
|
||||||
xml = comment.to_diaspora_xml
|
end
|
||||||
xml.include?(commenter.person.id.to_s).should be_false
|
it 'serializes the sender handle' do
|
||||||
xml.include?(commenter.diaspora_handle).should be_true
|
@xml.include?(@commenter.diaspora_handle).should be_true
|
||||||
|
end
|
||||||
|
it 'serializes the post_guid' do
|
||||||
|
@xml.should include(@post.guid)
|
||||||
|
end
|
||||||
|
describe 'marshalling' do
|
||||||
|
before do
|
||||||
|
@marshalled_comment = Comment.from_xml(@xml)
|
||||||
|
end
|
||||||
|
it 'marshals the author' do
|
||||||
|
@marshalled_comment.person.should == @commenter.person
|
||||||
|
end
|
||||||
|
it 'marshals the post' do
|
||||||
|
@marshalled_comment.post.should == @post
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe 'local commenting' do
|
describe 'local commenting' do
|
||||||
|
|
@ -201,13 +212,17 @@ describe Comment do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should attach the creator signature if the user is commenting' do
|
it 'should attach the creator signature if the user is commenting' do
|
||||||
user.comment "Yeah, it was great", :on => @remote_message
|
comment = user.comment "Yeah, it was great", :on => @remote_message
|
||||||
|
pp comment.signable_string
|
||||||
|
@remote_message.comments.reset
|
||||||
|
pp @remote_message.comments.first
|
||||||
@remote_message.comments.first.signature_valid?.should be_true
|
@remote_message.comments.first.signature_valid?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should sign the comment if the user is the post creator' do
|
it 'should sign the comment if the user is the post creator' do
|
||||||
message = user.post :status_message, :message => "hi", :to => aspect.id
|
message = user.post :status_message, :message => "hi", :to => aspect.id
|
||||||
user.comment "Yeah, it was great", :on => message
|
user.comment "Yeah, it was great", :on => message
|
||||||
|
message.comments.reset
|
||||||
message.comments.first.signature_valid?.should be_true
|
message.comments.first.signature_valid?.should be_true
|
||||||
message.comments.first.verify_post_creator_signature.should be_true
|
message.comments.first.verify_post_creator_signature.should be_true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue