Sha256: 2e230627a1df184c9d1e8193f5b8346260f86e3cb49256f54cde06cf55d50aff

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

require 'test_helper'
require 'ostruct'

class TreeForTest < ActiveSupport::TestCase
  class Context
    def initialize(roles)
      @roles = roles
    end
  end

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

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

  EXAMPLE_MARKUP = <<-HTML
<ul id="roles" class="roles tree">
  <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

5 entries across 5 versions & 2 rubygems

Version Path
express_admin-1.3.2 vendor/gems/express_templates/test/components/tree_for_test.rb
express_admin-1.3.1 vendor/gems/express_templates/test/components/tree_for_test.rb
express_templates-0.7.1 test/components/tree_for_test.rb
express_templates-0.7.0 test/components/tree_for_test.rb
express_admin-1.3.0 vendor/gems/express_templates/test/components/tree_for_test.rb