test/as.rb in cuba-sugar-0.3.0 vs test/as.rb in cuba-sugar-0.3.1
- old
+ new
@@ -1,7 +1,7 @@
-require File.expand_path("helper", File.dirname(__FILE__))
-require 'cuba/sugar/as'
+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
@@ -16,6 +16,28 @@
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