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.
@@ -20,7 +20,7 @@ class TestGroup < Test::Unit::TestCase
20
20
  end
21
21
 
22
22
  def test_should_copy_group
23
- @group.create_subgroups("a")
23
+ @group.send(:create_subgroups, "a")
24
24
  copy = @group.dup
25
25
  assert_equal 'test', copy.name
26
26
  assert_equal Ruport::Data::Record.new([1,2,3],:attributes => %w[a b c]),
@@ -34,7 +34,7 @@ class TestGroup < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  def test_eql
37
- table = [[1,2,3]].to_table(%w[a b c])
37
+ table = Table(%w[a b c], :data => [[1,2,3]])
38
38
 
39
39
  group2 = Ruport::Data::Group.new(:name => 'test',
40
40
  :data => [[1,2,3]],
@@ -47,7 +47,7 @@ class TestGroup < Test::Unit::TestCase
47
47
 
48
48
  def test_create_subgroups
49
49
  group = @group << [4,5,6]
50
- group.create_subgroups("a")
50
+ group.send(:create_subgroups, "a")
51
51
  b = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
52
52
  :column_names => %w[b c],
53
53
  :name => 1 ),
@@ -56,7 +56,7 @@ class TestGroup < Test::Unit::TestCase
56
56
  :name => 4 ) }
57
57
  assert_equal b, group.subgroups
58
58
 
59
- group.create_subgroups("b")
59
+ group.send(:create_subgroups, "b")
60
60
  c = { 2 => Ruport::Data::Group.new( :data => [[3]],
61
61
  :column_names => %w[c],
62
62
  :name => 2 ) }
@@ -114,12 +114,12 @@ end
114
114
  class TestGrouping < Test::Unit::TestCase
115
115
 
116
116
  def setup
117
- table = [[1,2,3],[4,5,6]].to_table(%w[a b c])
117
+ table = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
118
118
  @grouping = Ruport::Data::Grouping.new(table, :by => "a")
119
119
  end
120
120
 
121
121
  def test_grouping_constructor
122
- a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
122
+ a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
123
123
  b = Ruport::Data::Grouping.new(a, :by => "a")
124
124
  c = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
125
125
  :column_names => %w[b c],
@@ -174,7 +174,7 @@ class TestGrouping < Test::Unit::TestCase
174
174
  end
175
175
 
176
176
  def test_append
177
- a =[[1,2,3],[4,5,6]].to_table(%w[a b c])
177
+ a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
178
178
  @grouping << a.to_group("red snapper")
179
179
  assert_equal @grouping["red snapper"], a.to_group("red snapper")
180
180
 
@@ -186,7 +186,7 @@ class TestGrouping < Test::Unit::TestCase
186
186
  end
187
187
 
188
188
  def test_grouping_on_multiple_columns
189
- a = [[1,2,3,4],[4,5,6,7]].to_table(%w[a b c d])
189
+ a = Table(%w[a b c d], :data => [[1,2,3,4],[4,5,6,7]])
190
190
  b = Ruport::Data::Grouping.new(a, :by => %w[a b c])
191
191
  c = { 1 => Ruport::Data::Group.new( :data => [[2,3,4]],
192
192
  :column_names => %w[b c d],
@@ -366,7 +366,7 @@ end
366
366
  class TestGroupingRendering < Test::Unit::TestCase
367
367
 
368
368
  def setup
369
- table = [[1,2,3],[4,5,6]].to_table(%w[a b c])
369
+ table = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
370
370
  @grouping = Ruport::Data::Grouping.new(table, :by => "a")
371
371
  end
372
372
 
@@ -397,7 +397,7 @@ class TestGroupingKernelHacks < Test::Unit::TestCase
397
397
  end
398
398
 
399
399
  def test_grouping_kernel_hack
400
- table = [[1,2,3],[4,5,6]].to_table(%w[a b c])
400
+ table = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
401
401
  grouping = Ruport::Data::Grouping.new(table, :by => "a")
402
402
  a = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
403
403
  :column_names => %w[b c],
data/test/helpers.rb CHANGED
@@ -2,6 +2,8 @@ require "test/unit"
2
2
  require "ruport"
3
3
  begin; require "rubygems"; rescue LoadError; nil; end
4
4
  require "spec-unit"
5
+ require "mocha"
6
+ require "stubba"
5
7
 
6
8
  class Test::Unit::TestCase
7
9
  include SpecUnit
@@ -4,11 +4,11 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
4
4
  class TestRenderHTMLTable < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- Ruport::Formatter::Template.create(:simple) do |t|
8
- t.table_format = {
7
+ Ruport::Formatter::Template.create(:simple) do |format|
8
+ format.table = {
9
9
  :show_headings => false
10
10
  }
11
- t.grouping_format = {
11
+ format.grouping = {
12
12
  :style => :justified,
13
13
  :show_headings => false
14
14
  }
@@ -25,7 +25,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
25
25
  def test_render_html_basic
26
26
 
27
27
  actual = Ruport::Renderer::Table.render_html { |r|
28
- r.data = [[1,2,3],[4,5,6]].to_table
28
+ r.data = Table([], :data => [[1,2,3],[4,5,6]])
29
29
  }
30
30
 
31
31
  assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
@@ -34,7 +34,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
34
34
  "\t</tr>\n\t</table>",actual)
35
35
 
36
36
  actual = Ruport::Renderer::Table.render_html { |r|
37
- r.data = [ [1,2,3],[4,5,6]].to_table(%w[a b c])
37
+ r.data = 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<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
@@ -4,27 +4,27 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
4
4
  class TestRenderPDFTable < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- Ruport::Formatter::Template.create(:simple) do |t|
8
- t.page_format = {
7
+ Ruport::Formatter::Template.create(:simple) do |format|
8
+ format.page = {
9
9
  :size => "LETTER",
10
10
  :layout => :landscape
11
11
  }
12
- t.text_format = {
12
+ format.text = {
13
13
  :font_size => 16
14
14
  }
15
- t.table_format = {
15
+ format.table = {
16
16
  :show_headings => false
17
17
  }
18
- t.column_format = {
18
+ format.column = {
19
19
  :alignment => :center,
20
20
  :width => 50
21
21
  }
22
- t.heading_format = {
22
+ format.heading = {
23
23
  :alignment => :right,
24
24
  :bold => false,
25
25
  :title => "Test"
26
26
  }
27
- t.grouping_format = {
27
+ format.grouping = {
28
28
  :style => :separated
29
29
  }
30
30
  end
@@ -32,7 +32,7 @@ class TestRenderPDFTable < Test::Unit::TestCase
32
32
 
33
33
  def test_render_pdf_basic
34
34
  # can't render without column names
35
- data = [[1,2],[3,4]].to_table
35
+ data = Table([], :data => [[1,2],[3,4]])
36
36
  assert_raise(Ruport::FormatterError) do
37
37
  data.to_pdf
38
38
  end
@@ -54,7 +54,7 @@ class TestRenderPDFTable < Test::Unit::TestCase
54
54
  # this is just to make sure that the column_opts code is being called.
55
55
  # FIXME: add mocks to be sure
56
56
  def test_table_with_options
57
- data = [[1,2],[3,4]].to_table(%w[a b])
57
+ data = Table(%w[a b], :data => [[1,2],[3,4]])
58
58
  assert_nothing_raised do
59
59
  data.to_pdf(:table_format => {
60
60
  :column_options => { :justification => :center } } )
@@ -186,9 +186,9 @@ class TestRenderPDFTable < Test::Unit::TestCase
186
186
  # PDF::SimpleTable does not handle symbols as column names
187
187
  # Ruport should smartly fix this surprising behaviour (#283)
188
188
  def test_tables_should_render_with_symbol_column_name
189
- data = [[1,2,3],[4,5,6]].to_table([:a,:b,:c])
189
+ data = Table([:a,:b,:c], :data => [[1,2,3],[4,5,6]])
190
190
  assert_nothing_raised { data.to_pdf }
191
- end
191
+ end
192
192
 
193
193
  # draw_table has destructive behavior on nested rendering options (#359)
194
194
  def test_draw_table_should_not_destroy_nested_rendering_options
@@ -196,11 +196,11 @@ class TestRenderPDFTable < Test::Unit::TestCase
196
196
  f.options = Ruport::Renderer::Options.new
197
197
  f.options[:table_format] =
198
198
  { :column_options => { :heading => {:justification => :center }}}
199
- f.draw_table [[1,2,3],[4,5,6]].to_table(%w[a b c])
199
+ f.draw_table Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
200
200
  assert_equal({ :justification => :center },
201
201
  f.options[:table_format][:column_options][:heading])
202
202
  end
203
-
203
+
204
204
  end
205
205
 
206
206
  class TestRenderPDFGrouping < Test::Unit::TestCase
@@ -210,7 +210,7 @@ class TestRenderPDFGrouping < Test::Unit::TestCase
210
210
  # As of Ruport 0.10.0, PDF's justified group output was throwing
211
211
  # UnknownFormatError (#288)
212
212
  def test_group_styles_should_not_throw_error
213
- table = [[1,2,3],[4,5,6],[1,7,9]].to_table(%w[a b c])
213
+ table = Table(%w[a b c], :data => [[1,2,3],[4,5,6],[1,7,9]])
214
214
  grouping = Grouping(table,:by => "a")
215
215
  assert_nothing_raised { grouping.to_pdf }
216
216
  assert_nothing_raised { grouping.to_pdf(:style => :inline) }
@@ -271,6 +271,15 @@ class TestPDFFormatterHelpers < Test::Unit::TestCase
271
271
  a.move_cursor(50)
272
272
  assert_equal(525,a.cursor)
273
273
  end
274
+
275
+ def test_move_up
276
+ a = Ruport::Formatter::PDF.new
277
+ a.move_cursor_to(500)
278
+ a.move_up(50)
279
+ assert_equal(550,a.cursor)
280
+ a.move_down(100)
281
+ assert_equal(450,a.cursor)
282
+ end
274
283
 
275
284
  def test_padding
276
285
  a = Ruport::Formatter::PDF.new
data/test/record_test.rb CHANGED
@@ -86,6 +86,11 @@ class TestRecord < Test::Unit::TestCase
86
86
  assert_equal @record.b, @record["b"]
87
87
  assert_equal @record.c, @record["c"]
88
88
  assert_equal @record.d, @record["d"]
89
+ end
90
+
91
+ def test_can_has_id
92
+ record = Ruport::Data::Record.new(:id => 12345)
93
+ assert_equal 12345, record.id
89
94
  end
90
95
 
91
96
  def test_nonexistent_accessor
@@ -63,27 +63,62 @@ class DummyText < Ruport::Formatter
63
63
  end
64
64
  end
65
65
 
66
+ class VanillaBinary < Ruport::Formatter
67
+ renders :bin, :for => VanillaRenderer
68
+ save_as_binary_file
69
+ end
70
+
66
71
 
67
72
  class TestRenderer < Test::Unit::TestCase
68
73
 
74
+ def teardown
75
+ Ruport::Formatter::Template.instance_variable_set(:@templates, nil)
76
+ end
77
+
69
78
  def test_trivial
70
79
  actual = OldSchoolRenderer.render(:text)
71
80
  assert_equal "header\nbody\nfooter\n", actual
72
81
  end
73
82
 
74
83
  context "when using templates" do
75
- def specify_apply_template_should_be_called
76
- Ruport::Formatter::Template.create(:stub)
77
- Table(%w[a b c]).to_csv(:template => :stub) do |r|
78
- r.formatter.expects(:apply_template)
79
- end
80
- end
81
-
82
- def specify_undefined_template_should_throw_sensible_error
83
- assert_raises(Ruport::Formatter::TemplateNotDefined) do
84
- Table(%w[a b c]).to_csv(:template => :sub)
85
- end
86
- end
84
+ def specify_apply_template_should_be_called
85
+ Ruport::Formatter::Template.create(:stub)
86
+ Table(%w[a b c]).to_csv(:template => :stub) do |r|
87
+ r.formatter.expects(:apply_template)
88
+ end
89
+ end
90
+
91
+ def specify_undefined_template_should_throw_sensible_error
92
+ assert_raises(Ruport::Formatter::TemplateNotDefined) do
93
+ Table(%w[a b c]).to_csv(:template => :sub)
94
+ end
95
+ end
96
+ end
97
+
98
+ context "when using default templates" do
99
+ def specify_default_template_should_be_called
100
+ Ruport::Formatter::Template.create(:default)
101
+ Table(%w[a b c]).to_csv do |r|
102
+ r.formatter.expects(:apply_template)
103
+ assert r.formatter.template == Ruport::Formatter::Template[:default]
104
+ end
105
+ end
106
+
107
+ def specify_specific_should_override_default
108
+ Ruport::Formatter::Template.create(:default)
109
+ Ruport::Formatter::Template.create(:stub)
110
+ Table(%w[a b c]).to_csv(:template => :stub) do |r|
111
+ r.formatter.expects(:apply_template)
112
+ assert r.formatter.template == Ruport::Formatter::Template[:stub]
113
+ end
114
+ end
115
+
116
+ def specify_should_be_able_to_disable_templates
117
+ Ruport::Formatter::Template.create(:default)
118
+ Table(%w[a b c]).to_csv(:template => false) do |r|
119
+ r.formatter.expects(:apply_template).never
120
+ end
121
+ end
87
122
  end
88
123
 
89
124
  def test_using_io
@@ -96,19 +131,23 @@ class TestRenderer < Test::Unit::TestCase
96
131
  end
97
132
 
98
133
  def test_using_file
99
- begin
100
- require "mocha"
101
- require "stubba"
102
- rescue LoadError
103
- $stderr.puts "Warning: Mocha not found -- skipping some Renderer tests"
104
- end
105
- if Object.const_defined?(:Mocha)
106
- f = []
107
- File.expects(:open).yields(f)
108
- a = OldSchoolRenderer.render(:text, :file => "foo.text")
109
- assert_equal "header\nbody\nfooter\n", f[0]
110
- end
134
+ f = []
135
+ File.expects(:open).yields(f)
136
+ a = OldSchoolRenderer.render(:text, :file => "foo.text")
137
+ assert_equal "header\nbody\nfooter\n", f[0]
138
+
139
+ f = []
140
+ File.expects(:open).with("blah","wb").yields(f)
141
+ VanillaRenderer.render(:bin, :file => "blah")
142
+ end
143
+
144
+ def test_using_file_via_rendering_tools
145
+ f = []
146
+ File.expects(:open).yields(f)
147
+ Table(%w[a b c], :data => [[1,2,3],[4,5,6]]).save_as("foo.csv")
148
+ assert_equal "a,b,c\n1,2,3\n4,5,6\n", f[0]
111
149
  end
150
+
112
151
 
113
152
  def test_formats
114
153
  assert_equal( {}, Ruport::Renderer.formats )
@@ -160,6 +199,36 @@ class TestRenderer < Test::Unit::TestCase
160
199
  end
161
200
 
162
201
 
202
+ class TestFormatterUsingBuild < Test::Unit::TestCase
203
+ # This formatter uses the build syntax
204
+ class UsesBuild < Ruport::Formatter
205
+ renders :text_using_build, :for => VanillaRenderer
206
+
207
+ build :header do
208
+ output << "header\n"
209
+ end
210
+
211
+ build :body do
212
+ output << "body\n"
213
+ end
214
+
215
+ build :footer do
216
+ output << "footer\n"
217
+ end
218
+ end
219
+
220
+ def test_should_render_using_build_syntax
221
+ assert_equal "header\nbody\nfooter\n",
222
+ VanillaRenderer.render_text_using_build
223
+ VanillaRenderer.render_text_using_build do |rend|
224
+ assert rend.formatter.respond_to?(:build_header)
225
+ assert rend.formatter.respond_to?(:build_body)
226
+ assert rend.formatter.respond_to?(:build_footer)
227
+ end
228
+ end
229
+ end
230
+
231
+
163
232
  class TestFormatterWithLayout < Test::Unit::TestCase
164
233
  # This formatter is meant to check out a special case in Ruport's renderer,
165
234
  # in which a layout method is called and yielded to when defined
@@ -190,13 +259,10 @@ end
190
259
  class TestRendererWithManyHooks < Test::Unit::TestCase
191
260
  # This provides a way to check several hooks that Renderer supports
192
261
  class RendererWithManyHooks < Ruport::Renderer
193
-
194
262
  add_format DummyText, :text
195
263
 
196
264
  prepare :document
197
265
 
198
- option :subtitle, :subsubtitle
199
-
200
266
  stage :header
201
267
  stage :body
202
268
  stage :footer
@@ -264,13 +330,6 @@ class TestRendererWithManyHooks < Test::Unit::TestCase
264
330
  assert_equal "pheader\nbody\nfooter\nf", actual
265
331
  end
266
332
 
267
- def test_option_helper
268
- RendererWithManyHooks.render_text do |r|
269
- r.subtitle = "Test Report"
270
- assert_equal "Test Report", r.options.subtitle
271
- end
272
- end
273
-
274
333
  def test_required_option_helper
275
334
  a = RendererWithManyHooks.dup
276
335
  a.required_option :title
@@ -295,9 +354,6 @@ end
295
354
  class TestRendererWithRunHook < Test::Unit::TestCase
296
355
 
297
356
  class RendererWithRunHook < Ruport::Renderer
298
-
299
- include AutoRunner
300
-
301
357
  add_format DummyText, :text
302
358
 
303
359
  required_option :foo,:bar
@@ -307,6 +363,7 @@ class TestRendererWithRunHook < Test::Unit::TestCase
307
363
 
308
364
  def run
309
365
  formatter.output << "|"
366
+ super
310
367
  end
311
368
 
312
369
  end
@@ -428,14 +485,14 @@ end
428
485
  class TestOptionReaders < Test::Unit::TestCase
429
486
 
430
487
  class RendererForCheckingOptionReaders < Ruport::Renderer
431
- option :foo
488
+ required_option :foo
432
489
  end
433
490
 
434
491
  class RendererForCheckingPassivity < Ruport::Renderer
435
492
  def foo
436
493
  "apples"
437
494
  end
438
- option :foo
495
+ required_option :foo
439
496
  end
440
497
 
441
498
  def setup
@@ -463,11 +520,10 @@ end
463
520
  class TestSetupOrdering < Test::Unit::TestCase
464
521
 
465
522
  class RendererWithSetup < Ruport::Renderer
466
- option :foo
467
- stage :bar
468
- def setup
469
- foo.capitalize!
470
- end
523
+ stage :bar
524
+ def setup
525
+ options.foo.capitalize!
526
+ end
471
527
  end
472
528
 
473
529
  class BasicFormatter < Ruport::Formatter
@@ -479,12 +535,12 @@ class TestSetupOrdering < Test::Unit::TestCase
479
535
  end
480
536
 
481
537
  def test_render_hash_options_should_be_called_before_setup
482
- assert_equal "Hello", RendererWithSetup.render_text(:foo => "hello")
538
+ assert_equal "Hello", RendererWithSetup.render_text(:foo => "hello")
483
539
  end
484
540
 
485
541
  def test_render_block_should_be_called_before_setup
486
- assert_equal "Hello",
487
- RendererWithSetup.render_text { |r| r.foo = "hello" }
542
+ assert_equal "Hello",
543
+ RendererWithSetup.render_text { |r| r.options.foo = "hello" }
488
544
  end
489
545
 
490
546
  end