Skip to content
Extraits de code Groupes Projets
comment_spec.rb 4,56 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'
    
    require File.join(Rails.root, "spec", "shared_behaviors", "relayable")
    
      before do
        @alices_aspect = alice.aspects.first
        @bobs_aspect = bob.aspects.first
    
    
        @bob = bob
        @eve = eve
        @status = alice.post(:status_message, :message => "hello", :to => @alices_aspect.id)
    
    maxwell's avatar
    maxwell a validé
      end
    
    
      describe 'comment#notification_type' do
        it "returns 'comment_on_post' if the comment is on a post you own" do
    
          comment = bob.comment("why so formal?", :on => @status)
    
          comment.notification_type(alice, bob.person).should == Notifications::CommentOnPost
    
        end
    
        it 'returns false if the comment is not on a post you own and no one "also_commented"' do
    
          comment = alice.comment("I simply felt like issuing a greeting.  Do step off.", :on => @status)
          comment.notification_type(@bob, alice.person).should == false
    
        end
    
        context "also commented" do
          before do
    
            @bob.comment("a-commenta commenta", :on => @status)
            @comment = @eve.comment("I also commented on the first user's post", :on => @status)
    
          end
    
          it 'does not return also commented if the user commented' do
    
            @comment.notification_type(@eve, alice.person).should == false
    
          end
    
          it "returns 'also_commented' if another person commented on a post you commented on" do
    
            @comment.notification_type(@bob, alice.person).should == Notifications::AlsoCommented
    
          end
        end
      end
    
    Raphael's avatar
    Raphael a validé
      describe 'User#comment' do
    
        it "should be able to comment on one's own status" do
          alice.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 contact's status" do
          bob.comment("sup dog", :on => @status)
    
          @status.reload.comments.first.text.should == "sup dog"
    
        it 'does not multi-post a comment' do
          lambda {
            alice.comment 'hello', :on => @status
          }.should change { Comment.count }.by(1)
    
    Raphael's avatar
    Raphael a validé
      end
    
    Raphael's avatar
    Raphael a validé
      describe 'xml' do
        before do
          @commenter = Factory.create(:user)
          @commenter_aspect = @commenter.aspects.create(:name => "bruisers")
    
          connect_users(alice, @alices_aspect, @commenter, @commenter_aspect)
          @post = alice.post :status_message, :message => "hello", :to => @alices_aspect.id
    
    Raphael's avatar
    Raphael a validé
          @comment = @commenter.comment "Fool!", :on => @post
          @xml = @comment.to_xml.to_s
        end
        it 'serializes the sender handle' do
          @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.author.should == @commenter.person
    
    Raphael's avatar
    Raphael a validé
          end
          it 'marshals the post' do
            @marshalled_comment.post.should == @post
          end
    
      describe 'youtube' do
        before do
    
          @message = alice.post :status_message, :message => "hi", :to => @alices_aspect.id
    
        end
        it 'should process youtube titles on the way in' do
          video_id = "ABYnqp-bxvg"
          url="http://www.youtube.com/watch?v=#{video_id}&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
          expected_title = "UP & down & UP & down &"
    
          mock_http = mock("http")
          Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
          mock_http.should_receive(:get).with('/feeds/api/videos/'+video_id+'?v=2', nil).and_return(
            [nil, 'Foobar <title>'+expected_title+'</title> hallo welt <asd><dasdd><a>dsd</a>'])
    
    
          comment = alice.build_comment url, :on => @message
    
    Raphael's avatar
    Raphael a validé
          Comment.find(comment.id).youtube_titles.should == {video_id => CGI::escape(expected_title)}
    
    danielvincent's avatar
    danielvincent a validé
      describe 'it is relayable' do
    
        before do
          @local_luke, @local_leia, @remote_raphael = set_up_friends
    
          @remote_parent = Factory.create(:status_message, :author => @remote_raphael)
    
    danielvincent's avatar
    danielvincent a validé
          @local_parent = @local_luke.post :status_message, :message => "hi", :to => @local_luke.aspects.first
    
    danielvincent's avatar
    danielvincent a validé
          @object_by_parent_author = @local_luke.comment("yo", :on => @local_parent)
          @object_by_recipient = @local_leia.build_comment("yo", :on => @local_parent)
          @dup_object_by_parent_author = @object_by_parent_author.dup
    
    danielvincent's avatar
    danielvincent a validé
          @object_on_remote_parent = @local_luke.comment("Yeah, it was great", :on => @remote_parent)
    
    danielvincent's avatar
    danielvincent a validé
        it_should_behave_like 'it is relayable'