Sha256: 1975dd821fab352b7f5c7482ab92e41fa6dbf9080278c30c74b1c0207e647cb6

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

require "test_helper"

module Guts
  class OptionsControllerTest < ActionController::TestCase
    setup do
      @option = guts_options :option_one
      @routes = Engine.routes
    end

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

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

    test "should create option" do
      assert_difference("Option.count") do
        post :create, option: {key: "Testing Key", value: "123"}
      end

      assert_redirected_to options_path
      assert_equal "Option was successfully created.", flash[:notice]
    end

    test "should fail to create option and send back to new" do
      post :create, option: {key: ""}
      assert_template "guts/options/new"
    end
    
    test "should show option" do
      get :show, id: @option
      assert_response :success
    end

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

    test "should update option" do
      patch :update, id: @option, option: {value: "Hey!"}
      assert_redirected_to options_path
      assert_equal "Option was successfully updated.", flash[:notice]
    end
    
    test "should fail to edit option and send back to edit" do
      patch :update, id: @option, option: {key: ""}
      assert_template "guts/options/edit"
    end

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

      assert_redirected_to options_path
      assert_equal "Option was successfully destroyed.", flash[:notice]
    end
    
    test "should allow for custom paginated limit" do
      get :index, per_page: 100
      assert_equal 100, assigns(:per_page).to_i
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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