Sha256: 9d66f066e2bc5ad23c13988d9258cabace36f09482cd8be09681788c996042ed
Contents?: true
Size: 1.73 KB
Versions: 60
Compression:
Stored size: 1.73 KB
Contents
require 'test_helper' class BaseTest < ActiveSupport::TestCase class Context def assigns {} end end def render(&block) ExpressTemplates.render(Context.new, &block) end class UnorderedList < ExpressTemplates::Components::Base tag :ul has_attributes :class => 'something', 'data-foo' => 'something-else' contains { li { "Some stuff" } } end test ".tag_name determines the enclosing tag" do assert_match /^\<ul/, render { unordered_list } end test ".has_attributes creates default attributes" do assert_match /class="[^"]*something[^"]*"/, render { unordered_list } assert_match /data-foo="[^"]*something-else[^"]*"/, render { unordered_list } end test ".contains places fragment inside the enclosing tag" do markup = render { unordered_list } assert_match /\<ul.*\<li.*\/li\>.*\/ul\>/, markup.gsub("\n", '') end test "class name is dasherized instead of underscored" do assert_match /class="[^"]*unordered-list[^"]*"/, render { unordered_list } end test "options are passed to html attributes" do assert_match /rows="5"/, render { unordered_list(rows: 5) } end test "class option adds a class, does not override" do markup = render { unordered_list(class: 'extra') } assert_match /class="[^"]*something[^"]*"/, markup assert_match /class="[^"]*unordered-list[^"]*"/, markup assert_match /class="[^"]*extra[^"]*"/, markup end class BeforeBuildHook < ExpressTemplates::Components::Base before_build :add_my_foo def add_my_foo set_attribute('data-foo', 'bar') end end test "before_build hook runs before build" do assert_match /data-foo="bar"/, render { before_build_hook } end end
Version data entries
60 entries across 60 versions & 2 rubygems