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

Version Path
express_templates-0.11.19 test/components/base_test.rb
express_templates-0.11.18 test/components/base_test.rb
express_templates-0.11.17 test/components/base_test.rb
express_templates-0.11.16 test/components/base_test.rb
express_templates-0.11.16.rc1 test/components/base_test.rb
express_templates-0.11.15 test/components/base_test.rb
express_templates-0.11.14 test/components/base_test.rb
express_templates-0.11.13 test/components/base_test.rb
express_templates-0.11.11 test/components/base_test.rb
express_templates-0.11.10 test/components/base_test.rb
express_templates-0.11.9 test/components/base_test.rb
express_templates-0.11.8 test/components/base_test.rb
express_templates-0.11.7 test/components/base_test.rb
express_templates-0.11.6 test/components/base_test.rb
express_templates-0.11.5 test/components/base_test.rb
express_templates-0.11.4 test/components/base_test.rb
express_admin-1.7.5 vendor/gems/express_templates/test/components/base_test.rb
express_admin-1.7.4 vendor/gems/express_templates/express_templates/test/components/base_test.rb
express_admin-1.7.3 vendor/gems/express_templates/test/components/base_test.rb
express_admin-1.7.2 vendor/gems/express_templates/test/components/base_test.rb