Sha256: 01e8276bef3a1b74e5c02e7123621204fefd0253455b8d1541e5cc691213c644

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

require 'assert'
require 'assert-rack-test'
require 'test/support/app'
require 'dassets/server'

module Dassets

  class RackTests < Assert::Context
    include Assert::Rack::Test

    desc "the middleware in a rack app"
    setup do
      app.use Dassets::Server
    end

    def app
      @app ||= SinatraApp
    end

  end

  class SuccessTests < RackTests
    desc "requesting an existing asset file"

    should "return a successful response" do
      resp = get '/file1-daa05c683a4913b268653f7a7e36a5b4.txt'
      assert_equal 200, resp.status
      assert_equal Dassets['file1.txt'].content, resp.body
    end

    should "return a successful response with no body on HEAD requests" do
      resp = head '/file2-9bbe1047cffbb590f59e0e5aeff46ae4.txt'
      assert_equal 200, resp.status
      assert_equal Dassets['file2.txt'].size.to_s, resp.headers['Content-Length']
      assert_empty resp.body
    end

  end

  class NotModifiedTests < RackTests
    desc "requesting an existing asset file that has not been modified"
    setup do
      @resp = get('/file1-daa05c683a4913b268653f7a7e36a5b4.txt', {}, {
        'HTTP_IF_MODIFIED_SINCE' => Dassets['file1.txt'].mtime.to_s
      })
    end

    should "return a successful response" do
      assert_equal 304, @resp.status
      assert_empty @resp.body
    end

  end

  class NotFoundTests < RackTests
    desc "requesting an non-existing asset file"

    should "return a not found response" do
      resp = get '/file1-daa05c683a4913b268.txt'
      assert_equal 404, resp.status

      get '/file1-.txt'
      assert_equal 404, resp.status

      get '/file1.txt'
      assert_equal 404, resp.status

      get '/something-not-found'
      assert_equal 404, resp.status
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dassets-0.4.0 test/system/rack_tests.rb