Sha256: 15c0fb7dced861482449e3929dde4aaa3d102d62c4346b4756129a6c144ba1f8

Contents?: true

Size: 1.53 KB

Versions: 12

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

describe Almanac::CommentsController do
  before :each do
    @post = create(:post)
  end

  describe "POST create" do
    context "with valid attributes" do
      it "creates a new comment" do
        expect{
          post :create, :use_route => :almanac, comment: attributes_for(:comment), :post_id => @post.id
        }.to change(Almanac::Comment, :count).by(1)
      end

      it "redirects to the post" do
        post :create, :use_route => :almanac, comment: attributes_for(:comment), :post_id => @post.id
        response.should redirect_to @post
      end
    end
    context "with invalid attributes" do
      it "doesn't create a new comment" do
        expect{
          post :create, :use_route => :almanac, comment: attributes_for(:comment, :body => nil), :post_id => @post.id
        }.to_not change(Almanac::Comment, :count)
      end

      it "redirects to the post" do
        post :create, :use_route => :almanac, comment: attributes_for(:comment), :post_id => @post.id
        response.should redirect_to @post
      end
    end
  end

  describe "DELETE destroy" do
    before :each do
      @comment = create(:comment, :post_id => @post.id)
    end

    it "deletes the comment" do
      expect{
        delete :destroy, :use_route => :almanac, id: @comment.id, :post_id => @post.id
      }.to change(Almanac::Comment, :count).by(-1)
    end

    it "redirects to the post" do
      delete :destroy, :use_route => :almanac, id: @comment.id, :post_id => @post.id
      response.should redirect_to @post
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
almanac-0.7.4 spec/controllers/comments_controller_spec.rb
almanac-0.7.3 spec/controllers/comments_controller_spec.rb
almanac-0.7.2 spec/controllers/comments_controller_spec.rb
almanac-0.7.1 spec/controllers/comments_controller_spec.rb
almanac-0.6.1 spec/controllers/comments_controller_spec.rb
almanac-0.6.0 spec/controllers/comments_controller_spec.rb
almanac-0.5.3 spec/controllers/comments_controller_spec.rb
almanac-0.5.2 spec/controllers/comments_controller_spec.rb
almanac-0.5.1 spec/controllers/comments_controller_spec.rb
almanac-0.5.0 spec/controllers/comments_controller_spec.rb
almanac-0.4.5 spec/controllers/comments_controller_spec.rb
almanac-0.4.4 spec/controllers/comments_controller_spec.rb