shard-kemal/spec/view_spec.cr
Fatih Kadir Akın 8267ffe2c5 Upgrade ParamParser to make it more convinient.
It now decouples `env.params` to `env.params.query`, `env.params.body`,
`env.params.json` and `env.params.url` and you still can access merged
values using `env.params.all`
2016-03-06 13:22:24 +02:00

43 lines
1.6 KiB
Crystal

require "./spec_helper"
macro render_with_base_and_layout(filename)
render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
end
describe "Views" do
it "renders file" do
kemal = Kemal::RouteHandler::INSTANCE
kemal.add_route "GET", "/view/:name" do |env|
name = env.params.url["name"]
render "spec/asset/hello.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
io_with_context = create_request_and_return_io(kemal, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.body.should contain("Hello world")
end
it "renders file with dynamic variables" do
kemal = Kemal::RouteHandler::INSTANCE
kemal.add_route "GET", "/view/:name" do |env|
name = env.params.url["name"]
render_with_base_and_layout "hello.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
io_with_context = create_request_and_return_io(kemal, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.body.should contain("Hello world")
end
it "renders layout" do
kemal = Kemal::RouteHandler::INSTANCE
kemal.add_route "GET", "/view/:name" do |env|
name = env.params.url["name"]
render "spec/asset/hello.ecr", "spec/asset/layout.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
io_with_context = create_request_and_return_io(kemal, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.body.should contain("<html>Hello world")
end
end