test/handler_test.rb in express_templates-0.5.0 vs test/handler_test.rb in express_templates-0.7.0
- old
+ new
@@ -1,11 +1,9 @@
require 'test_helper'
class HandlerTest < ActiveSupport::TestCase
- GARAHandler = ExpressTemplates::Template::Handler.new
-
DEFAULT_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
A_LINK = %Q(<a href="#">link</a>)
class LookupContext
def disable_cache
@@ -36,17 +34,21 @@
def capture(&block)
block.call
end
+ def assigns
+ {}
+ end
+
def link_helper
- A_LINK
+ A_LINK.html_safe
end
end
def new_template(body = " h1 'Hello' ", details = { format: :html })
- ActionView::Template.new(body, "hello template", details.fetch(:handler) { GARAHandler }, {:virtual_path => "hello"}.merge!(details))
+ ActionView::Template.new(body, "hello template", details.fetch(:handler) { ExpressTemplates::Template::Handler.new }, {:virtual_path => "hello"}.merge!(details))
end
def render(locals = {})
output = @template.render(@context, locals)
output
@@ -71,52 +73,52 @@
end
test "html generates <h1>Hello</h1> by default" do
@template = new_template
result = render
- assert_equal "<h1>Hello</h1>", result
+ assert_equal "<h1>Hello</h1>\n", result
end
test "nesting elements with ruby block structure" do
@template = new_template("ul { li 'one' ; li 'two' ; li 'three' }")
- assert_equal "<ul><li>one</li><li>two</li><li>three</li></ul>", render
+ assert_equal "<ul>\n <li>one</li>\n <li>two</li>\n <li>three</li>\n</ul>\n", render
end
- test "class names" do
- @template = new_template("p.whatever.another 'Lorum Ipsum' ")
- assert_equal "<p class=\"whatever another\">Lorum Ipsum</p>", render
- end
+ # TODO?: Does not work with arbre
+ # test "class names" do
+ # @template = new_template("p.whatever.another 'Lorum Ipsum' ")
+ # assert_equal "<p class=\"whatever another\">Lorum Ipsum</p>\n", render
+ # end
test "string in block works" do
@template = new_template "h1 { 'foo' } "
- assert_equal "<h1>foo</h1>", render
+ assert_equal "<h1>foo</h1>\n", render
end
# test "real document has doctype and newline" do
# @template = new_template("html { body { h1 \"hello\" } }")
# assert_equal with_doctype("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n <body>\n <h1>hello</h1>\n </body>\n</html>\n"), render
# end
test "other attributes" do
- @template = new_template("p('Lorum Ipsum', style: 'align: right;')")
- assert_equal "<p style=\"align: right;\">Lorum Ipsum</p>", render
+ @template = new_template("para('Lorum Ipsum', style: 'align: right;')")
+ assert_equal "<p style=\"align: right;\">Lorum Ipsum</p>\n", render
end
test "locals work" do
@template = new_template "h1 { my_title }"
@template.locals = [:my_title]
- assert_equal "<h1>Foo</h1>", render(my_title: 'Foo')
+ assert_equal "<h1>Foo</h1>\n", render(my_title: 'Foo')
end
test "helpers returning html when alone in a block" do
@template = new_template("li { link_helper } ")
- assert_equal "<li>#{A_LINK}</li>", render
+ assert_equal "<li>#{A_LINK}</li>\n", render
end
test "helpers returning html work in sequence within a block" do
@template = new_template("li { link_helper ; link_helper } ")
- assert_equal "<li>#{A_LINK}#{A_LINK}</li>", render
+ assert_equal "<li>\n#{A_LINK}#{A_LINK}</li>\n", render
end
-
end
\ No newline at end of file