Sha256: bc676b9d8bf676854b4161adacacba908d099b23f972a25a638a0e1c66ffbc77

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require_relative "test_helper"
require "cuba/sugar/as"

test "set status and headers through helper" do
  Cuba.plugin Cuba::Sugar::As
  Cuba.define do
    on "users" do
      as 201, {"Content-Location" => "http://somewhere.com/users/705"} do
        "User Created"
      end
    end
  end

  env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/users" }

  code, headers, resp = Cuba.call(env)

  assert_equal 201, code
  assert_equal ["User Created"], resp
  assert_equal "http://somewhere.com/users/705", headers["Content-Location"]
end

test "set a block to return json" do
  rum_and_coke = { "rum" => "hot", "coke" => "sweet" }

  Cuba.plugin Cuba::Sugar::As
  Cuba.define do
    on "drinks" do
      as_json 201, {"Content-Location" => "http://somewhere.com/drinks/42"} do
        rum_and_coke
      end
    end
  end

  env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/drinks" }

  code, headers, resp = Cuba.call(env)

  assert_equal 201, code
  assert_equal "application/json", headers["Content-Type"]
  assert_equal [rum_and_coke.to_json], resp
  assert_equal "http://somewhere.com/drinks/42", headers["Content-Location"]
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cuba-sugar-0.3.1 test/as.rb