sortablecolumns 0.1.0

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,24 @@
1
+ -
2
+ dudename:
3
+ heading: Dudename
4
+ datatype: string
5
+ link_options:
6
+ object_url: true
7
+
8
+ -
9
+ lastname:
10
+ heading: Last
11
+ datatype: string
12
+ -
13
+ age:
14
+ heading: Age
15
+ datatype: number
16
+ -
17
+ description:
18
+ heading: Description
19
+ datatype: string
20
+ sortable: false
21
+ print_options:
22
+ wrappers:
23
+ - truncate: 5
24
+ - simple_format
@@ -0,0 +1,64 @@
1
+ -
2
+ firstname:
3
+ heading: First
4
+ datatype: string
5
+ link_options:
6
+ controller: people
7
+ action: show
8
+ id: obj_id
9
+ td_class: left
10
+
11
+ -
12
+ lastname:
13
+ heading: Last
14
+ datatype: string
15
+ print_options:
16
+ wrappers: sanitize
17
+ -
18
+ age:
19
+ datatype: number
20
+ sort_options:
21
+ default_dir: desc
22
+ td_class: center
23
+ -
24
+ description:
25
+ datatype: string
26
+ sortable: false
27
+ print_options:
28
+ wrappers:
29
+ - auto_link
30
+ - sanitize
31
+ - simple_format
32
+ td_class: left
33
+ -
34
+ balance:
35
+ datatype: currency
36
+ precision: 2
37
+ separator: ","
38
+ delimiter: " "
39
+ unit: £
40
+ td_class: right
41
+
42
+ -
43
+ edit:
44
+ in_resultset: false
45
+ heading: false
46
+ th_class: invisible
47
+ print_text: Edit
48
+ link_options:
49
+ controller: people
50
+ action: edit
51
+ id: obj_id
52
+ -
53
+ delete:
54
+ in_resultset: false
55
+ heading: false
56
+ th_class: invisible
57
+ print_text: Delete
58
+ link_options:
59
+ controller: people
60
+ action: destroy
61
+ id: obj_id
62
+ extras:
63
+ method: delete
64
+ confirm: Are you sure?
@@ -0,0 +1,23 @@
1
+ -
2
+ type:
3
+ heading: Taco Type
4
+ datatype: string
5
+ link_options:
6
+ url: "http://www.tacotypes.com"
7
+ -
8
+ meat:
9
+ heading: Meat
10
+ datatype: string
11
+ link_options:
12
+ url: "/foods/meats/:id"
13
+ sort_options:
14
+ order_by: meats.id
15
+ -
16
+ calories:
17
+ heading: Calories
18
+ datatype: number
19
+ precision: 2
20
+ link_options:
21
+ controller: foods
22
+ action: calories
23
+ foo: bar
@@ -0,0 +1,510 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'sortable_columns'
5
+ require 'action_controller/integration'
6
+
7
+ RAILS_ROOT = File.dirname(__FILE__) + '/../'
8
+
9
+ #If you have SQLite3 installed along with the sqlite3-ruby gem, you can run this
10
+ #test file without any prior setup.
11
+ #Based on test code for Rails' acts_as_tree
12
+ #http://dev.rubyonrails.org/svn/rails/plugins/acts_as_tree/test/acts_as_tree_test.rb
13
+
14
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
15
+
16
+ # AR keeps printing annoying schema statements
17
+ $stdout = StringIO.new
18
+
19
+ def setup_db
20
+ ActiveRecord::Base.logger
21
+ ActiveRecord::Schema.define(:version => 1) do
22
+ create_table :people do |t|
23
+ t.column :firstname, :string
24
+ t.column :lastname, :string
25
+ t.column :age, :integer
26
+ t.column :description, :string
27
+ t.column :balance, :decimal
28
+ end
29
+ end
30
+ end
31
+
32
+ def teardown_db
33
+ ActiveRecord::Base.connection.tables.each do |table|
34
+ ActiveRecord::Base.connection.drop_table(table)
35
+ end
36
+ end
37
+
38
+ #---------------------------------------------------
39
+ # Models
40
+ #---------------------------------------------------
41
+ class Person < ActiveRecord::Base
42
+ sortable_columns :mysorter,
43
+ :path_prefix => "/test/col_def_test_yaml_files"
44
+ sortable_columns :tacosorter,
45
+ :path_prefix => "/test/col_def_test_yaml_files"
46
+
47
+ #Some mock methods. Normally we would have an AR object which could have been
48
+ #created by a find_by_sql query, which could include methods such as these.
49
+ def meat
50
+ 'Beef'
51
+ end
52
+
53
+ def type
54
+ 'Soft Shell'
55
+ end
56
+
57
+ def calories
58
+ 1200
59
+ end
60
+ end
61
+
62
+ class Dude < Person
63
+ sortable_columns :dude_report, :subclass_name => 'Dude',
64
+ :path_prefix => "/test/col_def_test_yaml_files"
65
+
66
+ def dudename
67
+ firstname
68
+ end
69
+ end
70
+
71
+ class SubPerson < Person
72
+ sortable_columns :cool_sorter_thing, :subclass_name => 'SubPerson',
73
+ :path_prefix => "/test/col_def_test_yaml_files"
74
+ end
75
+
76
+ #---------------------------------------------------
77
+ # Routes
78
+ #---------------------------------------------------
79
+ ActionController::Routing::Routes.draw do |map|
80
+ map.person '/people/show/:id',
81
+ :controller => 'people',
82
+ :action => 'show'
83
+ map.people_foods '/people/:person_id/foods',
84
+ :controller => 'foods',
85
+ :action => 'show'
86
+ #simulate the RESTful urls:
87
+ map.dude '/dudes/:id',
88
+ :controller => 'dudes',
89
+ :action => 'show'
90
+
91
+ map.connect '/:controller/:action/:id'
92
+
93
+ end
94
+
95
+
96
+ #---------------------------------------------------
97
+ # Tests
98
+ #---------------------------------------------------
99
+ class SortableColumnsTest< Test::Unit::TestCase
100
+ def setup
101
+ setup_db
102
+ @person = Person.create(:firstname => "Billy", :lastname => "Jones", :age => 24,
103
+ :description => "Billy is an awesome guy.\nHowever, he is also a punk. He loves www.google.com. ")
104
+ @person.save
105
+ end
106
+
107
+ def teardown
108
+ teardown_db
109
+ end
110
+
111
+ def test_basic
112
+ assert @person.valid?
113
+ end
114
+
115
+ def test_person_yaml_path
116
+ assert_equal "./../test/col_def_test_yaml_files/person/mysorter.yml", Person.mysorter_yaml_path
117
+ end
118
+
119
+ def test_sub_person_yaml_path
120
+ #test sub-models & models with multi-word names, such as SubPerson
121
+ assert_equal "./../test/col_def_test_yaml_files/person/sub_person/cool_sorter_thing.yml", SubPerson.cool_sorter_thing_yaml_path
122
+ end
123
+
124
+ def test_person_mysorter_yaml_load
125
+ col_defs = Person.mysorter_col_defs
126
+ assert_equal Array, col_defs.class
127
+ expected = {"firstname"=>
128
+ {"link_options"=>{:action=>"show", :id=>'obj_id', :controller=>"people"},
129
+ "td_class"=>"left",
130
+ "heading"=>"First",
131
+ "datatype"=>"string"}}
132
+ assert_equal expected, col_defs[0]
133
+ end
134
+
135
+ def test_person_tacosorter_yaml_load
136
+ col_defs = Person.tacosorter_col_defs
137
+ assert_equal Array, col_defs.class
138
+ expected = {"type"=>
139
+ {"link_options"=>{:url=>"http://www.tacotypes.com"},
140
+ "heading"=>"Taco Type",
141
+ "datatype"=>"string"}}
142
+ assert_equal expected, col_defs[0]
143
+ end
144
+
145
+ def test_dude_yaml_path
146
+ assert_equal "./../test/col_def_test_yaml_files/person/dude/dude_report.yml", Dude.dude_report_yaml_path
147
+ end
148
+
149
+ def test_dude_yaml_load
150
+ col_defs = Dude.dude_report_col_defs
151
+ assert_equal Array, col_defs.class
152
+ expected = {"dudename"=> {"link_options"=>{:object_url=>true}, "heading"=>"Dudename", "datatype"=>"string"}}
153
+ assert_equal expected, col_defs[0]
154
+ end
155
+
156
+ def test_dude_col_def_hash
157
+ expected = {"lastname"=>{"heading"=>"Last", "datatype"=>"string"},
158
+ "description"=>
159
+ {"print_options"=>{"wrappers"=>[{"truncate"=>5}, "simple_format"]},
160
+ "sortable"=>false,
161
+ "heading"=>"Description",
162
+ "datatype"=>"string"},
163
+ "dudename"=>
164
+ {"link_options"=>{:object_url=>true},
165
+ "heading"=>"Dudename",
166
+ "datatype"=>"string"},
167
+ "age"=>{"heading"=>"Age", "datatype"=>"number"}}
168
+ assert_equal expected, Dude.dude_report_col_def_hash
169
+ end
170
+
171
+ def test_col_keys_in_order
172
+ assert_equal ['firstname','lastname','age','description','balance','edit','delete'], Person.mysorter_col_keys_in_order
173
+ assert_equal ['type','meat','calories'], Person.tacosorter_col_keys_in_order
174
+ end
175
+
176
+ def test_heading
177
+ assert_equal 'Last', Dude.dude_report_heading('lastname')
178
+ assert_equal 'Description', Dude.dude_report_heading('description')
179
+ assert_equal 'Meat', Person.tacosorter_heading('meat')
180
+ assert_equal 'First', Person.mysorter_heading('firstname')
181
+ assert_equal false, Person.mysorter_heading('edit')
182
+ end
183
+
184
+ def test_headings_in_order
185
+ assert_equal Dude.dude_report_headings_in_order, ['Dudename','Last','Age','Description']
186
+ assert_equal Person.tacosorter_headings_in_order, ['Taco Type','Meat','Calories']
187
+ #should not include the edit field in headings:
188
+ assert_equal Person.mysorter_headings_in_order, ['First','Last','Age','Description','Balance']
189
+ end
190
+
191
+ def test_datatype
192
+ assert_equal 'string', Dude.dude_report_datatype('lastname')
193
+ assert_equal 'number', Dude.dude_report_datatype('age')
194
+ assert_equal 'currency', Person.mysorter_datatype('balance')
195
+ end
196
+
197
+ def test_sortable
198
+ assert_equal true, Dude.dude_report_sortable?('lastname')
199
+ assert_equal false, Dude.dude_report_sortable?('description')
200
+ assert_equal false, Person.mysorter_sortable?('edit')
201
+ end
202
+
203
+ def test_link
204
+ assert_equal true, Person.mysorter_link?('firstname')
205
+ assert_equal false, Person.mysorter_link?('description')
206
+ end
207
+
208
+ def test_sort_options
209
+ assert_equal({"default_dir"=> 'desc'}, Person.mysorter_sort_options('age'))
210
+ assert_equal nil, Person.mysorter_sort_options('description')
211
+ end
212
+
213
+ def test_print_options
214
+ assert_equal({"wrappers"=> ['auto_link','sanitize', 'simple_format']}, Person.mysorter_print_options('description'))
215
+ assert_equal({"wrappers"=> 'sanitize'}, Person.mysorter_print_options('lastname'))
216
+ assert_equal nil, Person.mysorter_print_options('age')
217
+ assert_equal({"wrappers"=> [{'truncate' => 5},'simple_format']}, Dude.dude_report_print_options('description'))
218
+ end
219
+
220
+ def test_td_class
221
+ assert_equal 'center', Person.mysorter_td_class('age')
222
+ assert_equal nil, Person.mysorter_td_class('lastname')
223
+ end
224
+
225
+ def test_precision
226
+ assert_equal 2, Person.mysorter_precision('balance')
227
+ assert_equal nil, Person.mysorter_precision('firstname')
228
+ end
229
+
230
+ def test_delimiter
231
+ assert_equal " ", Person.mysorter_delimiter('balance')
232
+ assert_equal ",", Person.mysorter_delimiter('age')
233
+ end
234
+
235
+ def test_separator
236
+ assert_equal ",", Person.mysorter_separator('balance')
237
+ assert_equal ".", Person.mysorter_separator('age')
238
+ end
239
+
240
+ def test_default_sort_dir
241
+ assert_equal "desc", Person.mysorter_default_sort_dir('age')
242
+ assert_equal 'asc', Person.mysorter_default_sort_dir('firstname')
243
+ end
244
+
245
+ def test_col_def_for_yui
246
+ expected = {:sortOptions=>{:defaultDir=>"YAHOO.widget.DataTable.CLASS_DESC"}, :key=>"age", :sortable=>true,
247
+ :label=>"Age", :formatter=>"number"}
248
+ assert_equal expected, Person.mysorter_col_def_for_yui('age')
249
+ end
250
+
251
+ def test_col_defs_for_yui
252
+ expected = [{:key=>"firstname", :sortable=>true, :label=>"First"},
253
+ {:key=>"lastname", :sortable=>true, :label=>"Last"},
254
+ {:key=>"age",
255
+ :sortable=>true,
256
+ :label=>"Age",
257
+ :formatter=>"number",
258
+ :sortOptions=>{:defaultDir=>"YAHOO.widget.DataTable.CLASS_DESC"}},
259
+ {:key=>"description", :sortable=>false, :label=>"Description"},
260
+ {:key=>"balance", :sortable=>true, :label=>"Balance", :formatter=>"currency"},
261
+ {:key=>"edit", :sortable=>false, :label=>""},
262
+ {:key=>"delete", :sortable=>false, :label=>""}]
263
+ assert_equal expected, Person.mysorter_col_defs_for_yui
264
+ end
265
+
266
+ def test_fields_for_yui
267
+ expected = [{:key=>"firstname"},
268
+ {:key=>"lastname"},
269
+ {:key=>"age", :parser=>"YAHOO.util.DataSource.parseNumber"},
270
+ {:key=>"description"},
271
+ {:key=>"balance", :parser=>"this.parseNumberFromCurrency"},
272
+ {:key=>"edit"},
273
+ {:key=>"delete"}]
274
+ assert_equal expected, Person.mysorter_fields_for_yui
275
+ end
276
+
277
+ end
278
+
279
+
280
+ #------------------------------------------------
281
+ # Helpers
282
+ #------------------------------------------------
283
+
284
+ class SortableColumnsHelperTest < Test::Unit::TestCase
285
+ #include SortableColumns::Helpers
286
+
287
+ class View
288
+ #include ActionController
289
+ #include ActionView::Helpers::AssetTagHelper
290
+ include ActionView::Helpers::TextHelper
291
+ include ActionView::Helpers::NumberHelper
292
+ include ActionView::Helpers::SanitizeHelper
293
+ include ActionView::Helpers::TagHelper
294
+ include ActionView::Helpers::UrlHelper
295
+ include ActionController::UrlWriter
296
+ include SortableColumns::Helpers
297
+ default_url_options[:host] = 'test.host'
298
+ attr_accessor :params
299
+ attr_accessor :request
300
+
301
+ def initialize
302
+ @request = ActionController::TestRequest.new
303
+ @request.request_uri = 'http://' + default_url_options[:host] + "/people"
304
+ @params = {}
305
+ @params[:controller] = 'people'
306
+ @params[:action] = 'index'
307
+ end
308
+
309
+ def protect_against_forgery?
310
+ false
311
+ end
312
+ end
313
+
314
+ def setup
315
+ @view = View.new
316
+ setup_db
317
+ @person = Person.create(:firstname => "Billy", :lastname => "Jones",
318
+ :age => 24, :balance => '1234.5678',
319
+ :description => "Billy is an awesome guy.\nHowever, he is also a punk. " +
320
+ "<script src='http://www.badguy.com/death.js'/>He loves www.google.com")
321
+
322
+ @person2 = Person.create(:firstname => "Joe", :lastname => "Shmoe", :age => 54,
323
+ :balance => '12.00', :description => "Joe rocks")
324
+
325
+ @dude = Dude.create(:firstname => "The Dude", :lastname => "Lebowski", :age => 45,
326
+ :description => "The Dude Speaks")
327
+
328
+ @expected_person_row = "<tr><td class=\"left\"><a href=\"http://test.host/people/show/1\">Billy</a></td><td>Jones</td><td class=\"center\">24</td><td class=\"left\"><p>Billy is an awesome guy.\n<br />However, he is also a punk. <a href=\"http://www.google.com\">www.google.com</a></p></td><td class=\"right\">£1 234,57</td><td><a href=\"http://test.host/people/edit/1\">Edit</a></td><td><a href=\"http://test.host/people/destroy/1\" onclick=\"if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;\">Delete</a></td></tr>"
329
+ @expected_person_row_alternate = @expected_person_row.gsub(/<tr>/, "<tr class=\"even\">")
330
+ @expected_person2_row = "<tr><td class=\"left\"><a href=\"http://test.host/people/show/2\">Joe</a></td><td>Shmoe</td><td class=\"center\">54</td><td class=\"left\"><p>Joe rocks</p></td><td class=\"right\">£12,00</td><td><a href=\"http://test.host/people/edit/2\">Edit</a></td><td><a href=\"http://test.host/people/destroy/2\" onclick=\"if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;\">Delete</a></td></tr>"
331
+ @expected_person2_row_alternate = @expected_person2_row.gsub(/<tr>/, "<tr class=\"odd\">")
332
+ @expected_person_heading_row = "<tr><th><a href=\"http://test.host/people?dir=asc&order_by=firstname\">First</a></th><th><a href=\"http://test.host/people?dir=asc&order_by=lastname\">Last</a></th><th><a href=\"http://test.host/people?dir=desc&order_by=age\">Age</a></th><th>Description</th><th><a href=\"http://test.host/people?dir=asc&order_by=balance\">Balance</a></th><th class=\"invisible\"></th><th class=\"invisible\"></th></tr>"
333
+ end
334
+
335
+ def teardown
336
+ teardown_db
337
+ end
338
+
339
+ def test_print_col_person_lastname
340
+ assert_equal '<td>Jones</td>', @view.print_col(@person, 'mysorter', 'lastname')
341
+ assert_equal '<td>Jones</td>', @view.print_col(@person, :mysorter, :lastname)
342
+ end
343
+
344
+ def test_print_col_person_description
345
+ #should be same as: simple_format(sanitize(auto_link(@person.description)))
346
+ expected = "<p>Billy is an awesome guy.\n<br />However, he is also a punk. <a href=\"http://www.google.com\">www.google.com</a></p>"
347
+ assert_equal "<td class=\"left\">#{expected}</td>", @view.print_col(@person, :mysorter, :description)
348
+ end
349
+
350
+ def test_print_col_dude_description
351
+ #should be same as: simple_format(truncate(@dude.description, 5))
352
+ expected = "<p>Th...</p>"
353
+ assert_equal "<td>#{expected}</td>", @view.print_col(@dude, :dude_report, :description)
354
+ end
355
+
356
+ def test_print_col_person_balance
357
+ assert_equal "<td class=\"right\">£1 234,57</td>", @view.print_col(@person, :mysorter, :balance)
358
+ end
359
+
360
+ def test_print_col_person_age
361
+ assert_equal "<td class=\"center\">24</td>", @view.print_col(@person, :mysorter, :age)
362
+ end
363
+
364
+ def test_print_col_person_firstname
365
+ assert_equal "<td class=\"left\"><a href=\"http://test.host/people/show/#{@person.id}\">Billy</a></td>", @view.print_col(@person, :mysorter, :firstname)
366
+ end
367
+
368
+ def test_print_col_dude_dudename
369
+ assert_equal "<td><a href=\"http://test.host/dudes/#{@dude.id}\">The Dude</a></td>", @view.print_col(@dude, :dude_report, :dudename)
370
+ end
371
+
372
+ def test_print_col_taco_meat
373
+ assert_equal "<td><a href=\"http://test.host/foods/meats/#{@person.id}\">Beef</a></td>", @view.print_col(@person, :tacosorter, :meat)
374
+ end
375
+
376
+ def test_print_col_taco_type
377
+ assert_equal "<td><a href=\"http://www.tacotypes.com\">Soft Shell</a></td>", @view.print_col(@person, :tacosorter, :type)
378
+ end
379
+
380
+ def test_print_col_taco_calories
381
+ #testing if we can have extra parameters in the url
382
+ assert_equal "<td><a href=\"http://test.host/foods/calories?foo=bar\">1200.00</a></td>", @view.print_col(@person, :tacosorter, :calories)
383
+ end
384
+
385
+ def test_print_col_edit
386
+ expected = "<td><a href=\"http://test.host/people/edit/#{@person.id}\">Edit</a></td>"
387
+ assert_equal expected, @view.print_col(@person, :mysorter, :edit)
388
+ end
389
+
390
+ def test_print_col_delete
391
+ expected = "<td><a href=\"http://test.host/people/destroy/1\" onclick=\"if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;\">Delete</a></td>"
392
+ assert_equal expected, @view.print_col(@person, :mysorter, :delete)
393
+ end
394
+
395
+ #---[ Column Headings ]-------------------------------------------------
396
+
397
+ def test_get_url
398
+ @view.params[:controller] = 'cars'
399
+ @view.params[:action] = 'wheels'
400
+ @view.params[:foo] = 'blah'
401
+ @view.params[:bar] = '123'
402
+ @view.params[:order_by] = 'wheel_type'
403
+ @view.params[:dir] = 'desc'
404
+ new_order = 'windshield_strength'
405
+ new_dir = 'asc'
406
+ _params = @view.params
407
+ expected = "http://test.host/cars/wheels?bar=123&dir=asc&foo=blah&order_by=windshield_strength"
408
+ #assert_equal expected, @view.get_url(new_order, new_dir, _params)
409
+ assert_equal expected, @view.get_url(new_order, new_dir)
410
+ end
411
+
412
+ def test_person_heading_firstname
413
+ expected = "<th><a href=\"http://test.host/people?dir=asc&order_by=firstname\">First</a></th>"
414
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
415
+
416
+ #test if controller changes
417
+ @view.params[:controller] = 'blah'
418
+ expected = "<th><a href=\"http://test.host/blah?dir=asc&order_by=firstname\">First</a></th>"
419
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
420
+
421
+ #test if action changes
422
+ @view.params[:action] = 'foo'
423
+ expected = "<th><a href=\"http://test.host/blah/foo?dir=asc&order_by=firstname\">First</a></th>"
424
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
425
+
426
+ #test if sort direction changes
427
+ @view = View.new
428
+ @view.params[:order_by] = 'firstname'
429
+ @view.params[:dir] = 'asc'
430
+ #should switch the direction to descending:
431
+ expected = "<th><a href=\"http://test.host/people?dir=desc&order_by=firstname\">First</a></th>"
432
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
433
+
434
+ #test a url route that has more than just controller and action
435
+ @view = View.new
436
+ @view.params[:controller] = 'foods'
437
+ @view.params[:action] = 'show'
438
+ @view.params[:person_id] = 1
439
+ expected = "<th><a href=\"http://test.host/people/1/foods?dir=asc&order_by=firstname\">First</a></th>"
440
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
441
+ end
442
+
443
+ def test_person_heading_age
444
+ #default direction should be desc
445
+ expected = "<th><a href=\"http://test.host/people?dir=desc&order_by=age\">Age</a></th>"
446
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :age)
447
+ @view.params[:order_by] = 'age'
448
+ @view.params[:dir] = 'desc'
449
+ #back to asc
450
+ expected = "<th><a href=\"http://test.host/people?dir=asc&order_by=age\">Age</a></th>"
451
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :age)
452
+ end
453
+
454
+ def test_person_heading_description
455
+ #not sortable, so no link in heading
456
+ expected = "<th>Description</th>"
457
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :description)
458
+ end
459
+
460
+ def test_taco_heading_meat
461
+ #test order_by sort_option from col_defs
462
+ expected = "<th><a href=\"http://test.host/people?dir=asc&order_by=meats.id\">Meat</a></th>"
463
+ assert_equal expected, @view.print_col_heading(Person, :tacosorter, :meat)
464
+ end
465
+
466
+ def test_person_heading_edit
467
+ expected = "<th class=\"invisible\"></th>"
468
+ assert_equal expected, @view.print_col_heading(Person, :mysorter, :edit)
469
+ end
470
+
471
+ def test_person_print_table_row
472
+ assert_equal @expected_person_row, @view.print_table_row(@person, :mysorter)
473
+ end
474
+
475
+ def test_person_print_table_heading_row
476
+ assert_equal @expected_person_heading_row, @view.print_table_heading_row(Person, :mysorter)
477
+ end
478
+
479
+ def test_person_print_table_thead
480
+ expected = "<thead>#{@expected_person_heading_row}</thead>"
481
+ assert_equal expected, @view.print_table_thead(Person, :mysorter)
482
+ end
483
+
484
+ def test_person_print_table_body
485
+ people = [@person, @person2]
486
+ expected = "<tbody>" + @expected_person_row + @expected_person2_row + "</tbody>"
487
+ assert_equal expected, @view.print_table_body(people, :mysorter)
488
+ end
489
+
490
+ def test_person_print_table
491
+ people = [@person, @person2]
492
+ expected = "<table><thead>#{@expected_person_heading_row}</thead>" +
493
+ "<tbody>" + @expected_person_row + @expected_person2_row + "</tbody></table>"
494
+ assert_equal expected, @view.print_table(people, :mysorter)
495
+
496
+ expected = "<table class=\"yui-skin-sam\" id=\"yui_table\">" +
497
+ "<thead>#{@expected_person_heading_row}</thead>" +
498
+ "<tbody>" + @expected_person_row + @expected_person2_row + "</tbody></table>"
499
+ assert_equal expected, @view.print_table(people, :mysorter,
500
+ {:table => {:class => 'yui-skin-sam', :id => 'yui_table'}})
501
+
502
+ expected = "<table class=\"yui-skin-sam\" id=\"yui_table\">" +
503
+ "<thead>#{@expected_person_heading_row}</thead>" +
504
+ "<tbody>" + @expected_person_row_alternate + @expected_person2_row_alternate +
505
+ "</tbody></table>"
506
+ assert_equal expected, @view.print_table(people, :mysorter,
507
+ :table => {:class => 'yui-skin-sam', :id => 'yui_table'},
508
+ :tr => {:classes => ['even','odd']})
509
+ end
510
+ end