Skip to content
Extraits de code Groupes Projets
comments_controller_spec.rb 1,92 ko
Newer Older
Raphael's avatar
Raphael 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.

require 'spec_helper'

describe CommentsController do
  render_views

Raphael's avatar
Raphael a validé
  before do
    @user1 = alice
    @user2 = bob
Raphael's avatar
Raphael a validé
    @aspect1 = @user1.aspects.first
    @aspect2 = @user2.aspects.first
Raphael's avatar
Raphael a validé
    sign_in :user, @user1
Raphael's avatar
Raphael a validé
  end

  describe '#create' do
    let(:comment_hash) {
      {:text    =>"facebook, is that you?",
       :post_id =>"#{@post.id}"}
Raphael's avatar
Raphael a validé
    }
Raphael's avatar
Raphael a validé
    context "on my own post" do
      before do
        @post = @user1.post :status_message, :text => 'GIANTS', :to => @aspect1.id
Raphael's avatar
Raphael a validé
      end
      it 'responds to format js' do
        post :create, comment_hash.merge(:format => 'js')
        response.code.should == '201'
Raphael's avatar
Raphael a validé
        response.body.should match comment_hash[:text]
Raphael's avatar
Raphael a validé
      end
    end
    context "on a post from a contact" do
Raphael's avatar
Raphael a validé
      before do
        @post = @user2.post :status_message, :text => 'GIANTS', :to => @aspect2.id
Raphael's avatar
Raphael a validé
      end
      it 'comments' do
        post :create, comment_hash
        response.code.should == '201'
      end
      it "doesn't overwrite author_id" do
        comment_hash[:author_id] = new_user.person.id.to_s
Raphael's avatar
Raphael a validé
        post :create, comment_hash
        Comment.find_by_text(comment_hash[:text]).author_id.should == @user1.person.id
Raphael's avatar
Raphael a validé
      end
      it "doesn't overwrite id" do
Raphael's avatar
Raphael a validé
        old_comment = @user1.comment("hello", :on => @post)
        comment_hash[:id] = old_comment.id
Raphael's avatar
Raphael a validé
        post :create, comment_hash
        old_comment.reload.text.should == 'hello'
      end
    end
    context 'on a post from a stranger' do
      before do
        @post = eve.post :status_message, :text => 'GIANTS', :to => eve.aspects.first.id
Raphael's avatar
Raphael a validé
      end
      it 'posts no comment' do
Raphael's avatar
Raphael a validé
        @user1.should_not_receive(:comment)
Raphael's avatar
Raphael a validé
        post :create, comment_hash
danielvincent's avatar
danielvincent a validé
        response.code.should == '406'
Raphael's avatar
Raphael a validé
      end
    end
  end
end