ruport 1.2.3 → 1.4.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.
- data/Rakefile +2 -4
- data/examples/centered_pdf_text_box.rb +2 -6
- data/examples/pdf_report_with_common_base.rb +2 -5
- data/examples/png_embed.rb +3 -8
- data/examples/simple_templating_example.rb +7 -7
- data/examples/tattle_rubygems_version.rb +0 -3
- data/lib/ruport/data/grouping.rb +11 -10
- data/lib/ruport/data/record.rb +3 -1
- data/lib/ruport/data/table.rb +0 -14
- data/lib/ruport/formatter/csv.rb +10 -15
- data/lib/ruport/formatter/html.rb +4 -6
- data/lib/ruport/formatter/pdf.rb +50 -91
- data/lib/ruport/formatter/template.rb +33 -15
- data/lib/ruport/formatter/text.rb +22 -26
- data/lib/ruport/formatter.rb +27 -11
- data/lib/ruport/renderer/grouping.rb +0 -6
- data/lib/ruport/renderer/table.rb +0 -4
- data/lib/ruport/renderer.rb +64 -78
- data/lib/ruport.rb +7 -4
- data/test/csv_formatter_test.rb +8 -8
- data/test/grouping_test.rb +10 -10
- data/test/helpers.rb +2 -0
- data/test/html_formatter_test.rb +5 -5
- data/test/pdf_formatter_test.rb +23 -14
- data/test/record_test.rb +5 -0
- data/test/renderer_test.rb +103 -47
- data/test/table_test.rb +111 -138
- data/test/template_test.rb +12 -1
- data/test/text_formatter_test.rb +12 -14
- metadata +69 -88
- data/lib/ruport/acts_as_reportable.rb +0 -378
- data/lib/ruport/query/sql_split.rb +0 -33
- data/lib/ruport/query.rb +0 -232
- data/test/acts_as_reportable_test.rb +0 -272
- data/test/query_test.rb +0 -259
- data/test/sql_split_test.rb +0 -20
data/test/table_test.rb
CHANGED
@@ -14,7 +14,6 @@ class DuckRecord < Ruport::Data::Record; end
|
|
14
14
|
|
15
15
|
class TestTable < Test::Unit::TestCase
|
16
16
|
def test_constructors
|
17
|
-
|
18
17
|
table = Ruport::Data::Table.new
|
19
18
|
|
20
19
|
table2 = Ruport::Data::Table.new :column_names => %w[a b c]
|
@@ -26,8 +25,8 @@ class TestTable < Test::Unit::TestCase
|
|
26
25
|
tables.zip([[],%w[a b c], [], %w[col1 col2 col3]]).each do |t,n|
|
27
26
|
assert_equal n, t.column_names
|
28
27
|
|
29
|
-
|
30
|
-
|
28
|
+
t = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
29
|
+
table_from_records = Table(t.column_names, :data => t.data)
|
31
30
|
end
|
32
31
|
|
33
32
|
a = Ruport::Data::Record.new [1,2,3]
|
@@ -94,7 +93,7 @@ class TestTable < Test::Unit::TestCase
|
|
94
93
|
end
|
95
94
|
|
96
95
|
def test_to_group
|
97
|
-
a =[[1,2,3],[4,5,6]]
|
96
|
+
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]]).to_group("Packrats")
|
98
97
|
b = Ruport::Data::Group.new( :data => [[1,2,3],[4,5,6]],
|
99
98
|
:column_names => %w[a b c],
|
100
99
|
:name => "Packrats" )
|
@@ -102,7 +101,7 @@ class TestTable < Test::Unit::TestCase
|
|
102
101
|
end
|
103
102
|
|
104
103
|
def test_rows_with
|
105
|
-
table = [[1,2,3],[1,3,4],[7,8,9]]
|
104
|
+
table = Table(%w[a b c], :data => [[1,2,3],[1,3,4],[7,8,9]])
|
106
105
|
|
107
106
|
assert_equal([table[0],table[1]],table.rows_with("a" => 1))
|
108
107
|
assert_equal([table[1]],table.rows_with("a" => 1, "b" => 3))
|
@@ -112,7 +111,7 @@ class TestTable < Test::Unit::TestCase
|
|
112
111
|
end
|
113
112
|
|
114
113
|
def test_sigma
|
115
|
-
table = [[1,2],[3,4],[5,6]]
|
114
|
+
table = Table(%w[col1 col2], :data => [[1,2],[3,4],[5,6]])
|
116
115
|
assert table.respond_to?(:sigma)
|
117
116
|
assert table.respond_to?(:sum)
|
118
117
|
assert_equal(9,table.sigma(0))
|
@@ -121,46 +120,46 @@ class TestTable < Test::Unit::TestCase
|
|
121
120
|
end
|
122
121
|
|
123
122
|
def test_sub_table
|
124
|
-
table = [
|
125
|
-
|
123
|
+
table = Table(%w[a b c d],
|
124
|
+
:data => [ [1,2,3,4],[5,6,7,9],[10,11,12,13],[14,15,16,17] ])
|
126
125
|
|
127
|
-
assert_equal [[6,7],[11,12]]
|
126
|
+
assert_equal Table(%w[b c], :data => [[6,7],[11,12]]),
|
128
127
|
table.sub_table(%w[b c],1..-2)
|
129
128
|
|
130
|
-
assert_equal [[3,4,1],[7,9,5]]
|
129
|
+
assert_equal Table(%w[c d a], :data => [[3,4,1],[7,9,5]]),
|
131
130
|
table.sub_table(%w[c d a]) { |r| r.a < 10 }
|
132
131
|
|
133
|
-
assert_equal [[1,3],[5,7],[10,12],[14,16]]
|
132
|
+
assert_equal Table(%w[a c], :data => [[1,3],[5,7],[10,12],[14,16]]),
|
134
133
|
table.sub_table(%w[a c])
|
135
134
|
|
136
|
-
assert_equal [[10,11,12,13],[14,15,16,17]]
|
135
|
+
assert_equal Table(%w[a b c d], :data => [[10,11,12,13],[14,15,16,17]]),
|
137
136
|
table.sub_table { |r| r.c > 10 }
|
138
137
|
|
139
|
-
assert_equal [[10,11,12,13],[14,15,16,17]]
|
138
|
+
assert_equal Table(%w[a b c d], :data => [[10,11,12,13],[14,15,16,17]]),
|
140
139
|
table.sub_table(2..-1)
|
141
140
|
|
142
141
|
end
|
143
142
|
|
144
143
|
def test_subtable_records_have_correct_data
|
145
|
-
table = [
|
146
|
-
|
144
|
+
table = Table(%w[a b c d],
|
145
|
+
:data => [ [1,2,3,4],[5,6,7,9],[10,11,12,13],[14,15,16,17] ])
|
147
146
|
sub = table.sub_table(%w[b c d]) {|r| r.a == 1 }
|
148
147
|
assert_equal({"b"=>2, "c"=>3, "d"=>4}, sub[0].data)
|
149
148
|
assert_equal(["b", "c", "d"], sub[0].attributes)
|
150
149
|
end
|
151
150
|
|
152
151
|
def test_reduce
|
153
|
-
table = [
|
154
|
-
|
152
|
+
table = Table(%w[a b c d],
|
153
|
+
:data => [ [1,2,3,4],[5,6,7,9],[10,11,12,13],[14,15,16,17] ])
|
155
154
|
|
156
155
|
table.reduce(%w[b c],1..-2)
|
157
|
-
assert_equal [[6,7],[11,12]]
|
156
|
+
assert_equal Table(%w[b c], :data => [[6,7],[11,12]]), table
|
158
157
|
|
159
|
-
table = [
|
160
|
-
|
158
|
+
table = Table(%w[a b c d],
|
159
|
+
:data => [ [1,2,3,4],[5,6,7,9],[10,11,12,13],[14,15,16,17] ])
|
161
160
|
table.reduce(%w[c d a]) { |r| r.a < 10 }
|
162
161
|
|
163
|
-
assert_equal [[3,4,1],[7,9,5]]
|
162
|
+
assert_equal Table(%w[c d a], :data => [[3,4,1],[7,9,5]]), table
|
164
163
|
end
|
165
164
|
|
166
165
|
def test_reorder
|
@@ -170,13 +169,13 @@ class TestTable < Test::Unit::TestCase
|
|
170
169
|
rows = [%w[a c], %w[d e]]
|
171
170
|
table.each { |r| assert_equal rows.shift, r.to_a
|
172
171
|
assert_equal %w[col1 col3], r.attributes }
|
173
|
-
a = [[1,2,3],[4,5,6]]
|
172
|
+
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]]).reorder 2,0
|
174
173
|
rows = [[3,1],[6,4]]
|
175
174
|
a.each { |r| assert_equal rows.shift, r.to_a
|
176
175
|
assert_equal %w[c a], r.attributes }
|
177
176
|
assert_equal %w[c a], a.column_names
|
178
177
|
|
179
|
-
b = [[1,2,3],[4,5,6]]
|
178
|
+
b = Table(%w[a b c], :data => [[1,2,3],[4,5,6]]).reorder(%w[a c])
|
180
179
|
rows = [[1,3],[4,6]]
|
181
180
|
b.each { |r|
|
182
181
|
assert_equal rows.shift, r.to_a
|
@@ -272,52 +271,37 @@ class TestTable < Test::Unit::TestCase
|
|
272
271
|
|
273
272
|
end
|
274
273
|
|
275
|
-
def test_array_hack
|
276
|
-
t = [[1,2],[3,4],[5,6]].to_table
|
277
|
-
assert_instance_of Ruport::Data::Table, t
|
278
|
-
assert_equal [], t.column_names
|
279
|
-
table = Ruport::Data::Table.new :column_names => %w[a b],
|
280
|
-
:data => [[1,2],[3,4],[5,6]]
|
281
|
-
|
282
|
-
table2 = [[1,2],[3,4],[5,6]].to_table %w[a b]
|
283
|
-
|
284
|
-
assert_equal table, table2
|
285
|
-
|
286
|
-
end
|
287
|
-
|
288
274
|
def test_record_class
|
289
275
|
a = Ruport::Data::Table.new( :column_names => %w[first_name last_name c],
|
290
276
|
:data =>[['joe','loop',3],['jim','blue',6]],
|
291
277
|
:record_class => Person )
|
292
|
-
assert_equal a, [
|
293
|
-
['joe','loop',3],['jim','blue',6]
|
294
|
-
].to_table(%w[first_name last_name c])
|
278
|
+
assert_equal a, Table(%w[first_name last_name c],
|
279
|
+
:data => [ ['joe','loop',3],['jim','blue',6] ])
|
295
280
|
assert_kind_of Person, a[0]
|
296
281
|
assert_equal 'joe loop', a[0].name
|
297
282
|
assert_equal 'jim blue', a[1].name
|
298
283
|
|
299
|
-
b = Table(%w[first_name last_name], :record_class => Person
|
284
|
+
b = Table(%w[first_name last_name], :record_class => Person) do |t|
|
300
285
|
t << { 'first_name' => 'joe', 'last_name' => 'frasier' }
|
301
286
|
t << { 'first_name' => 'brian', 'last_name' => 'black' }
|
302
287
|
end
|
303
288
|
|
304
289
|
b.each { |r| assert_kind_of Person, r }
|
305
290
|
|
306
|
-
assert_equal ['joe frasier', 'brian black'],
|
307
|
-
b.map { |r| r.name }
|
308
|
-
|
291
|
+
assert_equal ['joe frasier', 'brian black'], b.map { |r| r.name }
|
309
292
|
end
|
310
293
|
|
311
294
|
## BUG Traps -------------------------------------------------
|
312
295
|
|
313
296
|
def test_ensure_table_creation_allows_record_coercion
|
314
|
-
table = [[1,2,3],[4,5,6],[7,8,9]]
|
315
|
-
table_with_names = [[1,2,3],[4,5,6],[7,8,9]]
|
297
|
+
table = Table([], :data => [[1,2,3],[4,5,6],[7,8,9]])
|
298
|
+
table_with_names = Table(%w[a b c], :data => [[1,2,3],[4,5,6],[7,8,9]])
|
316
299
|
|
317
300
|
a,b,c = nil
|
318
|
-
assert_nothing_raised { a =
|
319
|
-
assert_nothing_raised { b =
|
320
|
-
assert_nothing_raised { c = table_with_names.
|
301
|
+
assert_nothing_raised { a = Table(%w[a b c], :data => table.to_a) }
|
302
|
+
assert_nothing_raised { b = Table(%w[d e f], :data => table.to_a) }
|
303
|
+
assert_nothing_raised { c = Table(table_with_names.column_names,
|
304
|
+
:data => table_with_names.to_a) }
|
321
305
|
|
322
306
|
[a,b,c].each { |t| assert_equal(3,t.length) }
|
323
307
|
assert_equal %w[a b c], a.column_names
|
@@ -339,8 +323,8 @@ class TestTable < Test::Unit::TestCase
|
|
339
323
|
end
|
340
324
|
|
341
325
|
def test_ensure_coerce_sum
|
342
|
-
s = [["1"],["3"],["5"]
|
343
|
-
t = [["1.23"],["1.5"]]
|
326
|
+
s = Table([], :data => [["1"],["3"],["5"]])
|
327
|
+
t = Table([], :data => [["1.23"],["1.5"]])
|
344
328
|
|
345
329
|
assert_equal(9,s.sum(0))
|
346
330
|
assert_equal(2.73,t.sum(0))
|
@@ -348,7 +332,7 @@ class TestTable < Test::Unit::TestCase
|
|
348
332
|
|
349
333
|
def test_to_yaml
|
350
334
|
require "yaml"
|
351
|
-
a = []
|
335
|
+
a = Table([])
|
352
336
|
assert_nothing_raised { a.to_yaml }
|
353
337
|
a = Table(%w[first_name last_name],:record_class => Person) { |t|
|
354
338
|
t << %w[joe loop]
|
@@ -358,15 +342,15 @@ class TestTable < Test::Unit::TestCase
|
|
358
342
|
end
|
359
343
|
|
360
344
|
def test_ensure_subtable_works_with_unnamed_tables
|
361
|
-
a = [[1,2,3],[4,5,6]]
|
345
|
+
a = Table([], :data => [[1,2,3],[4,5,6]])
|
362
346
|
b = a.sub_table { |r| (r[0] % 2).zero? }
|
363
|
-
assert_equal [[4,5,6]]
|
347
|
+
assert_equal Table([], :data => [[4,5,6]]), b
|
364
348
|
end
|
365
349
|
|
366
350
|
def test_ensure_appending_records_works_with_unnamed_tables
|
367
|
-
a = [[1,2,3],[4,5,6]]
|
351
|
+
a = Table([], :data => [[1,2,3],[4,5,6]])
|
368
352
|
a << Ruport::Data::Record.new([7,8,9])
|
369
|
-
assert_equal [[1,2,3],[4,5,6],[7,8,9]]
|
353
|
+
assert_equal Table([], :data => [[1,2,3],[4,5,6],[7,8,9]]),a
|
370
354
|
end
|
371
355
|
|
372
356
|
def test_ensure_propagate_record_class
|
@@ -406,10 +390,10 @@ class TestTableAppendOperations < Test::Unit::TestCase
|
|
406
390
|
end
|
407
391
|
|
408
392
|
def test_append_hash
|
409
|
-
table = [[1,2,3],[4,5,6]]
|
393
|
+
table = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
410
394
|
table << { "a" => 7, "c" => 9, "b" => 8 }
|
411
395
|
|
412
|
-
assert_equal [[1,2,3],[4,5,6],[7,8,9]]
|
396
|
+
assert_equal Table(%w[a b c], :data => [[1,2,3],[4,5,6],[7,8,9]]), table
|
413
397
|
end
|
414
398
|
|
415
399
|
def test_append_table
|
@@ -442,13 +426,12 @@ class TestTableFormattingHooks < Test::Unit::TestCase
|
|
442
426
|
a.to_csv(:show_table_headers => false)
|
443
427
|
|
444
428
|
assert_equal "would,you,like\none,red,cat\n",
|
445
|
-
a.to_csv { |r| r.show_table_headers = false }
|
429
|
+
a.to_csv { |r| r.options.show_table_headers = false }
|
446
430
|
|
447
431
|
assert_equal "would\tyou\tlike\none\tred\tcat\n",
|
448
432
|
a.to_csv(:show_table_headers => false) { |r|
|
449
|
-
r.format_options = { :col_sep => "\t" }
|
433
|
+
r.options.format_options = { :col_sep => "\t" }
|
450
434
|
}
|
451
|
-
|
452
435
|
end
|
453
436
|
|
454
437
|
def test_to_hack
|
@@ -459,7 +442,7 @@ class TestTableFormattingHooks < Test::Unit::TestCase
|
|
459
442
|
end
|
460
443
|
|
461
444
|
def test_as_throws_proper_errors
|
462
|
-
a = [[1,2,3],[4,5,6]]
|
445
|
+
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
463
446
|
assert_nothing_raised { a.as(:csv) }
|
464
447
|
assert_nothing_raised { a.to_csv }
|
465
448
|
assert_raises(Ruport::Renderer::UnknownFormatError) { a.as(:nothing) }
|
@@ -471,19 +454,19 @@ end
|
|
471
454
|
class TestTableColumnOperations < Test::Unit::TestCase
|
472
455
|
|
473
456
|
def test_column
|
474
|
-
a = [[1,2,3],[4,5,6]]
|
457
|
+
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
475
458
|
assert_equal [3,6], a.column(2)
|
476
459
|
assert_equal [2,5], a.column("b")
|
477
460
|
|
478
461
|
assert_raise(ArgumentError) { a.column("d") }
|
479
462
|
assert_raise(ArgumentError) { a.column(42) }
|
480
463
|
|
481
|
-
a = [[1],[2],[3],[4]]
|
464
|
+
a = Table([], :data => [[1],[2],[3],[4]])
|
482
465
|
assert_equal [1,2,3,4], a.column(0)
|
483
466
|
end
|
484
467
|
|
485
468
|
def test_set_column_names
|
486
|
-
a = [[1,2,3],[4,5,6]]
|
469
|
+
a = Table([], :data => [[1,2,3],[4,5,6]])
|
487
470
|
|
488
471
|
assert_equal([],a.column_names)
|
489
472
|
assert_equal([[1,2,3],[4,5,6]],a.map { |r| r.to_a } )
|
@@ -500,87 +483,78 @@ class TestTableColumnOperations < Test::Unit::TestCase
|
|
500
483
|
end
|
501
484
|
|
502
485
|
def test_add_column
|
503
|
-
|
504
|
-
a = [[1,2],[3,4],[5,6]].to_table(%w[a b])
|
486
|
+
a = Table(%w[a b], :data => [[1,2],[3,4],[5,6]])
|
505
487
|
a.add_column("c")
|
506
|
-
assert_equal [[1,2,nil],[3,4,nil],[5,6,nil]]
|
488
|
+
assert_equal Table(%w[a b c], :data => [[1,2,nil],[3,4,nil],[5,6,nil]]), a
|
507
489
|
|
508
|
-
a = [[1,2],[3,4],[5,6]]
|
490
|
+
a = Table(%w[a b], :data => [[1,2],[3,4],[5,6]])
|
509
491
|
a.add_column("c",:default => "x")
|
510
|
-
assert_equal [[1,2,'x'],[3,4,'x'],[5,6,'x']]
|
492
|
+
assert_equal Table(%w[a b c], :data => [[1,2,'x'],[3,4,'x'],[5,6,'x']]), a
|
511
493
|
|
512
494
|
b = a.dup
|
513
495
|
b.add_column("x",:before => "b")
|
514
|
-
assert_equal [
|
515
|
-
|
516
|
-
[5,nil,6,'x']].to_table(%w[a x b c]), b
|
496
|
+
assert_equal Table(%w[a x b c],
|
497
|
+
:data => [[1,nil,2,'x'],[3,nil,4,'x'],[5,nil,6,'x']]), b
|
517
498
|
|
518
499
|
b = a.dup
|
519
500
|
b.add_column("x",:after => "b")
|
520
|
-
assert_equal [
|
521
|
-
|
522
|
-
[5,6,nil,'x']].to_table(%w[a b x c]), b
|
501
|
+
assert_equal Table(%w[a b x c],
|
502
|
+
:data => [[1,2,nil,'x'],[3,4,nil,'x'],[5,6,nil,'x']]), b
|
523
503
|
|
524
504
|
|
525
505
|
a.add_column("d") { |r| r[0]+r[1] }
|
526
|
-
assert_equal(
|
527
|
-
|
528
|
-
[3,4,'x',7],
|
529
|
-
[5,6,'x',11] ].to_table(%w[a b c d]), a)
|
506
|
+
assert_equal Table(%w[a b c d],
|
507
|
+
:data => [ [1,2,'x',3],[3,4,'x',7],[5,6,'x',11] ]), a
|
530
508
|
|
531
509
|
a.add_column("x",:position => 1)
|
532
|
-
assert_equal(
|
533
|
-
|
534
|
-
|
535
|
-
[5,nil,6,'x',11] ].to_table(%w[a x b c d]), a)
|
536
|
-
|
537
|
-
end
|
510
|
+
assert_equal Table(%w[a x b c d],
|
511
|
+
:data => [ [1,nil,2,'x',3],[3,nil,4,'x',7],[5,nil,6,'x',11] ]), a
|
512
|
+
end
|
538
513
|
|
539
|
-
def test_add_columns
|
540
|
-
a = [[1,2],[3,4],[5,6]]
|
514
|
+
def test_add_columns
|
515
|
+
a = Table(%w[a b], :data => [[1,2],[3,4],[5,6]])
|
541
516
|
a.add_columns(%w[c d])
|
542
|
-
expected = [
|
543
|
-
|
544
|
-
[5,6,nil,nil] ].to_table(%w[a b c d])
|
517
|
+
expected = Table(%w[a b c d],
|
518
|
+
:data => [ [1,2,nil,nil],[3,4,nil,nil],[5,6,nil,nil] ])
|
545
519
|
|
546
520
|
assert_equal expected, a
|
547
521
|
|
548
|
-
a = [[1,2],[3,4],[5,6]]
|
522
|
+
a = Table(%w[a b], :data => [[1,2],[3,4],[5,6]])
|
549
523
|
|
550
524
|
a.add_columns(%w[c d],:after => "a")
|
551
525
|
|
552
|
-
expected = [
|
553
|
-
|
554
|
-
[5,nil,nil,6], ].to_table(%w[a c d b])
|
526
|
+
expected = Table(%w[a c d b],
|
527
|
+
:data => [ [1,nil,nil,2],[3,nil,nil,4],[5,nil,nil,6], ])
|
555
528
|
|
556
529
|
assert_equal expected, a
|
557
530
|
|
558
531
|
a.add_columns(%w[x f],:before => "a")
|
559
532
|
|
560
|
-
expected = [
|
533
|
+
expected = Table(%w[x f a c d b],
|
534
|
+
:data => [ [nil,nil,1,nil,nil,2],
|
561
535
|
[nil,nil,3,nil,nil,4],
|
562
|
-
[nil,nil,5,nil,nil,6] ]
|
536
|
+
[nil,nil,5,nil,nil,6] ])
|
563
537
|
|
564
538
|
assert_equal expected, a
|
565
539
|
|
566
|
-
a = [[1,2,0],[3,4,0],[5,6,0]]
|
540
|
+
a = Table(%w[a b c], :data => [[1,2,0],[3,4,0],[5,6,0]])
|
567
541
|
|
568
542
|
a.add_columns(%w[x y],:default => 9, :position => 1)
|
569
543
|
|
570
|
-
expected =
|
544
|
+
expected = Table(%w[a x y b c],
|
545
|
+
:data => [[1,9,9,2,0],[3,9,9,4,0],[5,9,9,6,0]])
|
571
546
|
|
572
547
|
assert_equal expected, a
|
573
548
|
|
574
|
-
a = [[1,2],[3,4],[5,6]]
|
549
|
+
a = Table(%w[a b], :data => [[1,2],[3,4],[5,6]])
|
575
550
|
a.add_columns(%w[f x],:default => 0)
|
576
551
|
|
577
|
-
expected = [[1,2,0,0],[3,4,0,0],[5,6,0,0]]
|
552
|
+
expected = Table(%w[a b f x], :data => [[1,2,0,0],[3,4,0,0],[5,6,0,0]])
|
578
553
|
assert_equal expected, a
|
579
554
|
|
580
555
|
assert_raises(RuntimeError) do
|
581
556
|
a.add_columns(%w[a b]) { }
|
582
|
-
end
|
583
|
-
|
557
|
+
end
|
584
558
|
end
|
585
559
|
|
586
560
|
def test_remove_column
|
@@ -664,19 +638,19 @@ class TestTableColumnOperations < Test::Unit::TestCase
|
|
664
638
|
end
|
665
639
|
|
666
640
|
def test_ensure_setting_column_names_later_does_not_break_replace_column
|
667
|
-
a = [[1,2,3],[4,5,6]]
|
641
|
+
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
668
642
|
a.replace_column("b","q") { |r| r.a + r.c }
|
669
643
|
a.column_names = %w[d e f]
|
670
|
-
assert_equal [[1,4,3],[4,10,6]]
|
644
|
+
assert_equal Table(%w[d e f], :data => [[1,4,3],[4,10,6]]), a
|
671
645
|
|
672
|
-
a = [[1,2,3],[4,5,6]]
|
646
|
+
a = Table([], :data => [[1,2,3],[4,5,6]])
|
673
647
|
|
674
648
|
a.replace_column(1) { |r| r[0] + r[2] }
|
675
649
|
|
676
650
|
a.column_names = %w[d e f]
|
677
|
-
assert_equal [[1,4,3],[4,10,6]]
|
651
|
+
assert_equal Table(%w[d e f], :data => [[1,4,3],[4,10,6]]), a
|
678
652
|
|
679
|
-
a = [[1,2,3],[4,5,6]]
|
653
|
+
a = Table([], :data => [[1,2,3],[4,5,6]])
|
680
654
|
|
681
655
|
a.replace_column(2) { |r| r[0] + 5 }
|
682
656
|
|
@@ -685,7 +659,7 @@ class TestTableColumnOperations < Test::Unit::TestCase
|
|
685
659
|
a.replace_column("b") { |r| r.a + 4 }
|
686
660
|
a.replace_column("b","foo") { |r| r.b + 1 }
|
687
661
|
|
688
|
-
assert_equal [[1,6,6],[4,9,9]]
|
662
|
+
assert_equal Table(%w[a foo c], :data => [[1,6,6],[4,9,9]]), a
|
689
663
|
end
|
690
664
|
|
691
665
|
end
|
@@ -698,48 +672,46 @@ class TestTableFromCSV < Test::Unit::TestCase
|
|
698
672
|
rows = [%w[a b c],["d",nil,"e"]]
|
699
673
|
table.each { |r| assert_equal rows.shift, r.to_a
|
700
674
|
assert_equal %w[col1 col2 col3], r.attributes }
|
701
|
-
expected = [%w[1 2 3],%w[4 5 6]]
|
675
|
+
expected = Table(%w[a b c], :data => [%w[1 2 3],%w[4 5 6]])
|
702
676
|
|
703
677
|
# ticket:94
|
704
678
|
table = Ruport::Data::Table.load( File.join(TEST_SAMPLES,"data.tsv"),
|
705
679
|
:csv_options => { :col_sep => "\t" } )
|
706
680
|
assert_equal expected, table
|
707
681
|
|
708
|
-
|
709
|
-
expected = ['c','e']
|
682
|
+
expected = ['c','e']
|
710
683
|
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
684
|
+
table = Ruport::Data::Table.load( File.join(TEST_SAMPLES,"data.csv"),
|
685
|
+
:csv_options => { :headers => true, :header_converters => :symbol }
|
686
|
+
) do |s,r|
|
687
|
+
assert_equal expected.shift, r[:col3]
|
688
|
+
end
|
715
689
|
|
716
|
-
|
690
|
+
assert_equal [:col1,:col2,:col3], table.column_names
|
717
691
|
|
692
|
+
expected = ['c','e']
|
718
693
|
|
719
|
-
|
720
|
-
|
721
|
-
Ruport::Data::Table.load( File.join(TEST_SAMPLES,"data.csv"),
|
722
|
-
:records => true ) do |s,r|
|
694
|
+
Ruport::Data::Table.load( File.join(TEST_SAMPLES,"data.csv"),
|
695
|
+
:records => true ) do |s,r|
|
723
696
|
assert_equal expected.shift, r.col3
|
724
697
|
assert_kind_of Ruport::Data::Record, r
|
725
|
-
|
698
|
+
end
|
726
699
|
|
727
|
-
|
700
|
+
table = Ruport::Data::Table.load( File.join(TEST_SAMPLES, "data.csv"),
|
728
701
|
:has_names => false )
|
729
|
-
|
730
|
-
|
731
|
-
|
702
|
+
assert_equal([],table.column_names)
|
703
|
+
assert_equal(Table([],
|
704
|
+
:data => [%w[col1 col2 col3],%w[a b c],["d",nil,"e"]]), table)
|
732
705
|
end
|
733
706
|
|
734
707
|
# ticket:76
|
735
708
|
def test_parse
|
736
|
-
|
737
709
|
assert_nothing_raised {
|
738
710
|
Ruport::Data::Table.parse("a,b,c\n1,2,3\n")
|
739
711
|
}
|
740
712
|
|
741
713
|
table = Ruport::Data::Table.parse("a,b,c\n1,2,3\n4,5,6\n")
|
742
|
-
expected = [%w[1 2 3],%w[4 5 6]]
|
714
|
+
expected = Table(%w[a b c], :data => [%w[1 2 3],%w[4 5 6]])
|
743
715
|
|
744
716
|
table = Ruport::Data::Table.parse( "a\tb\tc\n1\t2\t3\n4\t5\t6\n",
|
745
717
|
:csv_options => { :col_sep => "\t" } )
|
@@ -748,9 +720,7 @@ class TestTableFromCSV < Test::Unit::TestCase
|
|
748
720
|
table = Ruport::Data::Table.parse( "a,b,c\n1,2,3\n4,5,6\n",
|
749
721
|
:has_names => false)
|
750
722
|
assert_equal([],table.column_names)
|
751
|
-
assert_equal([%w[a b c],%w[1 2 3]
|
752
|
-
|
753
|
-
|
723
|
+
assert_equal(Table([], :data => [%w[a b c],%w[1 2 3],%w[4 5 6]]), table)
|
754
724
|
end
|
755
725
|
|
756
726
|
def test_csv_block_form
|
@@ -761,7 +731,7 @@ class TestTableFromCSV < Test::Unit::TestCase
|
|
761
731
|
assert_equal expected.shift, r
|
762
732
|
s << r
|
763
733
|
end
|
764
|
-
assert_equal [%w[a b],%w[1 2],%w[3 4]]
|
734
|
+
assert_equal Table([], :data => [%w[a b],%w[1 2],%w[3 4]]), t
|
765
735
|
end
|
766
736
|
|
767
737
|
# - BUG TRAPS --------------------
|
@@ -773,8 +743,8 @@ class TestTableFromCSV < Test::Unit::TestCase
|
|
773
743
|
s << r
|
774
744
|
s << r
|
775
745
|
}
|
776
|
-
assert_equal [
|
777
|
-
|
746
|
+
assert_equal Table([],
|
747
|
+
:data => [%w[a b],%w[a b],%w[1 2], %w[1 2],%w[3 4],%w[3 4]]), t
|
778
748
|
x = Ruport::Data::Table.load(File.join(TEST_SAMPLES,"data.csv")) { |s,r|
|
779
749
|
assert_kind_of Ruport::Data::Feeder, s
|
780
750
|
assert_kind_of Array, r
|
@@ -802,8 +772,10 @@ end
|
|
802
772
|
class TestTableKernelHack < Test::Unit::TestCase
|
803
773
|
|
804
774
|
def test_simple
|
805
|
-
assert_equal
|
806
|
-
|
775
|
+
assert_equal Ruport::Data::Table.new(:column_names => %w[a b c]),
|
776
|
+
Table(%w[a b c])
|
777
|
+
assert_equal Ruport::Data::Table.new(:column_names => %w[a b c]),
|
778
|
+
Table("a","b","c")
|
807
779
|
assert_equal Ruport::Data::Table.load(
|
808
780
|
File.join(TEST_SAMPLES,"addressbook.csv")),
|
809
781
|
Table(File.join(TEST_SAMPLES,"addressbook.csv"))
|
@@ -812,7 +784,10 @@ class TestTableKernelHack < Test::Unit::TestCase
|
|
812
784
|
Table(File.join(TEST_SAMPLES,"addressbook.csv"), :has_names => false)
|
813
785
|
Table("a","b","c") do |t|
|
814
786
|
t << [1,2,3]
|
815
|
-
assert_equal(
|
787
|
+
assert_equal(
|
788
|
+
Ruport::Data::Table.new(:column_names => %w[a b c], :data => [[1,2,3]]),
|
789
|
+
t.data
|
790
|
+
)
|
816
791
|
end
|
817
792
|
|
818
793
|
assert_equal Table("a"), Table(%w[a])
|
@@ -820,7 +795,6 @@ class TestTableKernelHack < Test::Unit::TestCase
|
|
820
795
|
end
|
821
796
|
|
822
797
|
def test_iterators
|
823
|
-
|
824
798
|
Table(File.join(TEST_SAMPLES,"addressbook.csv")) do |s,r|
|
825
799
|
assert_kind_of(Array,r)
|
826
800
|
assert_kind_of(Ruport::Data::Feeder,s)
|
@@ -835,7 +809,6 @@ class TestTableKernelHack < Test::Unit::TestCase
|
|
835
809
|
end
|
836
810
|
|
837
811
|
assert_equal 2, n
|
838
|
-
|
839
812
|
end
|
840
813
|
|
841
814
|
def test_with_file_arg
|
data/test/template_test.rb
CHANGED
@@ -6,6 +6,10 @@ class TemplateTest < Test::Unit::TestCase
|
|
6
6
|
def setup
|
7
7
|
@template_class = Ruport::Formatter::Template.dup
|
8
8
|
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
Ruport::Formatter::Template.instance_variable_set(:@templates, nil)
|
12
|
+
end
|
9
13
|
|
10
14
|
def test_template_should_exist
|
11
15
|
@template_class.create(:foo)
|
@@ -32,6 +36,13 @@ class TemplateTest < Test::Unit::TestCase
|
|
32
36
|
Ruport::Formatter::Template[:bar].page_format[:layout]
|
33
37
|
assert_equal :letter,
|
34
38
|
Ruport::Formatter::Template[:bar].page_format[:paper_size]
|
35
|
-
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_default_template
|
42
|
+
assert_nil Ruport::Formatter::Template.default
|
43
|
+
Ruport::Formatter::Template.create(:default)
|
44
|
+
assert_equal Ruport::Formatter::Template[:default],
|
45
|
+
Ruport::Formatter::Template.default
|
46
|
+
end
|
36
47
|
|
37
48
|
end
|