Sha256: a5d141bb5e1013800fdce745b90ef27a0c3d9c5a64d4bdbbec91beda4b7a480f

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

require "test_helper"

module Fogged
  class ResourcesControllerCreateTest < ActionController::TestCase
    tests ResourcesController
    include ResourceTestHelper

    def setup
      super
      @resource_params = {
        :name => "Dummy",
        :filename => "dummy.png",
        :content_type => "image/png"
      }
    end

    test "should create resource" do
      assert_difference("Resource.count") do
        post :create, :resource => @resource_params
      end

      assert_json_resource(Resource.last)
      assert_equal "png", Resource.last.extension
    end

    test "should not create resource without resource parameter" do
      assert_no_difference("Resource.count") do
        assert_raise(ActionController::ParameterMissing) do
          post :create
        end
      end
    end

    [:content_type, :name].each do |field|
      test "should not create resource without #{field}" do
        assert_no_difference("Resource.count") do
          assert_raise(ActiveRecord::RecordInvalid) do
            post :create,
                 :resource => @resource_params.merge(field => "")
          end
        end
      end
    end

    test "should not create resource without filename" do
      assert_no_difference("Resource.count") do
        assert_raise(ActionController::ParameterMissing) do
          post :create,
               :resource => @resource_params.except(:filename)
        end
      end
    end

    test "should not create resource with invalid filename" do
      assert_no_difference("Resource.count") do
        assert_raise(ActiveRecord::RecordInvalid) do
          post :create,
               :resource => @resource_params.merge(:filename => "bar")
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fogged-0.0.13 test/controllers/fogged/resources_controller/create_test.rb
fogged-0.0.12 test/controllers/fogged/resources_controller/create_test.rb
fogged-0.0.11 test/controllers/fogged/resources_controller/create_test.rb
fogged-0.0.10 test/controllers/fogged/resources_controller/create_test.rb
fogged-0.0.9 test/controllers/fogged/resources_controller/create_test.rb