Sha256: 635813a44bbf9811313c1b1dd4d91a4bac027e15939a65fe01f846572df49e1b

Contents?: true

Size: 828 Bytes

Versions: 1

Compression:

Stored size: 828 Bytes

Contents

require "cuba/test"
require_relative "../lib/cuba/send_file"

FILE = __dir__ + "/foo.txt"

Cuba.plugin(Cuba::SendFile)

Cuba.define do
  on root do
    send_file(FILE)
  end

  on "custom" do
    send_file(FILE, "Content-Disposition" => "disposition")
  end
end

scope do
  test "sends the contents of the file" do
    get "/"

    assert_equal 200, last_response.status
    assert_equal "Hello World\n", last_response.body
  end

  test "sets response headers" do
    get "/"

    assert_equal "text/plain", last_response["Content-Type"]
    assert_equal "Hello World\n".length.to_s, last_response["Content-Length"]
    assert_equal File.mtime(FILE).httpdate, last_response["Last-Modified"]
  end

  test "sets custom header" do
    get "/custom"

    assert_equal "disposition", last_response["Content-Disposition"]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cuba-sendfile-0.0.1 test/send_file.rb