Sha256: 699c67a3cf782f7ba2161abd982005ad3d5caf2ae95f52de6813940990929299

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

require 'test_helper'

class Seatbelt::AssertContentTypeTest < Minitest::Test
  include Seatbelt::AssertContentType

  def test_assert_content_type_short
    Seatbelt::AssertContentType::SUPPORTED_MIME_TYPES.each do |short, long|
      @response = stub('Response', :headers => {'Content-Type' => "#{long}; charset=utf-8"})
      assert_content_type short
    end
  end

  def test_assert_content_type_short_crosscheck
    Seatbelt::AssertContentType::SUPPORTED_MIME_TYPES.keys.each do |short|
      @response = stub('Response', :headers => {'Content-Type' => "#{wrong_long_for_short(short)}; charset=utf-8"})
      assert_assertion_fails do
        assert_content_type short
      end
    end
  end

  def test_assert_content_type_long
    Seatbelt::AssertContentType::SUPPORTED_MIME_TYPES.each do |short, long|
      @response = stub('Response', :headers => {'Content-Type' => "#{long}; charset=utf-8"})
      assert_content_type long
    end
  end

  def test_assert_content_type_long_crosscheck
    Seatbelt::AssertContentType::SUPPORTED_MIME_TYPES.each do |short, long|
      @response = stub('Response', :headers => {'Content-Type' => "#{wrong_long_for_short(short)}; charset=utf-8"})
      assert_assertion_fails do
        assert_content_type long
      end
    end
  end

private

  def wrong_long_for_short(short)
    Seatbelt::AssertContentType::SUPPORTED_MIME_TYPES.values.select do |long|
      long != Seatbelt::AssertContentType::SUPPORTED_MIME_TYPES[short]
    end.sort_by { rand }.first
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
seatbelt-2.0.0 test/assert_content_type_test.rb
seatbelt-1.0.0 test/assert_content_type_test.rb
seatbelt-0.5.0 test/assert_content_type_test.rb
seatbelt-0.4.0 test/assert_content_type_test.rb
seatbelt-0.3.1 test/assert_content_type_test.rb