sorting_table_for 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,6 +82,13 @@ describe SortingTableFor, :type => :helper do
82
82
  helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
83
83
  end
84
84
 
85
+ it "should have option colspan" do
86
+ table_html = helper.sorting_table_for(@users) do |table|
87
+ html = table.columns :colspan => 5
88
+ html.should have_comp_tag('td[colspan="5"]', :count => (@users.size * User.content_columns.size))
89
+ end
90
+ end
91
+
85
92
  end
86
93
 
87
94
  describe " #table columns" do
@@ -160,6 +167,13 @@ describe SortingTableFor, :type => :helper do
160
167
  helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
161
168
  end
162
169
 
170
+ it "should have option colspan" do
171
+ table_html = helper.sorting_table_for(@users) do |table|
172
+ html = table.columns :username, :colspan => 5
173
+ html.should have_comp_tag('td[colspan="5"]', :count => @users.size)
174
+ end
175
+ end
176
+
163
177
  end
164
178
 
165
179
  describe " #table column" do
@@ -216,6 +230,17 @@ describe SortingTableFor, :type => :helper do
216
230
  helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
217
231
  end
218
232
 
233
+ it "should have option colspan" do
234
+ table_html = helper.sorting_table_for(@users) do |table|
235
+ html = table.columns do
236
+ table.column :username, :colspan => 5
237
+ table.column :price, :colspan => 3
238
+ end
239
+ html.should have_comp_tag('td[colspan="5"]', :count => @users.size)
240
+ html.should have_comp_tag('td[colspan="3"]', :count => @users.size)
241
+ end
242
+ end
243
+
219
244
  end
220
245
 
221
246
  describe " #table column with value" do
@@ -290,6 +315,21 @@ describe SortingTableFor, :type => :helper do
290
315
  helper.output_buffer.concat(table_html)
291
316
  helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
292
317
  end
318
+
319
+ it "should have option colspan" do
320
+ table_html = helper.sorting_table_for(@users) do |table|
321
+ html = table.columns do
322
+ table.column :colspan => 5 do
323
+ 'my_colspan'
324
+ end
325
+ table.column :colspan => 3 do
326
+ 'my_colspan_2'
327
+ end
328
+ end
329
+ html.should have_comp_tag('td[colspan="5"]', :count => @users.size)
330
+ html.should have_comp_tag('td[colspan="3"]', :count => @users.size)
331
+ end
332
+ end
293
333
 
294
334
  end
295
335
 
@@ -301,7 +341,7 @@ describe SortingTableFor, :type => :helper do
301
341
  SortingTableFor::TableBuilder.reserved_columns = [:id, :password, :salt]
302
342
  SortingTableFor::TableBuilder.default_actions = [:edit, :delete]
303
343
  end
304
-
344
+
305
345
  it "should not add total entries" do
306
346
  SortingTableFor::TableBuilder.show_total_entries = false
307
347
  helper.sorting_table_for(@users) do |table|
@@ -0,0 +1,267 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require File.expand_path(File.dirname(__FILE__) + '/../fixtures/user')
5
+
6
+ include SortingTableForSpecHelper
7
+
8
+ describe SortingTableFor, :type => :helper do
9
+
10
+ before :each do
11
+ @users = User.all
12
+ helper.stub!(:url_for).and_return('fake_link')
13
+ helper.stub!(:params).and_return({ :controller => 'fakes', :action => 'index' })
14
+ helper.output_buffer = ''
15
+ end
16
+
17
+ describe ' #default usage' do
18
+
19
+ it "should set nothing" do
20
+ helper.sorting_table_for(@users) do |table|
21
+ html = table.footers
22
+ html.should_not have_comp_tag("tfoot")
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ describe " #table footers" do
29
+
30
+ it "should set a footer with argument" do
31
+ helper.sorting_table_for(@users) do |table|
32
+ html = table.footers 'hello'
33
+ html.should have_comp_tag("tfoot", :count => 1)
34
+ html.should have_comp_tag("tr", :count => 1)
35
+ html.should have_comp_tag("td", :count => 1)
36
+ end
37
+ end
38
+
39
+ it "should set a footer with multiple arguments" do
40
+ helper.sorting_table_for(@users) do |table|
41
+ html = table.footers 'hello', 'hi', 'footer'
42
+ html.should have_comp_tag("tfoot", :count => 1)
43
+ html.should have_comp_tag("tr", :count => 1)
44
+ html.should have_comp_tag("td", :count => 3)
45
+ end
46
+ end
47
+
48
+ it "should set i18n" do
49
+ helper.sorting_table_for(@users) do |table|
50
+ html = table.footers :username
51
+ html.should have_comp_tag('td', :text => 'UserFoot')
52
+ end
53
+ end
54
+
55
+ it "should set i18n for multiple arguments" do
56
+ helper.sorting_table_for(@users) do |table|
57
+ html = table.footers :username, :price
58
+ html.should have_comp_tag('td:nth-child(1)', :text => 'UserFoot')
59
+ html.should have_comp_tag('td:nth-child(2)', :text => 'PriceFoot')
60
+ end
61
+ end
62
+
63
+ it "should works with colspan" do
64
+ helper.sorting_table_for(@users) do |table|
65
+ html = table.footers :username, :colspan => 5
66
+ html.should have_comp_tag('td[colspan="5"]')
67
+ end
68
+ end
69
+
70
+ it "should be customize with html" do
71
+ table_html = helper.sorting_table_for(@users, :html => { :class => 'table_class', :id => 'table_id' }) do |table|
72
+ html = table.footers :username, :html => { :class => 'header_class', :id => 'header_id' }
73
+ html.should have_comp_tag("tr[class=header_class][id=header_id]")
74
+ end
75
+ helper.output_buffer.concat(table_html)
76
+ helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
77
+ end
78
+
79
+ end
80
+
81
+ describe " #table footer" do
82
+
83
+ it "should set a footer with argument" do
84
+ helper.sorting_table_for(@users) do |table|
85
+ html = table.footers do
86
+ table.footer 'hello'
87
+ end
88
+ html.should have_comp_tag("tfoot", :count => 1)
89
+ html.should have_comp_tag("tr", :count => 1)
90
+ html.should have_comp_tag("td", :count => 1)
91
+ end
92
+ end
93
+
94
+ it "should set a footer with multiple arguments" do
95
+ helper.sorting_table_for(@users) do |table|
96
+ html = table.footers do
97
+ table.footer 'hello'
98
+ table.footer 'hi'
99
+ table.footer 'footer'
100
+ end
101
+ html.should have_comp_tag("tfoot", :count => 1)
102
+ html.should have_comp_tag("tr", :count => 1)
103
+ html.should have_comp_tag("td", :count => 3)
104
+ end
105
+ end
106
+
107
+ it "should set i18n" do
108
+ helper.sorting_table_for(@users) do |table|
109
+ html = table.footers do
110
+ table.footer :username
111
+ end
112
+ html.should have_comp_tag('td', :text => 'UserFoot')
113
+ end
114
+ end
115
+
116
+ it "should set i18n for multiple arguments" do
117
+ helper.sorting_table_for(@users) do |table|
118
+ html = table.footers do
119
+ table.footer :username
120
+ table.footer :price
121
+ end
122
+ html.should have_comp_tag('td:nth-child(1)', :text => 'UserFoot')
123
+ html.should have_comp_tag('td:nth-child(2)', :text => 'PriceFoot')
124
+ end
125
+ end
126
+
127
+ it "should works with colspan" do
128
+ helper.sorting_table_for(@users) do |table|
129
+ html = table.footers do
130
+ table.footer :username, :colspan => 5
131
+ end
132
+ html.should have_comp_tag('td[colspan="5"]')
133
+ end
134
+ end
135
+
136
+ it "should be customize with html" do
137
+ table_html = helper.sorting_table_for(@users, :html => { :class => 'table_class', :id => 'table_id' }) do |table|
138
+ html = table.footers(:html => { :class => 'header_class', :id => 'header_id' }) do
139
+ table.footer :username, :html => { :class => 'cell_1_class', :id => 'cell_1_id', :title => 'hello_1' }
140
+ table.footer :firstname, :html => { :class => 'cell_2_class', :id => 'cell_2_id', :title => 'hello_2' }
141
+ table.footer 'hello', :html => { :class => 'cell_3_class', :id => 'cell_3_id', :title => 'hello_3' }
142
+ end
143
+ html.should have_comp_tag("tr[class=header_class][id=header_id]")
144
+ html.should have_comp_tag("td:nth-child(1)[class='cell_1_class'][id=cell_1_id][title=hello_1]")
145
+ html.should have_comp_tag("td:nth-child(2)[class='cell_2_class'][id=cell_2_id][title=hello_2]")
146
+ html.should have_comp_tag("td:nth-child(3)[class=cell_3_class][id=cell_3_id][title=hello_3]")
147
+ end
148
+ helper.output_buffer.concat(table_html)
149
+ helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
150
+ end
151
+
152
+ end
153
+
154
+ describe " #table footer with block" do
155
+
156
+ it "should set a footer with argument" do
157
+ helper.sorting_table_for(@users) do |table|
158
+ html = table.footers do
159
+ table.footer do
160
+ 'hello'
161
+ end
162
+ end
163
+ html.should have_comp_tag("tfoot", :count => 1)
164
+ html.should have_comp_tag("tr", :count => 1)
165
+ html.should have_comp_tag("td", :count => 1)
166
+ end
167
+ end
168
+
169
+ it "should set a footer with multiple arguments" do
170
+ helper.sorting_table_for(@users) do |table|
171
+ html = table.footers do
172
+ table.footer do
173
+ 'hello'
174
+ end
175
+ table.footer do
176
+ 'hi'
177
+ end
178
+ table.footer do
179
+ 'footer'
180
+ end
181
+ end
182
+ html.should have_comp_tag("tfoot", :count => 1)
183
+ html.should have_comp_tag("tr", :count => 1)
184
+ html.should have_comp_tag("td", :count => 3)
185
+ end
186
+ end
187
+
188
+ it "should not set i18n" do
189
+ helper.sorting_table_for(@users) do |table|
190
+ html = table.footers do
191
+ table.footer do
192
+ :username
193
+ end
194
+ end
195
+ html.should_not have_comp_tag('td', :text => 'UserFoot')
196
+ end
197
+ end
198
+
199
+ it "should not set i18n for multiple arguments" do
200
+ helper.sorting_table_for(@users) do |table|
201
+ html = table.footers do
202
+ table.footer do
203
+ :username
204
+ end
205
+ table.footer do
206
+ :price
207
+ end
208
+ end
209
+ html.should_not have_comp_tag('td:nth-child(1)', :text => 'UserFoot')
210
+ html.should_not have_comp_tag('td:nth-child(2)', :text => 'PriceFoot')
211
+ end
212
+ end
213
+
214
+ it "should works with colspan" do
215
+ helper.sorting_table_for(@users) do |table|
216
+ html = table.footers do
217
+ table.footer :colspan => 5 do
218
+ :username
219
+ end
220
+ end
221
+ html.should have_comp_tag('td[colspan="5"]')
222
+ end
223
+ end
224
+
225
+ it "should be customize with html" do
226
+ table_html = helper.sorting_table_for(@users, :html => { :class => 'table_class', :id => 'table_id' }) do |table|
227
+ html = table.footers(:html => { :class => 'header_class', :id => 'header_id' }) do
228
+ table.footer :html => { :class => 'cell_1_class', :id => 'cell_1_id', :title => 'hello_1' } do
229
+ :username
230
+ end
231
+ table.footer :html => { :class => 'cell_2_class', :id => 'cell_2_id', :title => 'hello_2' } do
232
+ :firstname
233
+ end
234
+ table.footer :html => { :class => 'cell_3_class', :id => 'cell_3_id', :title => 'hello_3' } do
235
+ 'hello'
236
+ end
237
+ end
238
+ html.should have_comp_tag("tr[class=header_class][id=header_id]")
239
+ html.should have_comp_tag("td:nth-child(1)[class='cell_1_class'][id=cell_1_id][title=hello_1]")
240
+ html.should have_comp_tag("td:nth-child(2)[class='cell_2_class'][id=cell_2_id][title=hello_2]")
241
+ html.should have_comp_tag("td:nth-child(3)[class=cell_3_class][id=cell_3_id][title=hello_3]")
242
+ end
243
+ helper.output_buffer.concat(table_html)
244
+ helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
245
+ end
246
+
247
+ end
248
+
249
+ describe " #With editable options" do
250
+
251
+ before :each do
252
+ ## Restaure default values
253
+ SortingTableFor::TableBuilder.i18n_add_footer_action_scope = :footer
254
+ end
255
+
256
+ it "should change the i18n add" do
257
+ SortingTableFor::TableBuilder.i18n_add_footer_action_scope = :header
258
+ helper.sorting_table_for(@users) do |table|
259
+ html = table.footers :username, :price
260
+ html.should have_comp_tag('td:nth-child(1)', :text => 'Usernames')
261
+ html.should have_comp_tag('td:nth-child(2)', :text => 'Prices')
262
+ end
263
+ end
264
+
265
+ end
266
+
267
+ end
@@ -55,6 +55,13 @@ describe SortingTableFor, :type => :helper do
55
55
  helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
56
56
  end
57
57
 
58
+ it "should have option colspan" do
59
+ table_html = helper.sorting_table_for(@users) do |table|
60
+ html = table.headers :colspan => 5
61
+ html.should have_comp_tag('th[colspan="5"]', :count => User.content_columns.size)
62
+ end
63
+ end
64
+
58
65
  end
59
66
 
60
67
  describe ' #custom headers' do
@@ -108,6 +115,13 @@ describe SortingTableFor, :type => :helper do
108
115
  html.should have_comp_tag("th:nth-child(5)", :text => 'Edit users')
109
116
  end
110
117
  end
118
+
119
+ it "should have option colspan" do
120
+ table_html = helper.sorting_table_for(@users) do |table|
121
+ html = table.headers :username, :colspan => 5
122
+ html.should have_comp_tag('th[colspan="5"]', :count => 1)
123
+ end
124
+ end
111
125
 
112
126
  end
113
127
 
@@ -206,6 +220,17 @@ describe SortingTableFor, :type => :helper do
206
220
  end
207
221
  end
208
222
 
223
+ it "should have option colspan" do
224
+ table_html = helper.sorting_table_for(@users) do |table|
225
+ html = table.headers do
226
+ table.header :username, :colspan => 5
227
+ table.header :price, :colspan => 3
228
+ end
229
+ html.should have_comp_tag('th[colspan="5"]', :count => 1)
230
+ html.should have_comp_tag('th[colspan="3"]', :count => 1)
231
+ end
232
+ end
233
+
209
234
  end
210
235
 
211
236
  describe ' #custom sub header' do
@@ -291,6 +316,21 @@ describe SortingTableFor, :type => :helper do
291
316
  helper.output_buffer.should have_comp_tag("table[class='table_class sorting_table_for'][id=table_id]")
292
317
  end
293
318
 
319
+ it "should have option colspan" do
320
+ table_html = helper.sorting_table_for(@users) do |table|
321
+ html = table.headers do
322
+ table.header :colspan => 5 do
323
+ 'my_colspan'
324
+ end
325
+ table.header :colspan => 3 do
326
+ 'my_colspan_2'
327
+ end
328
+ end
329
+ html.should have_comp_tag('th[colspan="5"]', :count => 1)
330
+ html.should have_comp_tag('th[colspan="3"]', :count => 1)
331
+ end
332
+ end
333
+
294
334
  end
295
335
 
296
336
  describe ' #With editable options' do
@@ -298,8 +338,9 @@ describe SortingTableFor, :type => :helper do
298
338
  before :each do
299
339
  ## Restaure default values
300
340
  SortingTableFor::TableBuilder.reserved_columns = [:id, :password, :salt]
301
- SortingTableFor::TableBuilder.default_actions = [:edit, :delete]
302
- SortingTableFor::TableBuilder.params_sort_table = :table_sort
341
+ SortingTableFor::TableBuilder.default_actions = [:edit, :delete]
342
+ SortingTableFor::TableBuilder.params_sort_table = :table_sort
343
+ SortingTableFor::TableBuilder.i18n_add_header_action_scope = :header
303
344
  end
304
345
 
305
346
  it "should edit reserved columns" do
@@ -330,6 +371,15 @@ describe SortingTableFor, :type => :helper do
330
371
  end
331
372
  end
332
373
 
374
+ it "should change the i18n add" do
375
+ SortingTableFor::TableBuilder.i18n_add_header_action_scope = :footer
376
+ helper.sorting_table_for(@users) do |table|
377
+ html = table.headers :username, :price
378
+ html.should have_comp_tag('th:nth-child(1)', :text => 'UserFoot')
379
+ html.should have_comp_tag('th:nth-child(2)', :text => 'PriceFoot')
380
+ end
381
+ end
382
+
333
383
  end
334
384
 
335
385
  end
@@ -49,6 +49,7 @@ test:
49
49
 
50
50
  fakes:
51
51
  index:
52
+ table_caption: 'Quick Caption'
52
53
  edit: 'Edit'
53
54
  delete: 'Delete'
54
55
  header:
@@ -64,7 +65,9 @@ test:
64
65
  edit: 'Edit users'
65
66
  delete: 'Delete users'
66
67
  my_fake: 'Hello fake'
67
-
68
+ footer:
69
+ username: 'UserFoot'
70
+ price: 'PriceFoot'
68
71
 
69
72
  fake_scope:
70
73
  my_test: 'Hello'