ruport 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +38 -0
  3. data/HACKING +1 -17
  4. data/{README.rdoc → README.md} +30 -38
  5. data/Rakefile +0 -10
  6. data/examples/row_renderer.rb +1 -1
  7. data/examples/simple_pdf_lines.rb +1 -1
  8. data/examples/trac_ticket_status.rb +1 -1
  9. data/lib/ruport/controller.rb +1 -1
  10. data/lib/ruport/data/grouping.rb +7 -7
  11. data/lib/ruport/data/record.rb +4 -4
  12. data/lib/ruport/data/table.rb +9 -9
  13. data/lib/ruport/formatter/csv.rb +1 -1
  14. data/lib/ruport/formatter/markdown.rb +105 -0
  15. data/lib/ruport/formatter/prawn_pdf.rb +96 -9
  16. data/lib/ruport/formatter/text.rb +1 -1
  17. data/lib/ruport/formatter.rb +1 -2
  18. data/lib/ruport/version.rb +1 -1
  19. data/lib/ruport.rb +7 -11
  20. data/test/controller_test.rb +107 -109
  21. data/test/csv_formatter_test.rb +21 -21
  22. data/test/data_feeder_test.rb +39 -39
  23. data/test/expected_outputs/prawn_pdf_formatter/pdf_basic.pdf.test +265 -0
  24. data/test/grouping_test.rb +74 -74
  25. data/test/helpers.rb +16 -5
  26. data/test/html_formatter_test.rb +22 -22
  27. data/test/markdown_formatter_test.rb +142 -0
  28. data/test/prawn_pdf_formatter_test.rb +108 -0
  29. data/test/record_test.rb +82 -82
  30. data/test/table_pivot_test.rb +9 -2
  31. data/test/table_test.rb +33 -40
  32. data/test/template_test.rb +12 -12
  33. data/test/text_formatter_test.rb +34 -34
  34. data/util/bench/data/table/bench_column_manip.rb +0 -1
  35. data/util/bench/data/table/bench_dup.rb +0 -1
  36. data/util/bench/data/table/bench_init.rb +0 -1
  37. data/util/bench/data/table/bench_manip.rb +0 -1
  38. data/util/bench/formatter/bench_csv.rb +0 -1
  39. data/util/bench/formatter/bench_html.rb +0 -1
  40. data/util/bench/formatter/bench_pdf.rb +0 -1
  41. data/util/bench/formatter/bench_text.rb +0 -1
  42. metadata +30 -29
  43. data/lib/ruport/formatter/pdf.rb +0 -589
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby -w
1
+ #!/usr/bin/env ruby -w
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
3
3
 
4
4
  class TestGroup < Minitest::Test
@@ -8,7 +8,7 @@ class TestGroup < Minitest::Test
8
8
  :data => [[1,2,3]],
9
9
  :column_names => %w[a b c])
10
10
  end
11
-
11
+
12
12
  def test_group_constructor
13
13
  group = Ruport::Data::Group.new(:name => 'test',
14
14
  :data => [[1,2,3]],
@@ -44,7 +44,7 @@ class TestGroup < Minitest::Test
44
44
  assert_equal @group, group2
45
45
  assert_equal @group, @group.dup
46
46
  end
47
-
47
+
48
48
  def test_create_subgroups
49
49
  group = @group << [4,5,6]
50
50
  group.send(:create_subgroups, "a")
@@ -55,7 +55,7 @@ class TestGroup < Minitest::Test
55
55
  :column_names => %w[b c],
56
56
  :name => 4 ) }
57
57
  assert_equal b, group.subgroups
58
-
58
+
59
59
  group.send(:create_subgroups, "b")
60
60
  c = { 2 => Ruport::Data::Group.new( :data => [[3]],
61
61
  :column_names => %w[c],
@@ -65,8 +65,8 @@ class TestGroup < Minitest::Test
65
65
  :name => 5 ) }
66
66
  assert_equal c, group.subgroups[1].subgroups
67
67
  assert_equal d, group.subgroups[4].subgroups
68
- end
69
-
68
+ end
69
+
70
70
  def test_grouped_data
71
71
  a = @group << [4,5,6]
72
72
  b = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
@@ -85,7 +85,7 @@ class TestGroupRendering < Minitest::Test
85
85
  @group = Ruport::Data::Group.new(:name => 'test',
86
86
  :data => [[1,2,3]],
87
87
  :column_names => %w[a b c])
88
- end
88
+ end
89
89
 
90
90
  def test_group_as
91
91
  assert_equal(7, @group.to_text.split("\n").size)
@@ -94,7 +94,7 @@ class TestGroupRendering < Minitest::Test
94
94
  assert_equal(15, @group.to_html.split("\n").size)
95
95
  assert_equal(8, @group.to_html(:show_table_headers => false).split("\n").size)
96
96
  end
97
-
97
+
98
98
  def test_as_throws_proper_errors
99
99
  @group.as(:csv)
100
100
  @group.to_csv
@@ -111,14 +111,14 @@ class TestGroupRendering < Minitest::Test
111
111
  assert_equal "1\n\nb,c\n2,3\n", t.to_csv
112
112
  end
113
113
  end
114
-
114
+
115
115
  class TestGrouping < Minitest::Test
116
-
116
+
117
117
  def setup
118
118
  table = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
119
119
  @grouping = Ruport::Data::Grouping.new(table, :by => "a")
120
120
  end
121
-
121
+
122
122
  def test_grouping_constructor
123
123
  a = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
124
124
  b = Ruport::Data::Grouping.new(a, :by => "a")
@@ -129,24 +129,24 @@ class TestGrouping < Minitest::Test
129
129
  :column_names => %w[b c],
130
130
  :name => 4 ) }
131
131
  assert_equal c, b.data
132
- end
133
-
132
+ end
133
+
134
134
  def test_empty_grouping
135
135
  a = Ruport::Data::Grouping.new()
136
136
  a << Group("foo",:data => [[1,2,3],[4,5,6]],
137
137
  :column_names => %w[a b c] )
138
- assert_equal "foo", a["foo"].name
139
- assert_nil a.grouped_by
140
- end
141
-
138
+ assert_equal "foo", a["foo"].name
139
+ assert_nil a.grouped_by
140
+ end
141
+
142
142
  def test_empty_grouping_with_grouped_by
143
- a = Ruport::Data::Grouping.new(:by => "nada")
143
+ a = Ruport::Data::Grouping.new(:by => "nada")
144
144
  a << Group("foo",:data => [[1,2,3],[4,5,6]],
145
145
  :column_names => %w[a b c] )
146
- assert_equal "foo", a["foo"].name
146
+ assert_equal "foo", a["foo"].name
147
147
  assert_equal "nada", a.grouped_by
148
148
  end
149
-
149
+
150
150
  def test_grouping_indexing
151
151
  a = [Ruport::Data::Group.new( :data => [[2,3]],
152
152
  :column_names => %w[b c],
@@ -160,8 +160,8 @@ class TestGrouping < Minitest::Test
160
160
  assert_equal a[0], @grouping[1]
161
161
  assert_equal a[1], @grouping[4]
162
162
  assert_raises(IndexError) { @grouping[2] }
163
- end
164
-
163
+ end
164
+
165
165
  def test_should_copy_grouping
166
166
  a = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
167
167
  :column_names => %w[b c],
@@ -178,10 +178,10 @@ class TestGrouping < Minitest::Test
178
178
  a = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
179
179
  @grouping << a.to_group("red snapper")
180
180
  assert_equal @grouping["red snapper"], a.to_group("red snapper")
181
-
181
+
182
182
  assert_raises(ArgumentError) { @grouping << a.to_group("red snapper") }
183
183
  end
184
-
184
+
185
185
  def test_grouped_by
186
186
  assert_equal "a", @grouping.grouped_by
187
187
  end
@@ -205,7 +205,7 @@ class TestGrouping < Minitest::Test
205
205
  :name => 5 ) }
206
206
  assert_equal d, b[1].subgroups
207
207
  assert_equal e, b[4].subgroups
208
- end
208
+ end
209
209
 
210
210
  def test_subgrouping
211
211
  a = Ruport.Table(%w[first_name last_name id])
@@ -220,7 +220,7 @@ class TestGrouping < Minitest::Test
220
220
  sub = (g / "mike")["milner"]
221
221
  assert_equal %w[schweet], sub.column("id")
222
222
  end
223
-
223
+
224
224
  class TicketStatus < Ruport::Data::Record
225
225
 
226
226
  def closed
@@ -232,41 +232,41 @@ class TestGrouping < Minitest::Test
232
232
  end
233
233
 
234
234
  end
235
-
235
+
236
236
  def test_grouping_summary
237
237
  source = Ruport.Table(File.join(File.expand_path(File.dirname(__FILE__)),
238
238
  *%w[samples ticket_count.csv]),
239
239
  :record_class => TicketStatus)
240
240
  grouping = Grouping(source,:by => "date")
241
-
241
+
242
242
  expected = Ruport.Table(:date, :opened,:closed)
243
243
  grouping.each do |date,group|
244
244
  opened = group.sigma { |r| r.opened }
245
245
  closed = group.sigma { |r| r.closed }
246
246
  expected << { :date => date, :opened => opened, :closed => closed }
247
247
  end
248
-
248
+
249
249
  actual = grouping.summary :date,
250
250
  :opened => lambda { |g| g.sigma(:opened) },
251
251
  :closed => lambda { |g| g.sigma(:closed) },
252
252
  :order => [:date,:opened,:closed]
253
-
253
+
254
254
  assert_equal expected, actual
255
-
255
+
256
256
  actual = grouping.summary :date,
257
257
  :opened => lambda { |g| g.sigma(:opened) },
258
258
  :closed => lambda { |g| g.sigma(:closed) }
259
-
260
- assert_equal [], expected.column_names - actual.column_names
261
- end
262
-
259
+
260
+ assert_equal [], expected.column_names - actual.column_names
261
+ end
262
+
263
263
  def test_grouping_sigma
264
264
  assert_respond_to @grouping, :sigma
265
265
  assert_respond_to @grouping, :sum
266
-
266
+
267
267
  expected = {}
268
268
  @grouping.data[@grouping.data.keys.first].column_names.each do |col|
269
- expected[col] = @grouping.inject(0) do |s, (group_name, group)|
269
+ expected[col] = @grouping.inject(0) do |s, (_group_name, group)|
270
270
  s + group.sigma(col)
271
271
  end
272
272
  end
@@ -276,7 +276,7 @@ class TestGrouping < Minitest::Test
276
276
 
277
277
  expected = {}
278
278
  @grouping.data[@grouping.data.keys.first].column_names.each do |col|
279
- expected[col] = @grouping.inject(0) do |s, (group_name, group)|
279
+ expected[col] = @grouping.inject(0) do |s, (_group_name, group)|
280
280
  s + group.sigma {|r| r[col] + 2 }
281
281
  end
282
282
  end
@@ -286,66 +286,66 @@ class TestGrouping < Minitest::Test
286
286
  end
287
287
 
288
288
  describe "when sorting groupings" do
289
-
289
+
290
290
  def setup
291
291
  @table = Ruport.Table(%w[a b c]) << ["dog",1,2] << ["cat",3,5] <<
292
292
  ["banana",8,1] << ["dog",5,6] << ["dog",2,4] << ["banana",7,9]
293
293
  end
294
-
295
- def specify_can_set_by_group_name_order_in_constructor
296
- a = Grouping(@table, :by => "a", :order => :name)
297
- names = %w[banana cat dog]
294
+
295
+ def test_specify_can_set_by_group_name_order_in_constructor
296
+ a = Grouping(@table, :by => "a", :order => :name)
297
+ names = %w[banana cat dog]
298
298
  data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ]
299
299
  a.each do |name,group|
300
300
  assert_equal names.shift, name
301
- assert_equal data.shift, group.map { |r| r.to_a }
301
+ assert_equal data.shift, group.map { |r| r.to_a }
302
302
  end
303
303
  end
304
-
305
- def specify_can_set_by_proc_ordering_in_constructor
306
- a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
307
- names = %w[dog banana cat]
304
+
305
+ def test_specify_can_set_by_proc_ordering_in_constructor
306
+ a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
307
+ names = %w[dog banana cat]
308
308
  data = [ [[1,2],[5,6],[2,4]], [[8,1],[7,9]], [[3,5]] ]
309
309
  a.each do |name,group|
310
310
  assert_equal names.shift, name
311
- assert_equal data.shift, group.map { |r| r.to_a }
311
+ assert_equal data.shift, group.map { |r| r.to_a }
312
312
  end
313
- end
314
-
315
- def specify_can_override_sorting
316
- a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
313
+ end
314
+
315
+ def test_specify_can_override_sorting
316
+ a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
317
317
  a.sort_grouping_by!(:name)
318
- names = %w[banana cat dog]
318
+ names = %w[banana cat dog]
319
319
  data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ]
320
320
  a.each do |name,group|
321
321
  assert_equal names.shift, name
322
- assert_equal data.shift, group.map { |r| r.to_a }
322
+ assert_equal data.shift, group.map { |r| r.to_a }
323
323
  end
324
- end
325
-
326
- def specify_can_get_a_new_sorted_grouping
327
- a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
328
- b = a.sort_grouping_by(:name)
329
-
330
- names = %w[banana cat dog]
324
+ end
325
+
326
+ def test_specify_can_get_a_new_sorted_grouping
327
+ a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
328
+ b = a.sort_grouping_by(:name)
329
+
330
+ names = %w[banana cat dog]
331
331
  data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ]
332
332
  b.each do |name,group|
333
333
  assert_equal names.shift, name
334
- assert_equal data.shift, group.map { |r| r.to_a }
334
+ assert_equal data.shift, group.map { |r| r.to_a }
335
335
  end
336
-
336
+
337
337
  # assert original retained
338
- names = %w[dog banana cat]
338
+ names = %w[dog banana cat]
339
339
  data = [ [[1,2],[5,6],[2,4]], [[8,1],[7,9]], [[3,5]] ]
340
340
  a.each do |name,group|
341
341
  assert_equal names.shift, name
342
- assert_equal data.shift, group.map { |r| r.to_a }
343
- end
342
+ assert_equal data.shift, group.map { |r| r.to_a }
343
+ end
344
344
  end
345
345
  end
346
-
346
+
347
347
  class MyRecord < Ruport::Data::Record; end
348
-
348
+
349
349
  def test_grouping_should_set_record_class
350
350
  a = Ruport.Table(%w[a b c], :record_class => MyRecord) { |t|
351
351
  t << [1,2,3]
@@ -353,13 +353,13 @@ class TestGrouping < Minitest::Test
353
353
  }
354
354
  b = Ruport::Data::Grouping.new(a, :by => "a")
355
355
  assert_equal MyRecord, b[1].record_class
356
- end
356
+ end
357
357
 
358
358
  class MyGroupingSub < Ruport::Data::Grouping; end
359
359
 
360
360
  def test_ensure_grouping_subclasses_render_properly
361
361
  t = Ruport.Table(%w[a b c]) << [1,2,3]
362
- a = MyGroupingSub.new(t, :by => "a")
362
+ a = MyGroupingSub.new(t, :by => "a")
363
363
  assert_equal "1\n\nb,c\n2,3\n\n", a.to_csv
364
364
  end
365
365
  end
@@ -370,7 +370,7 @@ class TestGroupingRendering < Minitest::Test
370
370
  table = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
371
371
  @grouping = Ruport::Data::Grouping.new(table, :by => "a")
372
372
  end
373
-
373
+
374
374
  def test_grouping_as
375
375
  assert_equal(15, @grouping.to_text.split("\n").size)
376
376
  assert_equal(11, @grouping.as(:text,
@@ -379,7 +379,7 @@ class TestGroupingRendering < Minitest::Test
379
379
 
380
380
  def test_as_throws_proper_errors
381
381
  @grouping.as(:csv)
382
- @grouping.to_csv
382
+ @grouping.to_csv
383
383
  assert_raises(Ruport::Controller::UnknownFormatError) {
384
384
  @grouping.as(:nothing) }
385
385
  assert_raises(Ruport::Controller::UnknownFormatError) {
@@ -394,7 +394,7 @@ class TestGroupingKernelHacks < Minitest::Test
394
394
  :data => [[1,2,3]],
395
395
  :column_names => %w[a b c])
396
396
  assert_equal group, Group('test', :data => [[1,2,3]],
397
- :column_names => %w[a b c])
397
+ :column_names => %w[a b c])
398
398
  end
399
399
 
400
400
  def test_grouping_kernel_hack
data/test/helpers.rb CHANGED
@@ -1,16 +1,27 @@
1
+ require 'coveralls'
2
+ require 'simplecov'
3
+ require 'coveralls'
1
4
 
2
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
- require 'ruport'
4
- begin; require 'rubygems'; rescue LoadError; nil; end
5
+ # Use this formatter instead if you want to see coverage locally:
6
+ #
7
+ # SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
8
+ # SimpleCov::Formatter::HTMLFormatter,
9
+ # Coveralls::SimpleCov::Formatter
10
+ # ])
5
11
 
12
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
13
+ SimpleCov.start do
14
+ add_filter 'test'
15
+ end
6
16
 
17
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
18
+ require 'ruport'
7
19
  require 'minitest'
8
20
  require 'minitest/autorun'
9
-
10
21
  require 'minitest/spec'
11
22
  require 'minitest/unit'
12
23
  require 'shoulda-context'
13
- require 'mocha/mini_test'
24
+ require 'mocha/minitest'
14
25
  class Minitest::Test
15
26
  include Ruport
16
27
  end
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env ruby -w
1
+ #!/usr/bin/env ruby -w
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
3
3
 
4
4
  class TestRenderHTMLTable < Minitest::Test
5
-
5
+
6
6
  def setup
7
7
  Ruport::Formatter::Template.create(:simple) do |format|
8
8
  format.table = {
@@ -14,7 +14,7 @@ class TestRenderHTMLTable < Minitest::Test
14
14
  }
15
15
  end
16
16
  end
17
-
17
+
18
18
  def test_html_table
19
19
  a = Ruport::Formatter::HTML.new
20
20
 
@@ -23,11 +23,11 @@ class TestRenderHTMLTable < Minitest::Test
23
23
  end
24
24
 
25
25
  def test_render_html_basic
26
-
26
+
27
27
  actual = Ruport::Controller::Table.render_html { |r|
28
28
  r.data = Ruport.Table([], :data => [[1,2,3],[4,5,6]])
29
- }
30
-
29
+ }
30
+
31
31
  assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
32
32
  "</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t"+
33
33
  "\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
@@ -36,21 +36,21 @@ class TestRenderHTMLTable < Minitest::Test
36
36
  actual = Ruport::Controller::Table.render_html { |r|
37
37
  r.data = Ruport.Table(%w[a b c], :data => [ [1,2,3],[4,5,6]])
38
38
  }
39
-
39
+
40
40
  assert_equal("\t<table>\n\t\t<thead>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
41
41
  "\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t</thead>\n\t\t<tr>\n\t\t\t<td>1</td>"+
42
42
  "\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
43
43
  "\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
44
- "\t</tr>\n\t</table>\n",actual)
45
-
44
+ "\t</tr>\n\t</table>\n",actual)
45
+
46
46
  end
47
-
47
+
48
48
  def test_render_with_template
49
49
  formatter = Ruport::Formatter::HTML.new
50
50
  formatter.options = Ruport::Controller::Options.new
51
51
  formatter.options.template = :simple
52
52
  formatter.apply_template
53
-
53
+
54
54
  assert_equal false, formatter.options.show_table_headers
55
55
 
56
56
  assert_equal :justified, formatter.options.style
@@ -72,7 +72,7 @@ class TestRenderHTMLTable < Minitest::Test
72
72
  ) do |r|
73
73
  opts = r.options
74
74
  end
75
-
75
+
76
76
  assert_equal true, opts.show_table_headers
77
77
 
78
78
  assert_equal :inline, opts.style
@@ -90,27 +90,27 @@ class TestRenderHTMLTable < Minitest::Test
90
90
  ) do |r|
91
91
  opts = r.options
92
92
  end
93
-
93
+
94
94
  assert_equal true, opts.show_table_headers
95
95
 
96
96
  assert_equal :inline, opts.style
97
97
  assert_equal true, opts.show_group_headers
98
98
  end
99
99
  end
100
-
100
+
101
101
 
102
102
  class TestRenderHTMLRow < Minitest::Test
103
-
103
+
104
104
  def test_render_html_row
105
105
  actual = Ruport::Controller::Row.render_html { |r| r.data = [1,2,3] }
106
106
  assert_equal("\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
107
107
  "</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n",actual)
108
108
  end
109
109
  end
110
-
110
+
111
111
 
112
112
  class TestRenderHTMLGroup < Minitest::Test
113
-
113
+
114
114
  def test_render_html_group
115
115
  group = Ruport::Data::Group.new(:name => 'test',
116
116
  :data => [[1,2,3],[4,5,6]],
@@ -134,7 +134,7 @@ class TestRenderHTMLGroup < Minitest::Test
134
134
  "\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
135
135
  "\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
136
136
  "\t</tr>\n\t</table>\n", actual
137
- end
137
+ end
138
138
  end
139
139
 
140
140
 
@@ -181,8 +181,8 @@ class TestRenderHTMLGrouping < Minitest::Test
181
181
  "<td class=\"groupName\">2</td>\n\t\t\t<td>7</td>\n"+
182
182
  "\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n", actual
183
183
  end
184
- end
185
-
184
+ end
185
+
186
186
 
187
187
  class TestHTMLFormatterHelpers < Minitest::Test
188
188
  begin
@@ -190,8 +190,8 @@ class TestHTMLFormatterHelpers < Minitest::Test
190
190
  rescue LoadError
191
191
  nil
192
192
  end
193
-
194
- def test_textile
193
+
194
+ def test_textile
195
195
  require "redcloth"
196
196
  a = Ruport::Formatter::HTML.new
197
197
  assert_equal "<p><strong>foo</strong></p>", a.textile("*foo*")
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
4
+
5
+ class TestRenderMarkdownTable < Minitest::Test
6
+ def test_render_markdown_table_basic
7
+ actual = Ruport::Controller::Table.render_markdown do |r|
8
+ r.data = Ruport::Table([:foo, :bar, :baz], data: [[1, 2, 3], [], [4, 5], [6]])
9
+ end
10
+
11
+ assert_equal([
12
+ "|foo|bar|baz|\n",
13
+ "|:--|:--|:--|\n",
14
+ "|1|2|3|\n",
15
+ "||||\n",
16
+ "|4|5||\n",
17
+ "|6|||\n"
18
+ ].join, actual)
19
+ end
20
+
21
+ def test_render_markdown_table_without_column_names
22
+ actual = Ruport::Controller::Table.render_markdown do |r|
23
+ r.data = Ruport::Table(data: [[:foo, :bar], [1, 2], [3, 4]])
24
+ end
25
+
26
+ assert_equal([
27
+ "|foo|bar|\n",
28
+ "|:--|:--|\n",
29
+ "|1|2|\n",
30
+ "|3|4|\n",
31
+ ].join, actual)
32
+
33
+ actual = Ruport::Controller::Table.render_markdown do |r|
34
+ r.data = Ruport::Table([], data: [[:foo, :bar], [1, 2], [3, 4]])
35
+ end
36
+
37
+ assert_equal([
38
+ "|foo|bar|\n",
39
+ "|:--|:--|\n",
40
+ "|1|2|\n",
41
+ "|3|4|\n",
42
+ ].join, actual)
43
+ end
44
+
45
+ def test_escape_virtical_bar
46
+ actual = Ruport::Controller::Table.render_markdown do |r|
47
+ r.data = Ruport::Table([:foo], data: [['foo0|foo1']])
48
+ end
49
+
50
+ assert_equal([
51
+ "|foo|\n",
52
+ "|:--|\n",
53
+ "|foo0&#124;foo1|\n"
54
+ ].join, actual)
55
+ end
56
+
57
+ def test_escape_newline_code
58
+ actual = Ruport::Controller::Table.render_markdown do |r|
59
+ r.data = Ruport::Table([:foo], data: [["foo0\nfoo1"]])
60
+ end
61
+
62
+ assert_equal([
63
+ "|foo|\n",
64
+ "|:--|\n",
65
+ "|foo0<br>foo1|\n"
66
+ ].join, actual)
67
+ end
68
+
69
+ def test_alignment_option
70
+ actual = Ruport::Controller::Table.render_markdown(alignment: :left) do |r|
71
+ r.data = Ruport::Table([:foo, :bar], data: [[1, 2], [3, 4]])
72
+ end
73
+
74
+ assert_equal([
75
+ "|foo|bar|\n",
76
+ "|:--|:--|\n",
77
+ "|1|2|\n",
78
+ "|3|4|\n"
79
+ ].join, actual)
80
+
81
+ actual = Ruport::Controller::Table.render_markdown(alignment: :center) do |r|
82
+ r.data = Ruport::Table([:foo, :bar], data: [[1, 2], [3, 4]])
83
+ end
84
+
85
+ assert_equal([
86
+ "|foo|bar|\n",
87
+ "|:-:|:-:|\n",
88
+ "|1|2|\n",
89
+ "|3|4|\n"
90
+ ].join, actual)
91
+
92
+ actual = Ruport::Controller::Table.render_markdown(alignment: :right) do |r|
93
+ r.data = Ruport::Table([:foo, :bar], data: [[1, 2], [3, 4]])
94
+ end
95
+
96
+ assert_equal([
97
+ "|foo|bar|\n",
98
+ "|--:|--:|\n",
99
+ "|1|2|\n",
100
+ "|3|4|\n"
101
+ ].join, actual)
102
+ end
103
+
104
+ def test_column_alignments_option
105
+ actual = Ruport::Controller::Table.render_markdown(
106
+ column_alignments: { foo: :left, bar: :right, baz: :center }
107
+ ) do |r|
108
+ r.data = Ruport::Table([:foo, :bar, :baz, :qux], data: [[1, 2, 3, 4], [5, 6, 7, 8]])
109
+ end
110
+
111
+ assert_equal([
112
+ "|foo|bar|baz|qux|\n",
113
+ "|:--|--:|:-:|:--|\n",
114
+ "|1|2|3|4|\n",
115
+ "|5|6|7|8|\n"
116
+ ].join, actual)
117
+ end
118
+
119
+ def test_options_hash_override_template
120
+ Ruport::Formatter::Template.create(:a_template) do |format|
121
+ format.table = {
122
+ alignment: :center,
123
+ column_alignments: { foo: :right }
124
+ }
125
+ end
126
+
127
+ actual = Ruport::Controller::Table.render_markdown(
128
+ template: :a_template,
129
+ alignment: :right,
130
+ column_alignments: { foo: :left, bar: :center }
131
+ ) do |r|
132
+ r.data = Ruport::Table([:foo, :bar, :baz], data: [[1, 2, 3], [4, 5, 6]])
133
+ end
134
+
135
+ assert_equal([
136
+ "|foo|bar|baz|\n",
137
+ "|:--|:-:|--:|\n",
138
+ "|1|2|3|\n",
139
+ "|4|5|6|\n"
140
+ ].join, actual)
141
+ end
142
+ end