tangofoxtrot-table_helper 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class CellByDefaultTest < Test::Unit::TestCase
4
+ def setup
5
+ @cell = TableHelper::Cell.new(:name)
6
+ end
7
+
8
+ def test_should_have_content
9
+ assert_equal 'Name', @cell.content
10
+ end
11
+
12
+ def test_should_have_a_content_type
13
+ assert_equal :data, @cell.content_type
14
+ end
15
+
16
+ def test_should_have_a_class_name
17
+ assert_equal 'name', @cell[:class]
18
+ end
19
+
20
+ def test_should_build_html
21
+ assert_equal '<td class="name">Name</td>', @cell.html
22
+ end
23
+ end
24
+
25
+ class CellTest < Test::Unit::TestCase
26
+ def test_should_raise_exception_if_content_type_is_invalid
27
+ assert_raise(ArgumentError) {TableHelper::Cell.new(:name).content_type = :invalid}
28
+ end
29
+ end
30
+
31
+ class CellWithCustomContentTest < Test::Unit::TestCase
32
+ def setup
33
+ @cell = TableHelper::Cell.new(:name, 'John Smith')
34
+ end
35
+
36
+ def test_should_use_custom_content
37
+ assert_equal 'John Smith', @cell.content
38
+ end
39
+ end
40
+
41
+ class CellWithEmptyContentTest < Test::Unit::TestCase
42
+ def setup
43
+ @cell = TableHelper::Cell.new(:name, nil)
44
+ end
45
+
46
+ def test_should_include_empty_class
47
+ assert_equal 'name ui-state-empty', @cell[:class]
48
+ end
49
+
50
+ def test_should_use_custom_empty_class_if_specified
51
+ original_empty_class = TableHelper::Cell.empty_class
52
+ TableHelper::Cell.empty_class = 'ui-state-blank'
53
+
54
+ cell = TableHelper::Cell.new(:name, nil)
55
+ assert_equal 'name ui-state-blank', cell[:class]
56
+ ensure
57
+ TableHelper::Cell.empty_class = original_empty_class
58
+ end
59
+
60
+ def test_should_build_html
61
+ assert_equal '<td class="name ui-state-empty"></td>', @cell.html
62
+ end
63
+ end
64
+
65
+ class CellWithCustomHtmlOptionsTest < Test::Unit::TestCase
66
+ def setup
67
+ @cell = TableHelper::Cell.new(:name, :style => 'float: left;')
68
+ end
69
+
70
+ def test_should_include_custom_options
71
+ assert_equal 'float: left;', @cell[:style]
72
+ end
73
+
74
+ def test_should_build_html
75
+ assert_equal '<td class="name" style="float: left;">Name</td>', @cell.html
76
+ end
77
+
78
+ def test_should_append_automated_class_name_if_class_already_specified
79
+ cell = TableHelper::Cell.new(:name, :class => 'selected')
80
+ assert_equal 'selected name', cell[:class]
81
+ assert_equal '<td class="selected name">Name</td>', cell.html
82
+ end
83
+ end
84
+
85
+ class CellWithCustomContentAndHtmlOptionsTest < Test::Unit::TestCase
86
+ def setup
87
+ @cell = TableHelper::Cell.new(:name, 'John Smith', :style => 'float: left;')
88
+ end
89
+
90
+ def test_should_use_custom_content
91
+ assert_equal 'John Smith', @cell.content
92
+ end
93
+
94
+ def test_should_include_custom_options
95
+ assert_equal 'float: left;', @cell[:style]
96
+ end
97
+
98
+ def test_should_build_html
99
+ assert_equal '<td class="name" style="float: left;">John Smith</td>', @cell.html
100
+ end
101
+ end
102
+
103
+ class CellWithNamespaceTest < Test::Unit::TestCase
104
+ def setup
105
+ @cell = TableHelper::Cell.new(:name, :namespace => 'post')
106
+ end
107
+
108
+ def test_should_namespace_class
109
+ assert_equal 'post-name', @cell[:class]
110
+ end
111
+ end
112
+
113
+ class CellWithHeaderContentType < Test::Unit::TestCase
114
+ def setup
115
+ @cell = TableHelper::Cell.new(:name)
116
+ @cell.content_type = :header
117
+ end
118
+
119
+ def test_should_have_a_content_type
120
+ assert_equal :header, @cell.content_type
121
+ end
122
+
123
+ def test_should_build_a_header_cell
124
+ assert_equal '<th class="name">Name</th>', @cell.html
125
+ end
126
+ end
@@ -0,0 +1,228 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class CollectionTableByDefaultTest < Test::Unit::TestCase
4
+ def setup
5
+ @collection = []
6
+ @table = TableHelper::CollectionTable.new(@collection)
7
+ end
8
+
9
+ def test_cellspacing_should_be_zero
10
+ assert_equal '0', @table[:cellspacing]
11
+ end
12
+
13
+ def test_cellpadding_should_be_zero
14
+ assert_equal '0', @table[:cellpadding]
15
+ end
16
+
17
+ def test_should_have_a_css_class
18
+ assert_equal 'ui-collection', @table[:class]
19
+ end
20
+
21
+ def test_should_use_custom_collection_css_class_if_specified
22
+ original_collection_class = TableHelper::CollectionTable.collection_class
23
+ TableHelper::CollectionTable.collection_class = 'ui-records'
24
+
25
+ table = TableHelper::CollectionTable.new(@collection)
26
+ assert_equal 'ui-records', table[:class]
27
+ ensure
28
+ TableHelper::CollectionTable.collection_class = original_collection_class
29
+ end
30
+
31
+ def test_should_not_have_a_klass
32
+ assert_nil @table.klass
33
+ end
34
+
35
+ def test_should_not_have_an_object_name
36
+ assert_nil @table.object_name
37
+ end
38
+
39
+ def test_should_have_a_collection
40
+ assert_equal @collection, @table.collection
41
+ end
42
+
43
+ def test_should_have_a_header
44
+ assert_not_nil @table.header
45
+ assert_instance_of TableHelper::Header, @table.header
46
+ end
47
+
48
+ def test_should_have_a_body
49
+ assert_not_nil @table.rows
50
+ assert_instance_of TableHelper::Body, @table.rows
51
+ end
52
+
53
+ def test_should_have_a_footer
54
+ assert_not_nil @table.footer
55
+ assert_instance_of TableHelper::Footer, @table.footer
56
+ end
57
+
58
+ def test_should_be_empty
59
+ assert @table.empty?
60
+ end
61
+ end
62
+
63
+ class CollectionTableTest < Test::Unit::TestCase
64
+ def test_should_accept_block_with_self_as_argument
65
+ args = nil
66
+ table = TableHelper::CollectionTable.new([]) {|*args|}
67
+
68
+ assert_equal [table], args
69
+ end
70
+ end
71
+
72
+ class CollectionTableWithClassDetectionTest < Test::Unit::TestCase
73
+ class Post
74
+ end
75
+
76
+ class Reflection
77
+ def klass
78
+ Post
79
+ end
80
+ end
81
+
82
+ class PostCollection < Array
83
+ def proxy_reflection
84
+ Reflection.new
85
+ end
86
+ end
87
+
88
+ def test_should_not_detect_class_if_collection_is_empty_vanilla_array
89
+ table = TableHelper::CollectionTable.new([])
90
+ assert_nil table.klass
91
+ end
92
+
93
+ def test_should_detect_class_if_collection_has_objects
94
+ table = TableHelper::CollectionTable.new([Post.new])
95
+ assert_equal Post, table.klass
96
+ end
97
+
98
+ def test_should_detect_class_if_collection_is_model_proxy
99
+ table = TableHelper::CollectionTable.new(PostCollection.new)
100
+ assert_equal Post, table.klass
101
+ end
102
+ end
103
+
104
+ class CollectionTableWithClassTest < Test::Unit::TestCase
105
+ class Post
106
+ end
107
+
108
+ def setup
109
+ @table = TableHelper::CollectionTable.new([], Post)
110
+ end
111
+
112
+ def test_should_have_klass
113
+ assert_equal Post, @table.klass
114
+ end
115
+
116
+ def test_should_have_object_name
117
+ assert_equal 'post', @table.object_name
118
+ end
119
+
120
+ def test_should_include_pluralized_object_name_in_css_class
121
+ assert_equal 'posts ui-collection', @table[:class]
122
+ end
123
+ end
124
+
125
+ class CollectionTableWithEmptyCollectionTest < Test::Unit::TestCase
126
+ def setup
127
+ @table = TableHelper::CollectionTable.new([])
128
+ end
129
+
130
+ def test_should_be_empty
131
+ assert @table.empty?
132
+ end
133
+
134
+ def test_should_build_html
135
+ expected = <<-end_str
136
+ <table cellpadding="0" cellspacing="0" class="ui-collection">
137
+ <tbody>
138
+ <tr class="ui-collection-empty"><td>No matches found.</td></tr>
139
+ </tbody>
140
+ </table>
141
+ end_str
142
+ assert_html_equal expected, @table.html
143
+ end
144
+ end
145
+
146
+ class CollectionTableWithObjectsTest < Test::Unit::TestCase
147
+ def setup
148
+ @table = TableHelper::CollectionTable.new([Object.new])
149
+ end
150
+
151
+ def test_should_not_be_empty
152
+ assert !@table.empty?
153
+ end
154
+ end
155
+
156
+ class CollectionTableHeaderTest < Test::Unit::TestCase
157
+ def setup
158
+ @table = TableHelper::CollectionTable.new([Object.new])
159
+ end
160
+
161
+ def test_should_not_include_in_html_if_none_specified
162
+ expected = <<-end_str
163
+ <table cellpadding="0" cellspacing="0" class="objects ui-collection">
164
+ <tbody>
165
+ <tr class="object ui-collection-result"></tr>
166
+ </tbody>
167
+ </table>
168
+ end_str
169
+ assert_html_equal expected, @table.html
170
+ end
171
+
172
+ def test_should_include_in_html_if_specified
173
+ @table.header :name, :title
174
+
175
+ expected = <<-end_str
176
+ <table cellpadding="0" cellspacing="0" class="objects ui-collection">
177
+ <thead>
178
+ <tr>
179
+ <th class="object-name" scope="col">Name</th>
180
+ <th class="object-title" scope="col">Title</th>
181
+ </tr>
182
+ </thead>
183
+ <tbody>
184
+ <tr class="object ui-collection-result">
185
+ <td class="object-name ui-state-empty"></td>
186
+ <td class="object-title ui-state-empty"></td>
187
+ </tr>
188
+ </tbody>
189
+ </table>
190
+ end_str
191
+ assert_html_equal expected, @table.html
192
+ end
193
+ end
194
+
195
+ class CollectionTableFooterTest < Test::Unit::TestCase
196
+ def setup
197
+ @table = TableHelper::CollectionTable.new([Object.new])
198
+ end
199
+
200
+ def test_should_not_include_in_html_if_none_specified
201
+ expected = <<-end_str
202
+ <table cellpadding="0" cellspacing="0" class="objects ui-collection">
203
+ <tbody>
204
+ <tr class="object ui-collection-result"></tr>
205
+ </tbody>
206
+ </table>
207
+ end_str
208
+ assert_html_equal expected, @table.html
209
+ end
210
+
211
+ def test_should_include_in_html_if_specified
212
+ @table.footer :total, 1
213
+
214
+ expected = <<-end_str
215
+ <table cellpadding="0" cellspacing="0" class="objects ui-collection">
216
+ <tbody>
217
+ <tr class="object ui-collection-result"></tr>
218
+ </tbody>
219
+ <tfoot>
220
+ <tr>
221
+ <td class="object-total">1</td>
222
+ </tr>
223
+ </tfoot>
224
+ </table>
225
+ end_str
226
+ assert_html_equal expected, @table.html
227
+ end
228
+ end
@@ -0,0 +1,110 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class FooterByDefaultTest < Test::Unit::TestCase
4
+ def setup
5
+ @table = TableHelper::CollectionTable.new([])
6
+ @footer = TableHelper::Footer.new(@table)
7
+ end
8
+
9
+ def test_should_hide_when_empty
10
+ assert @footer.hide_when_empty
11
+ end
12
+
13
+ def test_should_be_empty
14
+ assert @footer.empty?
15
+ end
16
+
17
+ def test_should_have_a_row
18
+ assert_not_nil @footer.row
19
+ end
20
+
21
+ def test_should_have_a_table
22
+ assert_equal @table, @footer.table
23
+ end
24
+ end
25
+
26
+ class FooterTest < Test::Unit::TestCase
27
+ def setup
28
+ table = TableHelper::CollectionTable.new([Object.new])
29
+ @footer = TableHelper::Footer.new(table)
30
+ end
31
+
32
+ def test_should_include_custom_attributes
33
+ @footer[:class] = 'pretty'
34
+
35
+ expected = <<-end_str
36
+ <tfoot class="pretty">
37
+ <tr>
38
+ </tr>
39
+ </tfoot>
40
+ end_str
41
+ assert_html_equal expected, @footer.html
42
+ end
43
+ end
44
+
45
+ class FooterWithCellsTest < Test::Unit::TestCase
46
+ def setup
47
+ @table = TableHelper::CollectionTable.new([Object.new])
48
+ @footer = TableHelper::Footer.new(@table)
49
+ @cell = @footer.cell :total, 20
50
+ end
51
+
52
+ def test_should_namespace_cell_classes
53
+ assert_equal 'object-total', @cell[:class]
54
+ end
55
+
56
+ def test_should_build_html
57
+ expected = <<-end_str
58
+ <tfoot>
59
+ <tr>
60
+ <td class="object-total">20</td>
61
+ </tr>
62
+ </tfoot>
63
+ end_str
64
+ assert_html_equal expected, @footer.html
65
+ end
66
+
67
+ def test_should_include_colspan_if_more_headers_than_footers
68
+ @table.header :title, :name, :value
69
+
70
+ expected = <<-end_str
71
+ <tfoot>
72
+ <tr>
73
+ <td class="object-total" colspan="3">20</td>
74
+ </tr>
75
+ </tfoot>
76
+ end_str
77
+ assert_html_equal expected, @footer.html
78
+ end
79
+ end
80
+
81
+ class FooterWithEmptyCollectionTest < Test::Unit::TestCase
82
+ def setup
83
+ table = TableHelper::CollectionTable.new([])
84
+ @footer = TableHelper::Footer.new(table)
85
+ end
86
+
87
+ def test_should_not_display_if_hide_when_empty
88
+ @footer.hide_when_empty = true
89
+
90
+ expected = <<-end_str
91
+ <tfoot style="display: none;">
92
+ <tr>
93
+ </tr>
94
+ </tfoot>
95
+ end_str
96
+ assert_html_equal expected, @footer.html
97
+ end
98
+
99
+ def test_should_display_if_not_hide_when_empty
100
+ @footer.hide_when_empty = false
101
+
102
+ expected = <<-end_str
103
+ <tfoot>
104
+ <tr>
105
+ </tr>
106
+ </tfoot>
107
+ end_str
108
+ assert_html_equal expected, @footer.html
109
+ end
110
+ end