test/components/base_test.rb in express_templates-0.5.0 vs test/components/base_test.rb in express_templates-0.7.0
- old
+ new
@@ -1,44 +1,46 @@
require 'test_helper'
class BaseTest < ActiveSupport::TestCase
+ def assigns
+ {}
+ end
+
class NoLogic < ExpressTemplates::Components::Base
- has_markup -> {
+ emits {
h1 { span "Some stuff" }
}
end
test ".has_markup makes compile return the block passed through express compiled" do
- assert_equal %Q("<h1><span>Some stuff</span></h1>"), NoLogic.new.compile
+ assert_equal "<h1>\n <span>Some stuff</span>\n</h1>\n", ExpressTemplates.render(self) { no_logic }
end
- test "components register themselves as macros" do
- assert ExpressTemplates::Expander.instance_methods.include?(:no_logic)
+ test "components register themselves as arbre builder methods" do
+ assert Arbre::Element::BuilderMethods.instance_methods.include?(:no_logic)
end
class Context
- def initialize ; @foo = ['bar', 'baz'] ; end
+ def assigns
+ {:foo => ['bar', 'baz']}
+ end
end
- test "fragments and has_markup are synonyms for emits" do
- assert_equal NoLogic.method(:emits), NoLogic.method(:fragments)
- assert_equal NoLogic.method(:emits), NoLogic.method(:has_markup)
- end
+ class HelperExample < ECB
+ def title_helper
+ foo.first
+ end
- class Helpers < ECB
- helper :title_helper, &-> { @foo.first }
-
- emits -> {
+ emits {
h1 {
title_helper
}
}
end
test "helpers defined in component are evaluated in context" do
- compiled = Helpers.new.compile
- assert_equal "<h1>bar</h1>", Context.new.instance_eval(Interpolator.transform(compiled))
+ assert_equal "<h1>bar</h1>\n", ExpressTemplates.render(Context.new) { helper_example }
end
end
\ No newline at end of file