Class: ColumnsTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/columns_test.rb

Overview

require ‘test/model_stub’

Instance Method Summary collapse

Instance Method Details

#setupObject



5
6
7
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/columns_test.rb', line 5

def setup
  @columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b)
end

#test_addObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/columns_test.rb', line 17

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

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

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

#test_block_configObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/columns_test.rb', line 55

def test_block_config
  assert !@columns.include?(:d)
  assert !@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

#test_eachObject



49
50
51
52
53
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/columns_test.rb', line 49

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

#test_findersObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/columns_test.rb', line 34

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

#test_initializationObject



9
10
11
12
13
14
15
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/columns_test.rb', line 9

def test_initialization
  assert_equal ModelStub, @columns.active_record_class

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