From ed51f34ebba202838fd0eb4534f7043176fa4590 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Thu, 7 Jun 2012 09:51:25 -0600 Subject: [PATCH 1/3] strip comment text upon comment creation --- app/models/comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 747602ba7..0f3fec09a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -81,7 +81,7 @@ class Comment < ActiveRecord::Base end def initialize(person, target, text) - @text = text + @text = text.strip # remove leading and trailing whitespace now, otherwise it can cause signature issues super(person, target) end From 44e43158cc3ca9e962abd3a75833aa565df0f108 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Fri, 8 Jun 2012 22:50:17 -0600 Subject: [PATCH 2/3] add rspec test and make fix more rails-y --- app/models/comment.rb | 6 +++++- spec/integration/receiving_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 0f3fec09a..21faf3994 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -75,13 +75,17 @@ class Comment < ActiveRecord::Base self.post = parent end + def text= text + self[:text] = text.to_s.strip #to_s if for nil, for whatever reason + end + class Generator < Federated::Generator def self.federated_class Comment end def initialize(person, target, text) - @text = text.strip # remove leading and trailing whitespace now, otherwise it can cause signature issues + @text = text super(person, target) end diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index 3a3ac786c..cd55695d0 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -183,12 +183,28 @@ describe 'a user receives a post' do receive_with_zord(eve, alice.person, xml) comment = eve.comment!(@post, 'tada') + # Note: eve.comment! has already initialized comment.parent_author_signature. Writing to it again + # here causes the test to be different than the way the system actually runs comment.parent_author_signature = comment.sign_with_key(alice.encryption_key) @xml = comment.to_diaspora_xml comment.delete + + comment_with_whitespace = alice.comment!(@post, ' I cannot lift my thumb from the spacebar ') + @xml_with_whitespace = comment_with_whitespace.to_diaspora_xml + @guid_with_whitespace = comment_with_whitespace.guid + comment_with_whitespace.delete end end + it 'should receive a relayed comment with leading whitespace' do + eve.reload.visible_shareables(Post).size.should == 1 + post_in_db = StatusMessage.find(@post.id) + post_in_db.comments.should == [] + receive_with_zord(eve, alice.person, @xml_with_whitespace) + + post_in_db.comments(true).first.guid.should == @guid_with_whitespace + end + it 'should correctly attach the user already on the pod' do bob.reload.visible_shareables(Post).size.should == 1 post_in_db = StatusMessage.find(@post.id) From 9f6d84141c07ce51188c2c7e0cd0962a49d181cb Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Sat, 9 Jun 2012 09:34:06 -0600 Subject: [PATCH 3/3] fix incorrect comment on RSpec text --- spec/integration/receiving_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index cd55695d0..6b15ec72f 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -183,8 +183,8 @@ describe 'a user receives a post' do receive_with_zord(eve, alice.person, xml) comment = eve.comment!(@post, 'tada') - # Note: eve.comment! has already initialized comment.parent_author_signature. Writing to it again - # here causes the test to be different than the way the system actually runs + # After Eve creates her comment, it gets sent to Alice, who signs it with her private key + # before relaying it out to the contacts on the top-level post comment.parent_author_signature = comment.sign_with_key(alice.encryption_key) @xml = comment.to_diaspora_xml comment.delete