Skip to content
Extraits de code Groupes Projets
message_spec.rb 3,54 ko
Newer Older
  • Learn to ignore specific revisions
  • danielvincent's avatar
    danielvincent a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
    require 'spec_helper'
    
    require File.join(Rails.root, "spec", "shared_behaviors", "relayable")
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
    
    describe Message do
      before do
        @user1 = alice
        @user2 = bob
    
    
        @create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id],
                         :subject => "cool stuff", :text => "stuff"}
    
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
        @cnv = Conversation.create(@create_hash)
    
    danielvincent's avatar
    danielvincent a validé
        @message = @cnv.messages.first
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
        @xml = @message.to_diaspora_xml
      end
    
    
      it 'validates that the author is a participant in the conversation' do
        msg = Message.new(:text => 'yo', :author => eve.person, :conversation_id => @cnv.id)
    
      end
    
      describe '#notification_type' do
        it 'does not return anything for the author' do
          @message.notification_type(@user1, @user1.person).should be_nil
        end
    
        it 'returns private mesage for an actual receiver' do
          @message.notification_type(@user2, @user1.person).should == Notifications::PrivateMessage
        end
    
    danielvincent's avatar
    danielvincent a validé
        it 'signs the message' do
    
          @message.author_signature.should_not be_blank
    
    danielvincent's avatar
    danielvincent a validé
        end
    
        it 'signs the message author if author of conversation' do
    
          @message.parent_author_signature.should_not be_blank
    
    danielvincent's avatar
    danielvincent a validé
        end
      end
    
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
      describe 'serialization' do
        it 'serializes the text' do
          @xml.should include(@message.text)
        end
    
        it 'serializes the author_handle' do
          @xml.should include(@message.author.diaspora_handle)
        end
    
        it 'serializes the created_at time' do
          @xml.should include(@message.created_at.to_s)
        end
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
        it 'serializes the conversation_guid time' do
          @xml.should include(@message.conversation.guid)
        end
      end
    
    
    danielvincent's avatar
    danielvincent a validé
      describe 'it is relayable' do
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
        before do
    
    danielvincent's avatar
    danielvincent a validé
          @local_luke, @local_leia, @remote_raphael = set_up_friends
    
    
          cnv_hash = {:author => @remote_raphael, :participant_ids => [@local_luke.person, @local_leia.person, @remote_raphael].map(&:id),
                      :subject => 'cool story, bro', :text => 'hey'}
    
    danielvincent's avatar
    danielvincent a validé
    
          @remote_parent = Conversation.create(cnv_hash.dup)
    
    
          cnv_hash[:author] = @local_luke.person
    
    danielvincent's avatar
    danielvincent a validé
          @local_parent = Conversation.create(cnv_hash)
    
          msg_hash = {:author => @local_luke.person, :text => 'yo', :conversation => @local_parent}
          @object_by_parent_author = Message.create(msg_hash.dup)
          Postzord::Dispatch.new(@local_luke, @object_by_parent_author).post
    
          msg_hash[:author] = @local_leia.person
          @object_by_recipient = Message.create(msg_hash.dup)
    
          @dup_object_by_parent_author = @object_by_parent_author.dup
    
    danielvincent's avatar
    danielvincent a validé
          msg_hash[:author] = @local_luke.person
          msg_hash[:conversation] = @remote_parent
          @object_on_remote_parent = Message.create(msg_hash)
          Postzord::Dispatch.new(@local_luke, @object_on_remote_parent).post
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
        end
    
    danielvincent's avatar
    danielvincent a validé
        it_should_behave_like 'it is relayable'
    
    
        describe '#after_receive' do
          it 'increments the conversation visiblity for the conversation' do
           ConversationVisibility.where(:conversation_id => @object_by_recipient.reload.conversation.id,
                                                         :person_id => @local_luke.person.id).first.unread.should == 0
      
            @object_by_recipient.receive(@local_luke, @local_leia.person)
            ConversationVisibility.where(:conversation_id => @object_by_recipient.reload.conversation.id,
                                                         :person_id => @local_luke.person.id).first.unread.should == 1
          end
        end
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
      end
    end