2016-01-24 17:13:10 +00:00
|
|
|
require "./spec_helper"
|
|
|
|
|
|
|
|
macro render_with_base_and_layout(filename)
|
2021-04-11 09:17:50 +00:00
|
|
|
render "#{__DIR__}/asset/#{{{filename}}}", "#{__DIR__}/asset/layout.ecr"
|
2016-01-24 17:13:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Views" do
|
|
|
|
it "renders file" do
|
2016-03-21 16:29:48 +00:00
|
|
|
get "/view/:name" do |env|
|
2016-03-06 11:22:24 +00:00
|
|
|
name = env.params.url["name"]
|
2021-04-11 09:17:50 +00:00
|
|
|
render "#{__DIR__}/asset/hello.ecr"
|
2016-01-24 17:13:10 +00:00
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/view/world")
|
2016-03-21 16:29:48 +00:00
|
|
|
client_response = call_request_on_app(request)
|
2016-01-24 17:13:10 +00:00
|
|
|
client_response.body.should contain("Hello world")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders file with dynamic variables" do
|
2016-03-21 16:29:48 +00:00
|
|
|
get "/view/:name" do |env|
|
2016-03-06 11:22:24 +00:00
|
|
|
name = env.params.url["name"]
|
2016-01-24 17:13:10 +00:00
|
|
|
render_with_base_and_layout "hello.ecr"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/view/world")
|
2016-03-21 16:29:48 +00:00
|
|
|
client_response = call_request_on_app(request)
|
2016-01-24 17:13:10 +00:00
|
|
|
client_response.body.should contain("Hello world")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders layout" do
|
2016-03-21 16:29:48 +00:00
|
|
|
get "/view/:name" do |env|
|
2016-03-06 11:22:24 +00:00
|
|
|
name = env.params.url["name"]
|
2021-04-11 09:17:50 +00:00
|
|
|
render "#{__DIR__}/asset/hello.ecr", "#{__DIR__}/asset/layout.ecr"
|
2016-01-24 17:13:10 +00:00
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/view/world")
|
2016-03-21 16:29:48 +00:00
|
|
|
client_response = call_request_on_app(request)
|
2016-01-24 17:13:10 +00:00
|
|
|
client_response.body.should contain("<html>Hello world")
|
|
|
|
end
|
2016-07-09 15:57:35 +00:00
|
|
|
|
2016-07-11 21:09:01 +00:00
|
|
|
it "renders layout with variables" do
|
|
|
|
get "/view/:name" do |env|
|
|
|
|
name = env.params.url["name"]
|
|
|
|
var1 = "serdar"
|
|
|
|
var2 = "kemal"
|
2021-04-11 09:17:50 +00:00
|
|
|
render "#{__DIR__}/asset/hello_with_content_for.ecr", "#{__DIR__}/asset/layout_with_yield_and_vars.ecr"
|
2016-07-11 21:09:01 +00:00
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/view/world")
|
|
|
|
client_response = call_request_on_app(request)
|
|
|
|
client_response.body.should contain("Hello world")
|
|
|
|
client_response.body.should contain("serdar")
|
2016-07-17 11:31:45 +00:00
|
|
|
client_response.body.should contain("kemal")
|
2016-07-11 21:09:01 +00:00
|
|
|
end
|
|
|
|
|
2016-07-09 15:57:35 +00:00
|
|
|
it "renders layout with content_for" do
|
2016-07-09 16:54:35 +00:00
|
|
|
get "/view/:name" do |env|
|
|
|
|
name = env.params.url["name"]
|
2021-04-11 09:17:50 +00:00
|
|
|
render "#{__DIR__}/asset/hello_with_content_for.ecr", "#{__DIR__}/asset/layout_with_yield.ecr"
|
2016-07-09 15:57:35 +00:00
|
|
|
end
|
2016-07-09 16:54:35 +00:00
|
|
|
request = HTTP::Request.new("GET", "/view/world")
|
2016-07-09 15:57:35 +00:00
|
|
|
client_response = call_request_on_app(request)
|
2016-07-11 21:09:01 +00:00
|
|
|
client_response.body.should contain("Hello world")
|
2016-07-09 16:54:35 +00:00
|
|
|
client_response.body.should contain("<h1>Hello from otherside</h1>")
|
2016-07-09 15:57:35 +00:00
|
|
|
end
|
2016-01-24 17:13:10 +00:00
|
|
|
end
|