Sha256: 4f505e8c107f674b86c249a69cb7b25d3108258c08d3e9493c0c2d7782fa4141

Contents?: true

Size: 1.21 KB

Versions: 53

Compression:

Stored size: 1.21 KB

Contents

require 'test_helper'
require 'ostruct'

class TreeForTest < ActiveSupport::TestCase

  class Role
    attr :name, :children
    def initialize(name, children: [])
      @name = name
      @children = children
    end
  end

  def roles
    @roles ||= [Role.new('SuperAdmin', children:
          [Role.new('Admin', children:
            [Role.new('Publisher', children:
              [Role.new('Author')]),
             Role.new('Auditor')])])]
  end

  EXAMPLE_MARKUP = <<-HTML
<ul class="tree-for tree roles" id="roles">
  <li>
SuperAdmin
    <ul>
      <li>
Admin
        <ul>
          <li>
Publisher
            <ul>
              <li>Author</li>
            </ul>
          </li>
          <li>Auditor</li>
        </ul>
      </li>
    </ul>
  </li>
</ul>
HTML

  def assigns
    {roles: roles}
  end

  def simple_tree_for
    arbre {
      tree_for(:roles)
    }.to_s
  end

  test "tree_for renders correct markup with node.name as default" do
    assert_equal EXAMPLE_MARKUP, simple_tree_for
  end

  def custom_tree_for
    arbre {
      tree_for(:roles) { |node|
        text_node node.name.upcase
      }
    }
  end

  test "tree_for accepts block with custom content" do
    assert_match 'AUTHOR', custom_tree_for
  end

end

Version data entries

53 entries across 53 versions & 2 rubygems

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