Sha256: 6e8d5fb5e2f0016c47a08fa1cf03978c1fd108a7dfb6f6becc0add3b750f7fdc

Contents?: true

Size: 1.64 KB

Versions: 29

Compression:

Stored size: 1.64 KB

Contents

require 'test_helper'

class ColumnsTest < MiniTest::Test
  def setup
    @columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b)
  end

  def test_initialization
    assert_equal ModelStub, @columns.active_record_class

    assert @columns.include?('a'), 'checking via string'
    assert @columns.include?(:b), 'checking via symbol'
    refute @columns.include?(:c)
  end

  def test_add
    refute @columns.include?(:c)
    @columns.add 'c'
    assert @columns.include?('c')

    # test the alias
    refute @columns.include?(:d)
    @columns << :d
    assert @columns.include?(:d)

    # try adding an array of columns
    refute @columns.include?(:f)
    @columns.add [:f, :g]
    assert @columns.include?(:f)
    assert @columns.include?(:g)
  end

  def test_finders
    # test some basic assumptions before testing the finders
    assert @columns.include?(:a)
    assert @columns[:a].is_a?(ActiveScaffold::DataStructures::Column)

    # test the single finders
    assert @columns.find_by_name(:a).name == :a
    assert @columns[:b].name == :b

    # test the collection finders
    found = @columns.find_by_names(:a, :b)
    assert found.any? { |c| c.name == :a }
    assert found.any? { |c| c.name == :b }
  end

  def test_each
    @columns.each do |column|
      assert [:a, :b].include?(column.name)
    end
  end

  def test_block_config
    refute @columns.include?(:d)
    refute @columns.include?(:c)

    @columns.configure do |config|
      # test that we can use the config object
      config << :d
      # but test that we don't have to
      add 'c'
    end

    assert @columns.include?(:d)
    assert @columns.include?(:c)
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
active_scaffold-3.4.43 test/data_structures/columns_test.rb
active_scaffold-3.4.42 test/data_structures/columns_test.rb
active_scaffold-3.4.41.1 test/data_structures/columns_test.rb
active_scaffold-3.4.41 test/data_structures/columns_test.rb
active_scaffold-3.4.40 test/data_structures/columns_test.rb
active_scaffold-3.4.39 test/data_structures/columns_test.rb
active_scaffold-3.4.38 test/data_structures/columns_test.rb
active_scaffold-3.4.37 test/data_structures/columns_test.rb
active_scaffold-3.4.36 test/data_structures/columns_test.rb
active_scaffold-3.4.35 test/data_structures/columns_test.rb
active_scaffold-3.4.34 test/data_structures/columns_test.rb
active_scaffold-3.4.33 test/data_structures/columns_test.rb
active_scaffold-3.4.32 test/data_structures/columns_test.rb
active_scaffold-3.4.31 test/data_structures/columns_test.rb
active_scaffold-3.4.30 test/data_structures/columns_test.rb
active_scaffold-3.4.29 test/data_structures/columns_test.rb
active_scaffold-3.4.28 test/data_structures/columns_test.rb
active_scaffold-3.4.27 test/data_structures/columns_test.rb
active_scaffold-3.4.26 test/data_structures/columns_test.rb
active_scaffold-3.4.25 test/data_structures/columns_test.rb