Class: ColumnTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_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/column_test.rb', line 5

def setup
  @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub)
end


140
141
142
143
144
145
146
147
148
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 140

def test_action_link
  link = ActiveScaffold::DataStructures::ActionLink.new('foo/bar')
  @column.set_link link
  assert_equal link, @column.link

  @column.set_link 'hello_world'
  assert_equal 'hello_world', @column.link.action
  assert_equal @column.label, @column.link.label
end

#test_basic_propertiesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 14

def test_basic_properties
  # test that it was set during initialization
  assert_equal @column.name, :a
  # test that we can change it
  @column.name = :b
  assert_equal @column.name, :b

  # label
  @column.label = 'foo'
  assert_equal 'foo', @column.label

  # description
  @column.description = 'hello world'
  assert_equal 'hello world', @column.description

  # css class
  @column.css_class = 'style_me'
  assert_equal 'style_me', @column.css_class

  # required
  assert !@column.required?, 'default is false'
  @column.required = true
  assert @column.required?, 'can be changed'

  # calculation
  assert !@column.calculation?, 'default is nil'
  @column.calculate = :sum
  assert @column.calculation?, 'can be changed'
end

#test_columnObject



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

def test_column
  assert @column.column.is_a?(ActiveRecord::ConnectionAdapters::Column)
  assert @column.column.name == 'a'
end

#test_config_blockObject



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 128

def test_config_block
  @column.configure do |config|
    # we can use the config object
    config.name = 'foo'
    # or not
    self.label = 'hello'
  end

  assert_equal 'foo', @column.name
  assert_equal 'hello', @column.label
end

#test_custom_searchObject



98
99
100
101
102
103
104
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 98

def test_custom_search
  @column.search_sql = true
  assert_equal 'model_stubs.a', @column.search_sql
  @column.search_sql = 'foobar'
  assert_equal 'foobar', @column.search_sql
  assert @column.searchable?
end

#test_custom_sortObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 106

def test_custom_sort
  @column.sort = true
  hash = {:sql => 'model_stubs.a'}
  assert_equal hash, @column.sort
  @column.sort_by :sql => 'foobar'
  hash = {:sql => 'foobar'}
  assert_equal hash, @column.sort

  some_proc = proc {'foobar'}
  @column.sort_by :method => some_proc
  hash = {:method => some_proc}
  assert_equal hash, @column.sort
  assert @column.sortable?
end

#test_custom_sort__should_assert_keysObject



121
122
123
124
125
126
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 121

def test_custom_sort__should_assert_keys
  assert_raise(ArgumentError) { @column.sort_by :proc => "invalid config"  }
  assert_raise(ArgumentError) { @column.sort={:proc => "invalid config" } }
  assert_nothing_raised(ArgumentError) {@column.sort_by :method => "method"  }
  assert_nothing_raised(ArgumentError) {@column.sort_by :sql => "method"  }
end

#test_equalityObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 52

def test_equality
  # create a separate columns object, and make sure it's not ==
  columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b)
  assert columns != @column

  # create a separate action_columns object, and make sure it's not ==
  columns = ActiveScaffold::DataStructures::ActionColumns.new(:a, :b)
  assert columns != @column

  # identity
  assert @column == @column

  # string comparison
  assert @column == 'a'
  assert @column != 'fake'

  # symbol comparison
  assert @column == :a
  assert @column != :fake

  # comparison with different object of same type
  column2 = ActiveScaffold::DataStructures::Column.new(:fake, ModelStub)
  assert @column != column2
  column2.name = 'a'
  assert @column == column2

  # special comparisons
  assert @column != nil
  assert @column != ''
  assert @column != 0
end

#test_fieldObject



44
45
46
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 44

def test_field
  assert_equal 'model_stubs.a', @column.send(:field)
end

#test_includesObject



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 150

def test_includes
  assert_equal [], @column.includes
  
  # make sure that when a non-array comes in, an array comes out
  @column.includes = :column_name
  assert_equal([:column_name], @column.includes)

  # make sure that when a non-array comes in, an array comes out
  @column.includes = [:column_name]
  assert_equal([:column_name], @column.includes)
end

#test_searchableObject



84
85
86
87
88
89
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 84

def test_searchable
  @column.search_sql = nil
  assert !@column.searchable?
  @column.search_sql = true
  assert @column.searchable?
end

#test_sortableObject



91
92
93
94
95
96
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 91

def test_sortable
  @column.sort = nil
  assert !@column.sortable?
  @column.sort = true
  assert @column.sortable?
end

#test_tableObject



48
49
50
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/column_test.rb', line 48

def test_table
  assert_equal 'model_stubs', @column.send(:table)
end