Skip to content
Extraits de code Groupes Projets
comments_spec.rb 5,26 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    
    Raphael's avatar
    Raphael a validé
    #   the COPYRIGHT file.
    
    require 'spec_helper'
    
    
    describe Comment do
      describe "user" do
        before do
          @user = Factory.create :user
    
    Raphael's avatar
    Raphael a validé
          @aspect = @user.aspect(:name => "Doofuses")
    
    
          @user2 = Factory.create(:user)
    
    Raphael's avatar
    Raphael a validé
          @aspect2 = @user2.aspect(:name => "Lame-faces")
    
        end
        it "should be able to comment on his own status" do
    
          status = Factory.create(:status_message, :person => @user.person)
    
          status.comments.should == []
    
          @user.comment "Yeah, it was great", :on => status
    
          status.reload.comments.first.text.should == "Yeah, it was great"
    
        it "should be able to comment on a person's status" do
          person= Factory.create :person
          status = Factory.create(:status_message, :person => person)
    
    maxwell's avatar
    maxwell a validé
          @user.comment "sup dog", :on => status
    
          status.reload.comments.first.text.should == "sup dog"
          status.reload.comments.first.person.should == @user.person
    
    
        it 'should not send out comments when we have no people' do
    
          status = Factory.create(:status_message, :person => @user.person)
    
          User::QUEUE.should_not_receive(:add_post_request)
    
          @user.comment "sup dog", :on => status
    
    maxwell's avatar
    maxwell a validé
        end
    
        describe 'comment propagation' do
          before do
    
    Raphael's avatar
    Raphael a validé
            friend_users(@user, Aspect.first(:id => @aspect.id), @user2, @aspect2)
    
    Raphael's avatar
    Raphael a validé
    
    
    Raphael's avatar
    Raphael a validé
            @user.activate_friend(@person, Aspect.first(:id => @aspect.id))
    
            @person2 = Factory.create(:person)
    
    maxwell's avatar
    maxwell a validé
            @person_status = Factory.build(:status_message, :person => @person)
    
    Raphael's avatar
    Raphael a validé
            @user_status = @user.post :status_message, :message => "hi", :to => @aspect.id
    
    Raphael's avatar
    Raphael a validé
            @aspect.reload
    
          it 'should receive a comment from a person not on the pod' do
            user3 = Factory.create :user
            aspect3 = user3.aspect(:name => "blah")
    
            friend_users(@user, @aspect, user3, aspect3)
            
            comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => @user_status)
            comment.creator_signature = comment.sign_with_key(user3.encryption_key)
    
    
            comment.post_creator_signature = comment.sign_with_key(@user.encryption_key)
            xml = @user.salmon(comment).xml_for(@user2)
    
            user3.person.delete
            user3.delete
    
             
            @user_status.reload
            @user_status.comments.should == []
            @user2.receive_salmon(xml)
            @user_status.reload
            @user_status.comments.include?(comment).should be true
          end
    
    
    Raphael's avatar
    Raphael a validé
          it 'should have the post in the aspects post list' do
            aspect = Aspect.first(:id => @aspect.id)
            aspect.people.size.should == 2
            aspect.post_ids.include?(@user_status.id).should be true
    
          it "should send a user's comment on a person's post to that person" do
    
            User::QUEUE.should_receive(:add_post_request)
    
    maxwell's avatar
    maxwell a validé
            @user.comment "yo", :on => @person_status
    
          it 'should send a user comment on his own post to lots of people' do
    
    
            User::QUEUE.should_receive(:add_post_request).twice
    
    maxwell's avatar
    maxwell a validé
            @user.comment "yo", :on => @user_status
    
          it 'should send a comment a person made on your post to all people' do
    
    Raphael's avatar
    Raphael a validé
            comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status)
    
            User::QUEUE.should_receive(:add_post_request).twice
    
    ilya's avatar
    ilya a validé
            @user.receive comment.to_diaspora_xml, @person
    
    Raphael's avatar
    Raphael a validé
          end
    
          it 'should send a comment a user made on your post to all people' do
    
    Raphael's avatar
    Raphael a validé
            comment = @user2.comment( "balls", :on => @user_status)
    
            User::QUEUE.should_receive(:add_post_request).twice
    
    ilya's avatar
    ilya a validé
            @user.receive comment.to_diaspora_xml, @user2.person
    
    Raphael's avatar
    Raphael a validé
          it 'should not send a comment a person made on his own post to anyone' do
    
            User::QUEUE.should_not_receive(:add_post_request)
    
    Raphael's avatar
    Raphael a validé
            comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status)
    
    ilya's avatar
    ilya a validé
            @user.receive comment.to_diaspora_xml, @person
    
    Raphael's avatar
    Raphael a validé
          end
    
          it 'should not send a comment a person made on a person post to anyone' do
    
            User::QUEUE.should_not_receive(:add_post_request)
    
    Raphael's avatar
    Raphael a validé
            comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status)
    
    ilya's avatar
    ilya a validé
            @user.receive comment.to_diaspora_xml, @person
    
    Raphael's avatar
    Raphael a validé
          it 'should not clear the aspect post array on receiving a comment' do
            @aspect.post_ids.include?(@user_status.id).should be true
    
            comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status)
    
    
    ilya's avatar
    ilya a validé
            @user.receive comment.to_diaspora_xml, @person
    
    Raphael's avatar
    Raphael a validé
            @aspect.reload
            @aspect.post_ids.include?(@user_status.id).should be true
    
        describe 'serialization' do
          it 'should serialize the commenter' do
            commenter = Factory.create(:user)
    
    Raphael's avatar
    Raphael a validé
            commenter_aspect = commenter.aspect :name => "bruisers"
            friend_users(@user, @aspect, commenter, commenter_aspect)
            post = @user.post :status_message, :message => "hello", :to => @aspect.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