hirb 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -2
- data/Rakefile +23 -41
- data/gemspec +20 -0
- data/lib/bond/completions/hirb.rb +14 -0
- data/lib/hirb.rb +0 -3
- data/lib/hirb/helpers/table.rb +1 -1
- data/lib/hirb/version.rb +1 -1
- data/test/auto_table_test.rb +25 -27
- data/test/bacon_extensions.rb +26 -0
- data/test/console_test.rb +7 -9
- data/test/dynamic_view_test.rb +71 -77
- data/test/formatter_test.rb +39 -37
- data/test/hirb_test.rb +8 -8
- data/test/import_test.rb +4 -4
- data/test/menu_test.rb +42 -42
- data/test/object_table_test.rb +65 -67
- data/test/pager_test.rb +133 -135
- data/test/resizer_test.rb +48 -47
- data/test/table_test.rb +69 -70
- data/test/test_helper.rb +11 -7
- data/test/tree_test.rb +34 -46
- data/test/util_test.rb +57 -59
- data/test/view_test.rb +138 -140
- data/test/views_test.rb +8 -10
- metadata +66 -36
data/test/resizer_test.rb
CHANGED
@@ -1,61 +1,62 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
describe "Resizer" do
|
4
|
+
def table(options)
|
5
|
+
@table = Helpers::Table.new [options[:field_lengths].keys.inject({}) {|t,e| t[e] = '1'; t}]
|
6
|
+
@table.field_lengths = options[:field_lengths]
|
7
|
+
@table.width = options[:width]
|
8
|
+
@table.max_fields = options[:max_fields] if options[:max_fields]
|
9
|
+
@width, @field_lengths = @table.width, @table.field_lengths
|
10
|
+
@table
|
11
|
+
end
|
12
|
+
|
13
|
+
it "resize ensures columns total doesn't exceed max width" do
|
14
|
+
table :field_lengths=>{:f1=>135, :f2=>45, :f3=>4, :f4=>55}, :width=>195
|
15
|
+
Helpers::Table::Resizer.resize!(@table)
|
16
|
+
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
17
|
+
end
|
18
|
+
|
19
|
+
it "resize sets columns by relative lengths" do
|
20
|
+
table :field_lengths=>{:a=>30, :b=>30, :c=>40}, :width=>60
|
21
|
+
Helpers::Table::Resizer.resize!(@table)
|
22
|
+
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
23
|
+
@field_lengths.values.uniq.size.should.not == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "resize sets all columns roughly equal when adusting long fields don't work" do
|
27
|
+
table :field_lengths=>{:field1=>10, :field2=>15, :field3=>100}, :width=>20
|
28
|
+
Helpers::Table::Resizer.resize!(@table)
|
29
|
+
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
30
|
+
@field_lengths.values.each {|e| e.should <= 4 }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "add_extra_width and max_fields" do
|
34
|
+
def table_and_resize(options={})
|
35
|
+
defaults = {:field_lengths=>{:f1=>135, :f2=>30, :f3=>4, :f4=>100}, :width=>195, :max_fields=>{:f1=>80, :f4=>30} }
|
36
|
+
@table = table defaults.merge(options)
|
37
|
+
# repeated from table since instance variables aren't copied b/n contexts
|
10
38
|
@width, @field_lengths = @table.width, @table.field_lengths
|
39
|
+
Helpers::Table::Resizer.resize! @table
|
11
40
|
end
|
12
41
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
42
|
+
it "doesn't add to already maxed out field" do
|
43
|
+
table_and_resize
|
44
|
+
@field_lengths[:f3].should == 4
|
17
45
|
end
|
18
46
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
23
|
-
@field_lengths.values.uniq.size.should_not == 1
|
47
|
+
it "restricted before adding width" do
|
48
|
+
table_and_resize
|
49
|
+
@field_lengths[:f4].should <= 30
|
24
50
|
end
|
25
51
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@field_lengths.values.inject {|a,e| a+=e}.should <= @width
|
30
|
-
@field_lengths.values.each {|e| e.should <= 4 }
|
52
|
+
it "adds to restricted field" do
|
53
|
+
table_and_resize
|
54
|
+
@field_lengths[:f1].should <= 80
|
31
55
|
end
|
32
56
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
table defaults.merge(options)
|
37
|
-
Resizer.resize! @table
|
38
|
-
end
|
39
|
-
|
40
|
-
test "doesn't add to already maxed out field" do
|
41
|
-
table_and_resize
|
42
|
-
@field_lengths[:f3].should == 4
|
43
|
-
end
|
44
|
-
|
45
|
-
test "restricted before adding width" do
|
46
|
-
table_and_resize
|
47
|
-
@field_lengths[:f4].should <= 30
|
48
|
-
end
|
49
|
-
|
50
|
-
test "adds to restricted field" do
|
51
|
-
table_and_resize
|
52
|
-
@field_lengths[:f1].should <= 80
|
53
|
-
end
|
54
|
-
|
55
|
-
test "adds to unrestricted field" do
|
56
|
-
table_and_resize :field_lengths=>{:f1=>135, :f2=>70, :f3=>4, :f4=>100}
|
57
|
-
@field_lengths[:f2].should == 70
|
58
|
-
end
|
57
|
+
it "adds to unrestricted field" do
|
58
|
+
table_and_resize :field_lengths=>{:f1=>135, :f2=>70, :f3=>4, :f4=>100}
|
59
|
+
@field_lengths[:f2].should == 70
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
data/test/table_test.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
3
|
|
3
|
-
|
4
|
+
describe "Table" do
|
4
5
|
def table(*args)
|
5
|
-
|
6
|
+
Helpers::Table.render(*args)
|
6
7
|
end
|
7
|
-
|
8
|
+
before_all { reset_config }
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
describe "basic table" do
|
11
|
+
it "renders" do
|
11
12
|
expected_table = <<-TABLE.unindent
|
12
13
|
+---+---+
|
13
14
|
| a | b |
|
@@ -20,7 +21,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
20
21
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}]).should == expected_table
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
it "with no headers renders" do
|
24
25
|
expected_table = <<-TABLE.unindent
|
25
26
|
+---+---+
|
26
27
|
| 1 | 2 |
|
@@ -30,7 +31,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
30
31
|
table([{:a=>1, :b=>2}], :headers=>false).should == expected_table
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
+
it "with no headers and nil fields renders" do
|
34
35
|
expected_table = <<-TABLE.unindent
|
35
36
|
+---+---+
|
36
37
|
| 1 | |
|
@@ -40,7 +41,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
40
41
|
table([{:a=>1, :b=>nil}], :headers=>false).should == expected_table
|
41
42
|
end
|
42
43
|
|
43
|
-
|
44
|
+
it "with string keys renders" do
|
44
45
|
expected_table = <<-TABLE.unindent
|
45
46
|
+---+---+
|
46
47
|
| a | b |
|
@@ -53,7 +54,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
53
54
|
table([{'a'=>1, 'b'=>2}, {'a'=>3, 'b'=>4}]).should == expected_table
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
|
+
it "with array only rows renders" do
|
57
58
|
expected_table = <<-TABLE.unindent
|
58
59
|
+---+---+
|
59
60
|
| 0 | 1 |
|
@@ -66,21 +67,21 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
66
67
|
table([[1,2], [3,4]]).should == expected_table
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
+
it "with too many fields defaults to vertical table" do
|
70
71
|
rows = [Array.new(25, "A"* 10)]
|
71
|
-
|
72
|
+
Helpers::VerticalTable.expects(:render).with(rows, anything)
|
72
73
|
capture_stderr { table(rows)}.should =~ /Error/
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
+
it "with no rows renders" do
|
76
77
|
table([]).should == "0 rows in set"
|
77
78
|
end
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
it "with invalid rows raises an argumenterror" do
|
81
|
+
lambda { table(:a=>1) }.should.raise(ArgumentError).message.should =~ /Table must/
|
81
82
|
end
|
82
83
|
|
83
|
-
|
84
|
+
it "renders utf8" do
|
84
85
|
expected_table = <<-TABLE.unindent
|
85
86
|
+--------------------+
|
86
87
|
| name |
|
@@ -95,7 +96,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
95
96
|
table([{:name=>"アイウエオカキ"}, {:name=>"クケコサシスセソタチツテ"}, {:name=>"Tata l'asticote"}, {:name=>"toto létoile PAOLI"}]).should == expected_table
|
96
97
|
end
|
97
98
|
|
98
|
-
|
99
|
+
it "stringifies newlines and tabs and renders" do
|
99
100
|
expected_table = <<-TABLE.unindent
|
100
101
|
+-----+---+
|
101
102
|
| a | b |
|
@@ -110,35 +111,34 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
110
111
|
value.should == [{'a'=>"1\n", 'b'=>2}, {'a'=>"3\t", 'b'=>4}]
|
111
112
|
end
|
112
113
|
|
113
|
-
|
114
|
+
it "with a field of only array values renders values comma joined" do
|
114
115
|
expected_table = <<-TABLE.unindent
|
115
116
|
+----+------+
|
116
117
|
| a | b |
|
117
118
|
+----+------+
|
118
|
-
|
|
119
|
+
| 1 | 1, 2 |
|
119
120
|
| ok | 3, 4 |
|
120
121
|
+----+------+
|
121
122
|
2 rows in set
|
122
123
|
TABLE
|
123
|
-
|
124
|
-
table([{:a=>[1,2], :b=>[1,2]}, {:a=>'ok', :b=>[3,4]}]).should == expected_table
|
124
|
+
table([{:a=>1, :b=>[1,2]}, {:a=>'ok', :b=>[3,4]}]).should == expected_table
|
125
125
|
end
|
126
126
|
|
127
|
-
|
127
|
+
it "with filter class default doesn't override explicit filters" do
|
128
128
|
expected_table = <<-TABLE.unindent
|
129
129
|
+------+-------+
|
130
130
|
| name | value |
|
131
131
|
+------+-------+
|
132
|
-
| a |
|
132
|
+
| a | 1 |
|
133
133
|
+------+-------+
|
134
134
|
1 row in set
|
135
135
|
TABLE
|
136
|
-
table([{:name=>'a', :value=>{:b=>1}}], :filters=>{:value=>:
|
136
|
+
table([{:name=>'a', :value=>{:b=>1}}], :filters=>{:value=>:size}).should == expected_table
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
|
141
|
-
|
140
|
+
describe "table with" do
|
141
|
+
it "fields option renders" do
|
142
142
|
expected_table = <<-TABLE.unindent
|
143
143
|
+---+---+
|
144
144
|
| b | a |
|
@@ -151,7 +151,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
151
151
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :fields=>[:b, :a]).should == expected_table
|
152
152
|
end
|
153
153
|
|
154
|
-
|
154
|
+
it "fields option and array only rows" do
|
155
155
|
expected_table = <<-TABLE.unindent
|
156
156
|
+---+---+
|
157
157
|
| 0 | 2 |
|
@@ -163,13 +163,13 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
163
163
|
table([[1,2,3]], :fields=>[0,2]).should == expected_table
|
164
164
|
end
|
165
165
|
|
166
|
-
|
166
|
+
it "fields and number options copies fields option and does not modify it" do
|
167
167
|
options = {:fields=>[:f1], :number=>true}
|
168
168
|
table([{:f1=>1, :f2=>2}], options)
|
169
169
|
options[:fields].should == [:f1]
|
170
170
|
end
|
171
171
|
|
172
|
-
|
172
|
+
it "invalid fields option renders empty columns" do
|
173
173
|
expected_table = <<-TABLE.unindent
|
174
174
|
+---+---+
|
175
175
|
| b | c |
|
@@ -182,7 +182,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
182
182
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :fields=>[:b, :c]).should == expected_table
|
183
183
|
end
|
184
184
|
|
185
|
-
|
185
|
+
it "invalid field in max_fields option renders" do
|
186
186
|
expected_table = <<-TABLE.unindent
|
187
187
|
+------------+---+
|
188
188
|
| a | b |
|
@@ -194,7 +194,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
194
194
|
table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>10,:c=>10}).should == expected_table
|
195
195
|
end
|
196
196
|
|
197
|
-
|
197
|
+
it "max_fields option with fields less than 3 characters renders" do
|
198
198
|
expected_table = <<-TABLE.unindent
|
199
199
|
+----+---+
|
200
200
|
| a | b |
|
@@ -206,7 +206,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
206
206
|
table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>2}, :resize=>false).should == expected_table
|
207
207
|
end
|
208
208
|
|
209
|
-
|
209
|
+
it "max_fields option without resize renders" do
|
210
210
|
expected_table = <<-TABLE.unindent
|
211
211
|
+------------+---+
|
212
212
|
| a | b |
|
@@ -218,7 +218,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
218
218
|
table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>10}, :resize=>false).should == expected_table
|
219
219
|
end
|
220
220
|
|
221
|
-
|
221
|
+
it "max_fields option with percentage renders" do
|
222
222
|
expected_table = <<-TABLE.unindent
|
223
223
|
+------------------+---+
|
224
224
|
| a | b |
|
@@ -230,7 +230,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
230
230
|
table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>'0.15'}).should == expected_table
|
231
231
|
end
|
232
232
|
|
233
|
-
|
233
|
+
it "max_width option renders" do
|
234
234
|
expected_table = <<-TABLE.unindent
|
235
235
|
+-----------+---+------------+
|
236
236
|
| a | b | c |
|
@@ -242,7 +242,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
242
242
|
table([{:a=> "A" * 50, :b=>2, :c=>"C"*10}], :max_width=>30).should == expected_table
|
243
243
|
end
|
244
244
|
|
245
|
-
|
245
|
+
it "resize option false renders full table" do
|
246
246
|
expected_table = <<-TABLE.unindent
|
247
247
|
+----------------------------------------------------+---+------------+
|
248
248
|
| a | b | c |
|
@@ -254,7 +254,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
254
254
|
table([{:a=> "A" * 50, :b=>2, :c=>"C"*10}], :resize=>false).should == expected_table
|
255
255
|
end
|
256
256
|
|
257
|
-
|
257
|
+
it "global width renders" do
|
258
258
|
expected_table = <<-TABLE.unindent
|
259
259
|
+-----------+---+------------+
|
260
260
|
| a | b | c |
|
@@ -263,13 +263,13 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
263
263
|
+-----------+---+------------+
|
264
264
|
1 row in set
|
265
265
|
TABLE
|
266
|
-
|
267
|
-
|
266
|
+
View.load_config
|
267
|
+
View.resize(30)
|
268
268
|
table([{:a=> "A" * 50, :b=>2, :c=>"C"*10}]).should == expected_table
|
269
269
|
reset_config
|
270
270
|
end
|
271
271
|
|
272
|
-
|
272
|
+
it "headers option and headers longer than fields renders" do
|
273
273
|
expected_table = <<-TABLE.unindent
|
274
274
|
+---+---------+---------+
|
275
275
|
| a | field B | field C |
|
@@ -281,7 +281,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
281
281
|
table([{:a=> "A", :b=>2, :c=>"C"}], :headers=>{:b=>"field B", :c=>"field C"}).should == expected_table
|
282
282
|
end
|
283
283
|
|
284
|
-
|
284
|
+
it "headers option and headers shortened by max_fields renders" do
|
285
285
|
expected_table = <<-TABLE.unindent
|
286
286
|
+-------+---+
|
287
287
|
| fi... | b |
|
@@ -293,7 +293,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
293
293
|
table([{:a=> "A", :b=>2}], :headers=>{:a=>"field A"}, :max_fields=>{:a=>5}, :resize=>false).should == expected_table
|
294
294
|
end
|
295
295
|
|
296
|
-
|
296
|
+
it "headers option as an array renders" do
|
297
297
|
expected_table = <<-TABLE.unindent
|
298
298
|
+---+---+
|
299
299
|
| A | B |
|
@@ -306,7 +306,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
306
306
|
table([[1,2], [3,4]], :headers=>['A', 'B']).should == expected_table
|
307
307
|
end
|
308
308
|
|
309
|
-
|
309
|
+
it "header_filter option renders" do
|
310
310
|
expected_table = <<-TABLE.unindent
|
311
311
|
+---+---+
|
312
312
|
| A | B |
|
@@ -318,7 +318,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
318
318
|
table([{:a=> 2, :b=>3}], :header_filter=>:capitalize).should == expected_table
|
319
319
|
end
|
320
320
|
|
321
|
-
|
321
|
+
it "filters option renders" do
|
322
322
|
expected_table = <<-TABLE.unindent
|
323
323
|
+-----------+---+
|
324
324
|
| 0 | 1 |
|
@@ -332,7 +332,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
332
332
|
1=>[:[], :num]}).should == expected_table
|
333
333
|
end
|
334
334
|
|
335
|
-
|
335
|
+
it "filters option calls Filters method and renders" do
|
336
336
|
module ::Hirb::Helpers::Table::Filters
|
337
337
|
def semicolon_join(arr); arr.join('; '); end
|
338
338
|
end
|
@@ -348,7 +348,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
348
348
|
table([[['some'], %w{unsightly unreadable array}]], :filters=>{1=>:semicolon_join}).should == expected_table
|
349
349
|
end
|
350
350
|
|
351
|
-
|
351
|
+
it "number option renders" do
|
352
352
|
expected_table = <<-TABLE.unindent
|
353
353
|
+--------+---+---+
|
354
354
|
| number | 0 | 1 |
|
@@ -361,7 +361,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
361
361
|
table([['a','b'], ['c', 'd']], :number=>true).should == expected_table
|
362
362
|
end
|
363
363
|
|
364
|
-
|
364
|
+
it "description option false renders" do
|
365
365
|
expected_table = <<-TABLE.unindent
|
366
366
|
+---+---+
|
367
367
|
| 0 | 1 |
|
@@ -373,7 +373,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
373
373
|
table([['a','b'], ['c', 'd']], :description=>false).should == expected_table
|
374
374
|
end
|
375
375
|
|
376
|
-
|
376
|
+
it "vertical option renders vertical table" do
|
377
377
|
expected_table = <<-TABLE.unindent
|
378
378
|
*** 1. row ***
|
379
379
|
a: 1
|
@@ -386,7 +386,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
386
386
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :vertical=>true).should == expected_table
|
387
387
|
end
|
388
388
|
|
389
|
-
|
389
|
+
it "vertical option renders vertical table with newlines" do
|
390
390
|
expected_table = <<-TABLE.unindent
|
391
391
|
*** 1. row ***
|
392
392
|
a: 1
|
@@ -400,7 +400,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
400
400
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>"4\nand one"}], :vertical=>true).should == expected_table
|
401
401
|
end
|
402
402
|
|
403
|
-
|
403
|
+
it "vertical option renders vertical table successively" do
|
404
404
|
expected_table = <<-TABLE.unindent
|
405
405
|
*** 1. row ***
|
406
406
|
a: 1
|
@@ -415,7 +415,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
415
415
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], options).should == expected_table
|
416
416
|
end
|
417
417
|
|
418
|
-
|
418
|
+
it "hide_empty and vertical options renders" do
|
419
419
|
expected_table = <<-TABLE.unindent
|
420
420
|
*** 1. row ***
|
421
421
|
b: 2
|
@@ -426,7 +426,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
426
426
|
table([{:a=>'', :b=>2}, {:a=>3, :b=>nil}], :hide_empty=>true, :vertical=>true).should == expected_table
|
427
427
|
end
|
428
428
|
|
429
|
-
|
429
|
+
it "all_fields option renders all fields" do
|
430
430
|
expected_table = <<-TABLE.unindent
|
431
431
|
+---+---+---+
|
432
432
|
| a | b | c |
|
@@ -439,7 +439,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
439
439
|
table([{:a=>1, :b=>2}, {:a=>3, :c=>4}], :all_fields=>true).should == expected_table
|
440
440
|
end
|
441
441
|
|
442
|
-
|
442
|
+
it "change_fields option renders" do
|
443
443
|
expected_table = <<-TABLE.unindent
|
444
444
|
+------+-------+
|
445
445
|
| name | value |
|
@@ -453,7 +453,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
453
453
|
table([[1,2],[2,3]], :change_fields=>['name', 'value']).should == expected_table
|
454
454
|
end
|
455
455
|
|
456
|
-
|
456
|
+
it "change_fields and fields option renders" do
|
457
457
|
expected_table = <<-TABLE.unindent
|
458
458
|
+------+
|
459
459
|
| name |
|
@@ -466,7 +466,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
466
466
|
table([[1,2],[2,3]], :change_fields=>['name', 'value'], :fields=>['name']).should == expected_table
|
467
467
|
end
|
468
468
|
|
469
|
-
|
469
|
+
it "invalid fields in change_fields options are ignored" do
|
470
470
|
expected_table = <<-TABLE.unindent
|
471
471
|
+------+-------+
|
472
472
|
| name | value |
|
@@ -480,7 +480,7 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
480
480
|
table([[1,2],[2,3]], :change_fields=>['name', 'value','time']).should == expected_table
|
481
481
|
end
|
482
482
|
|
483
|
-
|
483
|
+
it "filter_any option filters any value" do
|
484
484
|
expected_table = <<-TABLE.unindent
|
485
485
|
+---------+
|
486
486
|
| a |
|
@@ -493,29 +493,27 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
493
493
|
table([{:a=>{:b=>1}}, {:a=>2}], :filter_any=>true).should == expected_table
|
494
494
|
end
|
495
495
|
|
496
|
-
|
496
|
+
it "filter_classes option overrides class-wide filter_classes" do
|
497
497
|
expected_table = <<-TABLE.unindent
|
498
|
-
|
499
|
-
| a
|
500
|
-
|
501
|
-
|
|
502
|
-
|
498
|
+
+---+
|
499
|
+
| a |
|
500
|
+
+---+
|
501
|
+
| 1 |
|
502
|
+
+---+
|
503
503
|
1 row in set
|
504
504
|
TABLE
|
505
|
-
table([{:a=>{:b=>1}}], :filter_classes=>{Hash=>:
|
505
|
+
table([{:a=>{:b=>1}}], :filter_classes=>{Hash=>:size}).should == expected_table
|
506
506
|
end
|
507
507
|
end
|
508
508
|
|
509
|
-
|
510
|
-
|
511
|
-
|
509
|
+
describe "table with callbacks" do
|
510
|
+
before_all {
|
511
|
+
Helpers::Table.send(:define_method, :and_one_callback) do |obj, opt|
|
512
512
|
obj.each {|row| row.each {|k,v| row[k] += opt[:add] } }
|
513
513
|
obj
|
514
514
|
end
|
515
515
|
}
|
516
|
-
|
517
|
-
|
518
|
-
test "detects and runs them" do
|
516
|
+
it "detects and runs them" do
|
519
517
|
expected_table = <<-TABLE.unindent
|
520
518
|
+---+---+
|
521
519
|
| a | b |
|
@@ -528,8 +526,8 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
528
526
|
table([{'a'=>1, 'b'=>2}, {'a'=>3, 'b'=>4}], :add=>1).should == expected_table
|
529
527
|
end
|
530
528
|
|
531
|
-
|
532
|
-
|
529
|
+
it "doesn't run callbacks in delete_callbacks option" do
|
530
|
+
Helpers::Table.send(:define_method, :and_two_callback) do |obj, opt|
|
533
531
|
obj.each {|row| row.each {|k,v| row[k] = row[k] * 2 } }
|
534
532
|
obj
|
535
533
|
end
|
@@ -545,7 +543,8 @@ class Hirb::Helpers::TableTest < Test::Unit::TestCase
|
|
545
543
|
TABLE
|
546
544
|
table([{'a'=>1, 'b'=>2}, {'a'=>3, 'b'=>4}], :add=>1, :delete_callbacks=>[:and_two]).should == expected_table
|
547
545
|
|
548
|
-
|
546
|
+
Helpers::Table.send(:remove_method, :and_two_callback)
|
549
547
|
end
|
548
|
+
after_all { Helpers::Table.send(:remove_method, :and_one_callback) }
|
550
549
|
end
|
551
550
|
end
|