Sha256: 04a7e3d8b12e96a600490587a2b5f27db0485b908817f1040af755f0bf743e28

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

require "erubis"
require_relative "../lib/tynn/render"

setup do
  Tynn.plugin(Tynn::Render, views: File.expand_path("./test/views"))

  Tynn::Test.new
end

test "partial" do |app|
  Tynn.define do
    on "partial" do
      res.write(partial("partial", name: "erb"))
    end
  end

  app.get("/partial")

  assert_equal "erb", app.res.body.strip
end

test "view" do |app|
  Tynn.define do
    on "view" do
      res.write(view("view", title: "tynn", name: "erb"))
    end
  end

  app.get("/view")

  assert_equal "tynn / erb", app.res.body.strip
end

test "render" do |app|
  Tynn.define do
    on "render" do
      render("view", title: "tynn", name: "erb")
    end
  end

  app.get("/render")

  assert_equal 200, app.res.status
  assert_equal "text/html", app.res.headers["Content-Type"]
  assert_equal "tynn / erb", app.res.body.strip
end

test "404" do |app|
  Tynn.define do
    on "404" do
      res.status = 404

      render("view", title: "tynn", name: "erb")
    end
  end

  app.get("/404")

  assert_equal 404, app.res.status
  assert_equal "text/html", app.res.headers["Content-Type"]
  assert_equal "tynn / erb", app.res.body.strip
end

test "custom layout" do
  class App < Tynn
    set :layout, "custom_layout"
  end

  App.define do
    root do
      render("view", title: "tynn", name: "erb")
    end
  end

  app = Tynn::Test.new(App)
  app.get("/")

  assert_equal "custom / tynn / erb", app.res.body.strip
end

test "escapes by default" do
  Tynn.define do
    root do
      res.write(partial("partial", name: "<a></a>"))
    end
  end

  app = Tynn::Test.new
  app.get("/")

  assert_equal "&lt;a&gt;&lt;/a&gt;", app.res.body.strip
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tynn-1.4.0 test/render_test.rb
tynn-1.3.0 test/render_test.rb
tynn-1.2.0 test/render_test.rb
tynn-1.1.0 test/render_test.rb