paginated_table 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/lib/paginated_table.rb +1 -0
  2. data/lib/paginated_table/controller_helpers.rb +4 -1
  3. data/lib/paginated_table/page.rb +0 -42
  4. data/lib/paginated_table/railtie.rb +6 -0
  5. data/lib/paginated_table/version.rb +1 -1
  6. data/lib/paginated_table/view_helpers.rb +1 -171
  7. data/test/dummy/app/controllers/data_controller.rb +11 -1
  8. data/test/dummy/app/views/data/_complex.html.erb +17 -0
  9. data/test/dummy/app/views/data/complex.html.erb +1 -0
  10. data/test/dummy/log/test.log +20149 -0
  11. data/test/dummy/tmp/cache/assets/C4B/9C0/sprockets%2Fc5653d450f0e19225c69a8448202901e +0 -0
  12. data/test/dummy/tmp/cache/assets/D1A/4D0/sprockets%2F7766b94fd3771a7e336ee60045f0fc7a +0 -0
  13. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  14. data/test/dummy/tmp/cache/assets/D61/7F0/sprockets%2F13eed08e0333722e08db28efdc037f0c +0 -0
  15. data/test/dummy/tmp/cache/assets/DF7/210/sprockets%2F424c1b802ed6f5c5f23ef0de59dcd0fa +0 -0
  16. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  17. data/test/integration/paginated_table_integration_test.rb +15 -9
  18. data/test/units/column_description_test.rb +97 -0
  19. data/test/units/config_test.rb +2 -0
  20. data/test/units/controller_helpers_test.rb +9 -0
  21. data/test/units/data_page_test.rb +36 -0
  22. data/test/units/link_renderer_test.rb +44 -0
  23. data/test/units/page_params_test.rb +48 -0
  24. data/test/units/page_test.rb +2 -79
  25. data/test/units/row_description_test.rb +71 -0
  26. data/test/units/table_description_test.rb +88 -0
  27. data/test/units/table_renderer_test.rb +234 -0
  28. data/test/units/view_helpers_test.rb +1 -306
  29. metadata +30 -4
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+
3
+ module PaginatedTable
4
+ describe TableDescription do
5
+ let(:description) { TableDescription.new }
6
+
7
+ describe "#column" do
8
+ let(:row) { row = stub("row", :column => nil) }
9
+
10
+ before do
11
+ RowDescription.stubs(:new).returns(row)
12
+ end
13
+
14
+ describe "when first called in a table description" do
15
+ it "creates a new row" do
16
+ description.column
17
+ description.rows.must_equal [row]
18
+ end
19
+
20
+ it "calls column on the row" do
21
+ args = [stub("arg1"), stub("arg2")]
22
+ row.expects(:column).with(*args)
23
+ description.column(*args)
24
+ end
25
+ end
26
+
27
+ describe "when subsequently called in a table description" do
28
+ before do
29
+ description.column
30
+ end
31
+
32
+ it "does not create a new row" do
33
+ description.expects(:row).never
34
+ description.column
35
+ end
36
+
37
+ it "calls column on the default row" do
38
+ args = [stub("arg1"), stub("arg2")]
39
+ row.expects(:column).with(*args)
40
+ description.column(*args)
41
+ end
42
+ end
43
+
44
+ describe "when called after row has been called by a table description" do
45
+ before do
46
+ description.row
47
+ end
48
+
49
+ it "raises TableDescription::Invalid" do
50
+ lambda { description.column }.must_raise TableDescription::Invalid
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ describe "#row" do
57
+ it "constructs a new RowDescription and appends it to the rows array" do
58
+ row = stub("row")
59
+ options = stub("options")
60
+ RowDescription.stubs(:new).with(description, options, nil).returns(row)
61
+ description.row(options)
62
+ description.rows.must_equal [row]
63
+ end
64
+ end
65
+
66
+ describe "#colspan" do
67
+ before do
68
+ description.row do |row|
69
+ row.column 'foo'
70
+ row.column 'bar'
71
+ end
72
+ description.row do |row|
73
+ row.column 'foo'
74
+ row.column 'bar'
75
+ row.column 'baz'
76
+ end
77
+ end
78
+
79
+ it "returns the maximum number of columns in a row as a string for :all" do
80
+ description.colspan(:all).must_equal '3'
81
+ end
82
+
83
+ it "returns ArgumentError otherwise" do
84
+ lambda { description.colspan(:foo) }.must_raise ArgumentError
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,234 @@
1
+ require 'test_helper'
2
+
3
+ module PaginatedTable
4
+ describe TableRenderer do
5
+ let(:view) { stub("view") }
6
+ let(:description) { stub("description") }
7
+ let(:data) { stub("data") }
8
+ let(:page) { stub("page", :sort_column => 'title', :sort_direction => 'asc') }
9
+ let(:data_page) { stub("data_page", :data => data, :page => page) }
10
+ let(:link_renderer) { stub("link_renderer") }
11
+ let(:table) { TableRenderer.new(view, description, data_page, link_renderer) }
12
+
13
+ describe "#initialize" do
14
+ it "creates a new instance with the view, description, and data_page" do
15
+ table
16
+ end
17
+ end
18
+
19
+ describe "#render" do
20
+ it "makes a div.paginated_table with the table and a pagination header and footer" do
21
+ table.stubs(:render_pagination_area).returns("<pagination/>")
22
+ table.stubs(:render_table).returns("<table/>")
23
+ view.expects(:content_tag).with('div', "<pagination/><table/><pagination/>", :class => 'paginated_table')
24
+ table.render
25
+ end
26
+ end
27
+
28
+ describe "#render_pagination_area" do
29
+ it "makes a div.header with the pagination info and links" do
30
+ table.stubs(:render_pagination_info).returns("<info/>")
31
+ table.stubs(:render_pagination_links).returns("<links/>")
32
+ view.expects(:content_tag).with('div', "<info/><links/>", :class => 'header')
33
+ table.render_pagination_area
34
+ end
35
+ end
36
+
37
+ describe "#render_pagination_info" do
38
+ it "makes a div.info with the page_entries_info from will_paginate" do
39
+ view.stubs(:page_entries_info).with(data).returns("<info/>")
40
+ view.expects(:content_tag).with('div', "<info/>", :class => 'info')
41
+ table.render_pagination_info
42
+ end
43
+ end
44
+
45
+ describe "#render_pagination_links" do
46
+ it "makes a div.links with the will_paginate links from will_paginate" do
47
+ view.stubs(:will_paginate).
48
+ with(data, :renderer => link_renderer).
49
+ returns("<links/>")
50
+ view.expects(:content_tag).with('div', "<links/>", :class => 'links')
51
+ table.render_pagination_links
52
+ end
53
+ end
54
+
55
+ describe "#render_table" do
56
+ it "makes a table.paginated with the table header and body" do
57
+ table.stubs(:render_table_header).returns("<header/>")
58
+ table.stubs(:render_table_body).returns("<body/>")
59
+ view.expects(:content_tag).with('table', "<header/><body/>", :class => 'paginated')
60
+ table.render_table
61
+ end
62
+ end
63
+
64
+ describe "#render_table_header" do
65
+ it "makes a thead with the table header rows" do
66
+ table.stubs(:render_table_header_rows).returns("<header/>")
67
+ view.expects(:content_tag).with('thead', "<header/>")
68
+ table.render_table_header
69
+ end
70
+ end
71
+
72
+ describe "#render_table_header_rows" do
73
+ it "concatenates the table headers for the rows with :header titles" do
74
+ rows = [
75
+ stub("row", :title => :header),
76
+ stub("row", :title => false),
77
+ stub("row", :title => :header)
78
+ ]
79
+ description.stubs(:rows).returns(rows)
80
+ table.stubs(:render_table_header_row).with(rows.first).returns("<row1/>")
81
+ table.stubs(:render_table_header_row).with(rows.last).returns("<row2/>")
82
+ table.render_table_header_rows.must_equal "<row1/><row2/>"
83
+ end
84
+ end
85
+
86
+ describe "#render_table_header_row" do
87
+ it "makes a tr with th columns" do
88
+ columns = [stub("column1"), stub("column2")]
89
+ row = stub("row", :columns => columns)
90
+ table.stubs(:render_table_header_column).with(columns.first).returns("<col1/>")
91
+ table.stubs(:render_table_header_column).with(columns.last).returns("<col2/>")
92
+ view.expects(:content_tag).with('tr', "<col1/><col2/>")
93
+ table.render_table_header_row(row)
94
+ end
95
+ end
96
+
97
+ describe "#render_table_header_column" do
98
+ it "makes a th with the render_header from the column" do
99
+ column = stub("column", :name => 'foo', :sortable? => false)
100
+ table.stubs(:render_table_header_column_content).with(column).returns("<header/>")
101
+ view.expects(:content_tag).with('th', "<header/>", {})
102
+ table.render_table_header_column(column)
103
+ end
104
+
105
+ describe "when the table is sorted on the column ascending" do
106
+ it "makes a th with css class 'sortable sorted_asc'" do
107
+ column = stub("column", :name => 'title', :sortable? => true)
108
+ table.stubs(:render_table_header_column_content).with(column).returns("<header/>")
109
+ view.expects(:content_tag).
110
+ with('th', "<header/>", :class => 'sortable sorted_asc')
111
+ table.render_table_header_column(column)
112
+ end
113
+ end
114
+
115
+ describe "when the table is sorted on the column descending" do
116
+ it "makes a th with css class 'sortable sorted_asc'" do
117
+ column = stub("column", :name => 'title', :sortable? => true)
118
+ page.stubs(:sort_direction => 'desc')
119
+ table.stubs(:render_table_header_column_content).with(column).returns("<header/>")
120
+ view.expects(:content_tag).
121
+ with('th', "<header/>", :class => 'sortable sorted_desc')
122
+ table.render_table_header_column(column)
123
+ end
124
+ end
125
+ end
126
+
127
+ describe "#render_table_header_column_content" do
128
+ describe "with a sortable column" do
129
+ let(:column) { stub("column", :name => :foo, :render_header => '<header/>', :sortable? => true) }
130
+
131
+ it "asks the link renderer to render a link to sort the column" do
132
+ result = stub("result")
133
+ link_renderer.stubs(:sort_link).with("<header/>", 'foo').returns(result)
134
+ table.render_table_header_column_content(column).must_equal result
135
+ end
136
+ end
137
+
138
+ describe "with an unsortable column" do
139
+ let(:column) { stub("column", :render_header => '<header/>', :sortable? => false) }
140
+
141
+ it "simply renders the column's header" do
142
+ table.render_table_header_column_content(column).must_equal '<header/>'
143
+ end
144
+ end
145
+ end
146
+
147
+ describe "#render_table_body" do
148
+ it "makes a tbody with the table body rows" do
149
+ data = [stub("datum1"), stub("datum2")]
150
+ data_page = stub("data_page", :data => data)
151
+ table = TableRenderer.new(view, description, data_page, link_renderer)
152
+ table.stubs(:render_table_body_rows).with(data.first).returns("<row1/>")
153
+ table.stubs(:render_table_body_rows).with(data.last).returns("<row2/>")
154
+ view.expects(:content_tag).with('tbody', "<row1/><row2/>")
155
+ table.render_table_body
156
+ end
157
+ end
158
+
159
+ describe "#render_table_body_rows" do
160
+ it "concatenates the interleaved table body rows for the rows" do
161
+ datum = stub("datum")
162
+ rows = [stub("row"), stub("row")]
163
+ description.stubs(:rows).returns(rows)
164
+ table.stubs(:render_table_body_row).with(rows.first, datum).returns("1")
165
+ table.stubs(:render_table_body_row).with(rows.last, datum).returns("2")
166
+ table.render_table_body_rows(datum).must_equal "12"
167
+ end
168
+ end
169
+
170
+ describe "#render_table_body_row" do
171
+ let(:datum) { stub("datum") }
172
+ let(:columns) { [stub("column1"), stub("column2")] }
173
+ let(:dom_id) { stub("dom_id") }
174
+ let(:row) {
175
+ stub("row", :columns => columns, :cycle => false, :hidden => false,
176
+ :data_type => false
177
+ )
178
+ }
179
+ before do
180
+ view.stubs(:dom_id).with(datum).returns(dom_id)
181
+ table.stubs(:render_table_body_cell).
182
+ with(datum, columns.first).returns("<cell1/>")
183
+ table.stubs(:render_table_body_cell).
184
+ with(datum, columns.last).returns("<cell2/>")
185
+ end
186
+
187
+ it "makes a tr with the table body cells" do
188
+ view.expects(:content_tag).
189
+ with('tr', "<cell1/><cell2/>", :"data-datum-id" => dom_id)
190
+ table.render_table_body_row(row, datum)
191
+ end
192
+
193
+ it "makes a tr with a css cycle for cycle rows" do
194
+ css = stub("css")
195
+ view.stubs(:cycle).with('foo', 'bar').returns(css)
196
+ row.stubs(:cycle => %w(foo bar))
197
+ view.expects(:content_tag).
198
+ with('tr', "<cell1/><cell2/>", :class => css, :"data-datum-id" => dom_id)
199
+ table.render_table_body_row(row, datum)
200
+ end
201
+
202
+ it "makes a tr with css style display: none for hidden rows" do
203
+ row.stubs(:hidden => true)
204
+ view.expects(:content_tag).
205
+ with('tr', "<cell1/><cell2/>",
206
+ :style => 'display: none', :"data-datum-id" => dom_id
207
+ )
208
+ table.render_table_body_row(row, datum)
209
+ end
210
+
211
+ it "makes a tr with a data-type attribute for data_type rows" do
212
+ data_type = stub("data_type")
213
+ row.stubs(:data_type => data_type)
214
+ view.expects(:content_tag).
215
+ with('tr', "<cell1/><cell2/>",
216
+ :"data-datum-id" => dom_id, :"data-type" => data_type
217
+ )
218
+ table.render_table_body_row(row, datum)
219
+ end
220
+ end
221
+
222
+ describe "#render_table_body_cell" do
223
+ it "makes a td with the render_cell from the column" do
224
+ datum = stub("datum")
225
+ column = stub("column")
226
+ column.stubs(:render_cell).with(datum).returns("<datum/>")
227
+ attributes = stub("attributes")
228
+ column.stubs(:html_attributes).with().returns(attributes)
229
+ view.expects(:content_tag).with('td', "<datum/>", attributes)
230
+ table.render_table_body_cell(datum, column)
231
+ end
232
+ end
233
+ end
234
+ end
@@ -20,7 +20,7 @@ module PaginatedTable
20
20
  link_renderer = stub("link_renderer")
21
21
  LinkRenderer.stubs("new").with(page).returns(link_renderer)
22
22
  table_renderer = stub("table_renderer")
23
- RendersTable.stubs("new").
23
+ TableRenderer.stubs("new").
24
24
  with(view, table_description, data_page, link_renderer).
25
25
  returns(table_renderer)
26
26
  table_renderer.expects("render")
@@ -28,309 +28,4 @@ module PaginatedTable
28
28
  end
29
29
  end
30
30
  end
31
-
32
- describe TableDescription do
33
- describe "#initialize" do
34
- it "creates a new instance with empty columns" do
35
- TableDescription.new.columns.must_equal []
36
- end
37
-
38
- it "calls the given block with itself" do
39
- fake_proc = stub("proc")
40
- fake_proc.expects(:call)
41
- TableDescription.new(fake_proc)
42
- end
43
- end
44
-
45
- describe "#column" do
46
- it "constructs a new Column and appends it to the columns array" do
47
- column = stub("column")
48
- TableDescription::Column.stubs(:new).with(:foo).returns(column)
49
- description = TableDescription.new
50
- description.column(:foo)
51
- description.columns.must_equal [column]
52
- end
53
- end
54
- end
55
-
56
- describe TableDescription::Column do
57
- describe "#initialize" do
58
- it "creates a new instance with a name and an optional block" do
59
- TableDescription::Column.new(:foo) { true }
60
- end
61
-
62
- it "accepts an options hash" do
63
- TableDescription::Column.new(:foo, :baz => 'bat')
64
- end
65
- end
66
-
67
- describe "#sortable?" do
68
- it "returns true by default" do
69
- TableDescription::Column.new(:foo).sortable?.must_equal true
70
- end
71
-
72
- it "returns false if the :sortable option is false" do
73
- TableDescription::Column.new(:foo, :sortable => false).sortable?.must_equal false
74
- end
75
- end
76
-
77
- describe "#html_attributes" do
78
- it "returns an empty hash by default" do
79
- TableDescription::Column.new(:foo).html_attributes.must_equal({})
80
- end
81
-
82
- it "adds the css classes given by the :class option" do
83
- TableDescription::Column.new(:foo, :class => %w(bar baz)).
84
- html_attributes.must_equal({ :class => 'bar baz' })
85
- end
86
-
87
- it "adds the css styles given by the :style option" do
88
- TableDescription::Column.new(:foo, :style => 'font-face: bold').
89
- html_attributes.must_equal({ :style => 'font-face: bold' })
90
- end
91
- end
92
-
93
- describe "#render_header" do
94
- it "returns the titleized name" do
95
- TableDescription::Column.new(:foo).render_header.must_equal "Foo"
96
- end
97
-
98
- it "returns the :title option if given" do
99
- TableDescription::Column.new(:foo, :title => 'bar').
100
- render_header.must_equal "bar"
101
- end
102
- end
103
-
104
- describe "#render_cell" do
105
- let(:results) { stub("results") }
106
-
107
- describe "on a column with no block" do
108
- let(:column) { TableDescription::Column.new(:foo) }
109
-
110
- it "sends its name to the datum" do
111
- datum = stub("datum", :foo => results)
112
- column.render_cell(datum).must_equal results
113
- end
114
- end
115
-
116
- describe "on a column with a block" do
117
- it "calls its block with the datum" do
118
- datum = stub("datum")
119
- column = TableDescription::Column.new(:foo) do |block_arg|
120
- results if block_arg == datum
121
- end
122
- column.render_cell(datum).must_equal results
123
- end
124
- end
125
- end
126
- end
127
-
128
- describe LinkRenderer do
129
- let(:page) { Page.new(:number => 2, :rows => 5, :sort_column => 'to_s', :sort_direction => 'desc') }
130
- let(:data) { (1..10).to_a }
131
- let(:data_page) { data.paginate(:page => 2, :per_page => 5) }
132
- let(:view) { stub("view") }
133
- let(:renderer) do
134
- renderer = LinkRenderer.new(page)
135
- renderer.prepare(data, {}, view)
136
- renderer
137
- end
138
- let(:text) { stub("text") }
139
- let(:href) { stub("href") }
140
- let(:link) { stub("link") }
141
-
142
-
143
- describe "#sort_link" do
144
- it "calls link_to on the view with the sort url and the :remote option" do
145
- view.stubs("url_for").
146
- with(:sort_direction => 'asc', :per_page => '5', :page => '1', :sort_column => 'to_s').
147
- returns(href)
148
- view.stubs("link_to").with(text, href, :remote => true).returns(link)
149
- renderer.sort_link(text, 'to_s').must_equal link
150
- end
151
- end
152
-
153
- describe "#tag" do
154
- it "calls link_to on the view with the :remote option for :a tags" do
155
- html_safe_text = stub("html_safe_text")
156
- text = stub("text", :to_s => stub("string", :html_safe => html_safe_text))
157
- view.expects(:link_to).
158
- with(html_safe_text, href, { :class => 'highlight', :remote => true }).
159
- returns(link)
160
- renderer.tag(:a, text, :class => 'highlight', :href => href).must_equal link
161
- end
162
-
163
- it "delegates to its parent for all other tags" do
164
- view.expects(:link_to).never
165
- renderer.tag(:span, "foo")
166
- end
167
- end
168
-
169
- end
170
-
171
- describe RendersTable do
172
- let(:view) { stub("view") }
173
- let(:description) { stub("description") }
174
- let(:data) { stub("data") }
175
- let(:page) { stub("page", :sort_column => 'title', :sort_direction => 'asc') }
176
- let(:data_page) { stub("data_page", :data => data, :page => page) }
177
- let(:link_renderer) { stub("link_renderer") }
178
- let(:table) { RendersTable.new(view, description, data_page, link_renderer) }
179
-
180
- describe "#initialize" do
181
- it "creates a new instance with the view, description, and data_page" do
182
- table
183
- end
184
- end
185
-
186
- describe "#render" do
187
- it "makes a div.paginated_table with the table and a pagination header and footer" do
188
- table.stubs(:render_pagination_area).returns("<pagination/>")
189
- table.stubs(:render_table).returns("<table/>")
190
- view.expects(:content_tag).with('div', "<pagination/><table/><pagination/>", :class => 'paginated_table')
191
- table.render
192
- end
193
- end
194
-
195
- describe "#render_pagination_area" do
196
- it "makes a div.header with the pagination info and links" do
197
- table.stubs(:render_pagination_info).returns("<info/>")
198
- table.stubs(:render_pagination_links).returns("<links/>")
199
- view.expects(:content_tag).with('div', "<info/><links/>", :class => 'header')
200
- table.render_pagination_area
201
- end
202
- end
203
-
204
- describe "#render_pagination_info" do
205
- it "makes a div.info with the page_entries_info from will_paginate" do
206
- view.stubs(:page_entries_info).with(data).returns("<info/>")
207
- view.expects(:content_tag).with('div', "<info/>", :class => 'info')
208
- table.render_pagination_info
209
- end
210
- end
211
-
212
- describe "#render_pagination_links" do
213
- it "makes a div.links with the will_paginate links from will_paginate" do
214
- view.stubs(:will_paginate).
215
- with(data, :renderer => link_renderer).
216
- returns("<links/>")
217
- view.expects(:content_tag).with('div', "<links/>", :class => 'links')
218
- table.render_pagination_links
219
- end
220
- end
221
-
222
- describe "#render_table" do
223
- it "makes a table.paginated with the table header and body" do
224
- table.stubs(:render_table_header).returns("<header/>")
225
- table.stubs(:render_table_body).returns("<body/>")
226
- view.expects(:content_tag).with('table', "<header/><body/>", :class => 'paginated')
227
- table.render_table
228
- end
229
- end
230
-
231
- describe "#render_table_header" do
232
- it "makes a thead with the table header row" do
233
- table.stubs(:render_table_header_row).returns("<header/>")
234
- view.expects(:content_tag).with('thead', "<header/>")
235
- table.render_table_header
236
- end
237
- end
238
-
239
- describe "#render_table_header_row" do
240
- it "makes a tr with the table header columns" do
241
- columns = [stub("column1"), stub("column2")]
242
- description.stubs(:columns).returns(columns)
243
- table.stubs(:render_table_header_column).with(columns.first).returns("<col1/>")
244
- table.stubs(:render_table_header_column).with(columns.last).returns("<col2/>")
245
- view.expects(:content_tag).with('tr', "<col1/><col2/>")
246
- table.render_table_header_row
247
- end
248
- end
249
-
250
- describe "#render_table_header_column" do
251
- it "makes a th with the render_header from the column" do
252
- column = stub("column", :name => 'foo', :sortable? => false)
253
- table.stubs(:render_table_header_column_content).with(column).returns("<header/>")
254
- view.expects(:content_tag).with('th', "<header/>", {})
255
- table.render_table_header_column(column)
256
- end
257
-
258
- describe "when the table is sorted on the column ascending" do
259
- it "makes a th with css class 'sortable sorted_asc'" do
260
- column = stub("column", :name => 'title', :sortable? => true)
261
- table.stubs(:render_table_header_column_content).with(column).returns("<header/>")
262
- view.expects(:content_tag).
263
- with('th', "<header/>", :class => 'sortable sorted_asc')
264
- table.render_table_header_column(column)
265
- end
266
- end
267
-
268
- describe "when the table is sorted on the column descending" do
269
- it "makes a th with css class 'sortable sorted_asc'" do
270
- column = stub("column", :name => 'title', :sortable? => true)
271
- page.stubs(:sort_direction => 'desc')
272
- table.stubs(:render_table_header_column_content).with(column).returns("<header/>")
273
- view.expects(:content_tag).
274
- with('th', "<header/>", :class => 'sortable sorted_desc')
275
- table.render_table_header_column(column)
276
- end
277
- end
278
- end
279
-
280
- describe "#render_table_header_column_content" do
281
- describe "with a sortable column" do
282
- let(:column) { stub("column", :name => :foo, :render_header => '<header/>', :sortable? => true) }
283
-
284
- it "asks the link renderer to render a link to sort the column" do
285
- result = stub("result")
286
- link_renderer.stubs(:sort_link).with("<header/>", 'foo').returns(result)
287
- table.render_table_header_column_content(column).must_equal result
288
- end
289
- end
290
-
291
- describe "with an unsortable column" do
292
- let(:column) { stub("column", :render_header => '<header/>', :sortable? => false) }
293
-
294
- it "simply renders the column's header" do
295
- table.render_table_header_column_content(column).must_equal '<header/>'
296
- end
297
- end
298
- end
299
-
300
- describe "#render_table_body" do
301
- it "makes a tbody with the table body rows" do
302
- data = [stub("datum1"), stub("datum2")]
303
- data_page = stub("data_page", :data => data)
304
- table = RendersTable.new(view, description, data_page, link_renderer)
305
- table.stubs(:render_table_body_row).with(data.first).returns("<row1/>")
306
- table.stubs(:render_table_body_row).with(data.last).returns("<row2/>")
307
- view.expects(:content_tag).with('tbody', "<row1/><row2/>")
308
- table.render_table_body
309
- end
310
- end
311
-
312
- describe "#render_table_body_row" do
313
- it "makes a tr with the table body cells" do
314
- datum = stub("datum")
315
- columns = [stub("column1"), stub("column2")]
316
- description.stubs(:columns).returns(columns)
317
- table.stubs(:render_table_body_cell).with(datum, columns.first).returns("<cell1/>")
318
- table.stubs(:render_table_body_cell).with(datum, columns.last).returns("<cell2/>")
319
- view.expects(:content_tag).with('tr', "<cell1/><cell2/>")
320
- table.render_table_body_row(datum)
321
- end
322
- end
323
-
324
- describe "#render_table_body_cell" do
325
- it "makes a td with the render_cell from the column" do
326
- datum = stub("datum")
327
- column = stub("column")
328
- column.stubs(:render_cell).with(datum).returns("<datum/>")
329
- attributes = stub("attributes")
330
- column.stubs(:html_attributes).with().returns(attributes)
331
- view.expects(:content_tag).with('td', "<datum/>", attributes)
332
- table.render_table_body_cell(datum, column)
333
- end
334
- end
335
- end
336
31
  end