Sha256: 88ab402e45b77181e51cc9288d2b5e0862c53b6730d634ce482f91412e5ee0ab

Contents?: true

Size: 1.83 KB

Versions: 23

Compression:

Stored size: 1.83 KB

Contents

require 'test_helper'

class ActionLinksTest < MiniTest::Test
  def setup
    @links = ActiveScaffold::DataStructures::ActionLinks.new
  end

  def test_add_and_find
    # test adding with a shortcut
    @links.add 'foo/bar'

    assert_equal 1, @links.find_all { true }.size
    assert_equal 'foo/bar', @links.find_all { true }[0].action
    assert_equal 'foo/bar', @links['foo/bar'].action

    # test adding an ActionLink object directly
    @links.add ActiveScaffold::DataStructures::ActionLink.new('hello/world')

    assert_equal 2, @links.find_all { true }.size

    # test the << alias
    @links << 'a/b'

    assert_equal 3, @links.find_all { true }.size
  end

  def test_array_access
    @link1 = ActiveScaffold::DataStructures::ActionLink.new 'foo/bar'
    @link2 = ActiveScaffold::DataStructures::ActionLink.new 'hello_world'

    @links.add @link1
    @links.add @link2

    assert_equal @link1, @links[@link1.action]
    assert_equal @link2, @links[@link2.action]
  end

  def test_empty
    assert @links.empty?
    @links.add 'a'
    refute @links.empty?
  end

  def test_cloning
    @links.add 'foo/bar'
    @links_copy = @links.clone

    refute @links.equal?(@links_copy)
    refute @links['foo/bar'].equal?(@links_copy['foo/bar'])
  end

  def test_each
    @links.add 'foo', :type => :collection
    @links.add 'bar', :type => :member

    @links.collection.each do |link|
      assert_equal 'foo', link.action
    end
    @links.member.each do |link|
      assert_equal 'bar', link.action
    end
  end

  def test_delete
    @links.add 'foo'
    @links.add 'bar'

    @links.delete :foo
    assert @links['foo'].nil?
    begin
      @links.delete :foo
      @links.delete 'foo'
    rescue StandardError
      assert false, "deleting from action links when item doesn't exist should not throw an error"
    end
    refute @links['bar'].nil?
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
active_scaffold-3.6.20 test/data_structures/action_links_test.rb
active_scaffold-3.6.19 test/data_structures/action_links_test.rb
active_scaffold-3.6.17 test/data_structures/action_links_test.rb
active_scaffold-3.6.15 test/data_structures/action_links_test.rb
active_scaffold-3.6.14 test/data_structures/action_links_test.rb
active_scaffold-3.6.13 test/data_structures/action_links_test.rb
active_scaffold-3.6.12 test/data_structures/action_links_test.rb
active_scaffold-3.6.11.1 test/data_structures/action_links_test.rb
active_scaffold-3.6.11 test/data_structures/action_links_test.rb
active_scaffold-3.6.10 test/data_structures/action_links_test.rb
active_scaffold-3.6.9 test/data_structures/action_links_test.rb
active_scaffold-3.6.8 test/data_structures/action_links_test.rb
active_scaffold-3.6.6 test/data_structures/action_links_test.rb
active_scaffold-3.6.5 test/data_structures/action_links_test.rb
active_scaffold-3.6.4.1 test/data_structures/action_links_test.rb
active_scaffold-3.6.4 test/data_structures/action_links_test.rb
active_scaffold-3.6.3 test/data_structures/action_links_test.rb
active_scaffold-3.6.2 test/data_structures/action_links_test.rb
active_scaffold-3.6.1 test/data_structures/action_links_test.rb
active_scaffold-3.6.0 test/data_structures/action_links_test.rb