Fixes for Crystal 0.19

This commit is contained in:
Amit Saha 2016-09-06 13:21:24 +10:00
parent 8c0d4268b9
commit f2659b06fd
3 changed files with 16 additions and 6 deletions

View file

@ -10,7 +10,7 @@ describe "SpecKemalApp" do
it "handles post" do
json_body = {"name": "Serdar", "age": 27, "skills": ["crystal, kemal"]}
post("/user", headers: HTTP::Headers{"Content-Type": "application/json"}, body: json_body.to_json)
post("/user", headers: HTTP::Headers{"Content-Type" => "application/json"}, body: json_body.to_json)
response.body.should eq(json_body.to_json)
end
end

View file

@ -10,7 +10,7 @@ end
post "/user" do |env|
env.response.content_type = "application/json"
name = env.params.json["name"]
age = env.params.json["age"] as Int
skills = env.params.json["skills"] as Array
age = env.params.json["age"]
skills = env.params.json["skills"]
{"name": name, "age": age, "skills": skills}.to_json
end

View file

@ -12,7 +12,17 @@ Kemal.config.host_binding = APP_HOST_BINDING
Kemal.config.port = APP_PORT
Kemal.config.logging = false
$response : HTTP::Client::Response?
class Global
@@response : HTTP::Client::Response?
def self.response=(@@response)
end
def self.response
@@response
end
end
def start
spawn do
@ -29,10 +39,10 @@ end
{% for method in %w(get post put head delete patch) %}
def {{method.id}}(path, headers : HTTP::Headers? = nil, body : String? = nil)
$response = HTTP::Client.{{method.id}}(APP_URL + path, headers, body)
Global.response = HTTP::Client.{{method.id}}(APP_URL + path, headers, body)
end
{% end %}
def response
$response.not_nil!
Global.response.not_nil!
end