diff options
author | Maxwell Salzberg <maxwell@joindiaspora.com> | 2011-09-14 03:42:47 +0400 |
---|---|---|
committer | Maxwell Salzberg <maxwell@joindiaspora.com> | 2011-09-14 03:42:47 +0400 |
commit | 119cb37ba51a5ac57c4b9df9a61b0ca85c28f5f5 (patch) | |
tree | 17b31e05253b119e235b28e0b3eff92c00c33e61 | |
parent | df87b398c725bb62003985b77d4afd749a9a5d6b (diff) |
DG MS; broke validations into methods in receiver
-rw-r--r-- | lib/postzord/receiver/private.rb | 51 | ||||
-rw-r--r-- | spec/integration/receiving_spec.rb | 4 |
2 files changed, 37 insertions, 18 deletions
diff --git a/lib/postzord/receiver/private.rb b/lib/postzord/receiver/private.rb index 6363e0d62..dd340c320 100644 --- a/lib/postzord/receiver/private.rb +++ b/lib/postzord/receiver/private.rb @@ -34,12 +34,14 @@ module Postzord Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}") if self.validate_object + set_author! receive_object else raise 'not a valid object' end end + # @return [Object] def receive_object obj = @object.receive(@user, @author) Notification.notify(@user, obj, @author) if obj.respond_to?(:notification_type) @@ -64,34 +66,51 @@ module Postzord end def validate_object - #begin similar - unless @object.is_a?(Request) || @user.contact_for(@sender) - Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}") - return false - end + return false if contact_required_unless_request + return false if relayable_without_parent? - #special casey - if @object.is_a?(Request) - @object.sender_handle = @sender.diaspora_handle - end + assign_sender_handle_if_request + + return false if author_does_not_match_xml_author? + + @object + end + + def set_author! + return unless @author + @object.author = @author if @object.respond_to? :author= + @object.person = @author if @object.respond_to? :person= + end + + private - # abort if we haven't received the post to a comment + #validations + def relayable_without_parent? if @object.respond_to?(:relayable?) && @object.parent.nil? Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})") - return false + return true end + end + def author_does_not_match_xml_author? if (@author.diaspora_handle != xml_author) Rails.logger.info("event=receive status=abort reason='author in xml does not match retrieved person' payload_type=#{@object.class} recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}") - return false + return true end + end - if @author - @object.author = @author if @object.respond_to? :author= - @object.person = @author if @object.respond_to? :person= + def contact_required_unless_request + unless @object.is_a?(Request) || @user.contact_for(@sender) + Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}") + return true end + end - @object + def assign_sender_handle_if_request + #special casey + if @object.is_a?(Request) + @object.sender_handle = @sender.diaspora_handle + end end end end diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index 3b12785df..c94a29b73 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -64,7 +64,7 @@ describe 'a user receives a post' do alice.visible_posts.count.should == 1 end - context 'mentions' do + context 'with mentions, ' do it 'adds the notifications for the mentioned users regardless of the order they are received' do Notification.should_receive(:notify).with(alice, anything(), bob.person) Notification.should_receive(:notify).with(eve, anything(), bob.person) @@ -81,7 +81,7 @@ describe 'a user receives a post' do zord.receive_object end - it 'notifies users when receiving a mention in a post from a remote user' do + it 'notifies local users who are mentioned' do @remote_person = Factory.create(:person, :diaspora_handle => "foobar@foobar.com") Contact.create!(:user => alice, :person => @remote_person, :aspects => [@alices_aspect]) |