Sha256: 05432edf3e27bbbdbc6b8e49281c9b1c406a7193f7f1d4b9d0ab33b746be4f3b

Contents?: true

Size: 1.75 KB

Versions: 4

Compression:

Stored size: 1.75 KB

Contents

require "test_helper"

module Guts
  class CategoriesControllerTest < ActionController::TestCase
    setup do
      @category = guts_categories :test_category
      @routes   = Engine.routes
    end

    test "should get index" do
      get :index
      assert_response :success
      assert_not_nil assigns(:categories)
    end

    test "should get new" do
      get :new
      assert_response :success
    end

    test "should create category" do
      assert_difference("Category.count") do
        post :create, category: {slug: "cat-test", title: "Cat Test"}
      end

      assert_redirected_to categories_path
      assert_equal "Category was successfully created.", flash[:notice]
    end
    
    test "should fail to create category and send back to new" do
      post :create, category: { title: "" }
      assert_template "guts/categories/new"
    end

    test "should show category" do
      get :show, id: @category
      assert_response :success
    end

    test "should get edit" do
      get :edit, id: @category
      assert_response :success
    end

    test "should update category" do
      patch :update, id: @category, category: { slug: @category.slug, title: @category.title }
      assert_redirected_to categories_path
      assert_equal "Category was successfully updated.", flash[:notice]
    end
    
    test "should fail to update category and send back to edit" do
      patch :update, id: @category, category: { title: "" }
      assert_template "guts/categories/edit"
    end

    test "should destroy category" do
      assert_difference("Category.count", -1) do
        delete :destroy, id: @category
      end

      assert_redirected_to categories_path
      assert_equal "Category was successfully destroyed.", flash[:notice]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
guts-1.0.8 test/controllers/guts/categories_controller_test.rb
guts-1.0.7 test/controllers/guts/categories_controller_test.rb
guts-1.0.5 test/controllers/guts/categories_controller_test.rb
guts-1.0.3 test/controllers/guts/categories_controller_test.rb