Sha256: f98dfa9d086663baf02921a9b7e634491946a8be85b2d422c7201166c5288bf8

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require 'rails_helper'

describe Admin::PostsController, type: :controller do

  before(:each) do
    activate_session(admin: true)
  end

  describe '#create_redirect_if_necessary' do
    before(:each) do
      @post = FactoryGirl.create(:spud_post)
    end

    it 'should create a redirect' do
      expect do
        put :update, params: { id: @post.id, spud_post: { url_name: 'new-url' }, blog_key: 'blog' }
      end.to change(@post.tb_redirects, :count).by(1)
    end

    it 'should not create a redirect' do
      expect do
        put :update, params: { id: @post.id, spud_post: { title: 'Hello World' }, blog_key: 'blog' }
      end.to_not change(@post.tb_redirects, :count)
    end
  end

  describe '#preview' do
    context 'with a new post' do
      it 'should set the attributes without saving' do
        expect do
          post :preview, params: { blog_key: 'blog', post_id: nil, spud_post: { title: 'Hello World' } }
        end.to_not change(SpudPost, :count)
      end
    end
    context 'with an existing post' do
      it 'should set the attributes without saving' do
        @post = FactoryGirl.create(:spud_post)
        expect do
          post :preview, params: { blog_key: @post.blog_key, post_id: @post.id, spud_post: { title: 'Hello World' } }
          @post.reload
        end.to_not change(@post, :title)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_blog-1.4.1 spec/controllers/admin/posts_controller_spec.rb
tb_blog-1.4.0 spec/controllers/admin/posts_controller_spec.rb
tb_blog-1.4.beta1 spec/controllers/admin/posts_controller_spec.rb