From 24e0824a9bf507ff25bea971b3a10d54b1129f58 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Tue, 12 Jul 2016 00:09:01 +0300 Subject: [PATCH] Better view_specs for layout variables --- spec/asset/layout_with_yield.ecr | 9 ++++++--- spec/asset/layout_with_yield_and_vars.ecr | 8 ++++++++ spec/view_spec.cr | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 spec/asset/layout_with_yield_and_vars.ecr diff --git a/spec/asset/layout_with_yield.ecr b/spec/asset/layout_with_yield.ecr index 035cc8d..f6cd673 100644 --- a/spec/asset/layout_with_yield.ecr +++ b/spec/asset/layout_with_yield.ecr @@ -1,3 +1,6 @@ -<%= content %> - -<%= yield_content "custom" %> \ No newline at end of file + + + <%= content %> + <%= yield_content "custom" %> + + \ No newline at end of file diff --git a/spec/asset/layout_with_yield_and_vars.ecr b/spec/asset/layout_with_yield_and_vars.ecr new file mode 100644 index 0000000..3a82a7a --- /dev/null +++ b/spec/asset/layout_with_yield_and_vars.ecr @@ -0,0 +1,8 @@ + + + <%= content %> + <%= yield_content "custom" %> + <%= var1 %> + <%= var2 %> + + \ No newline at end of file diff --git a/spec/view_spec.cr b/spec/view_spec.cr index 1d6a6fe..9ddc879 100644 --- a/spec/view_spec.cr +++ b/spec/view_spec.cr @@ -35,6 +35,20 @@ describe "Views" do client_response.body.should contain("Hello world") end + it "renders layout with variables" do + get "/view/:name" do |env| + name = env.params.url["name"] + var1 = "serdar" + var2 = "kemal" + render "spec/asset/hello_with_content_for.ecr", "spec/asset/layout_with_yield_and_vars.ecr" + 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") + client_response.body.should contain("kemal") + end + it "renders layout with content_for" do get "/view/:name" do |env| name = env.params.url["name"] @@ -42,7 +56,7 @@ describe "Views" do 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("Hello world") client_response.body.should contain("

Hello from otherside

") end end