jsanders-ruport 1.7.1

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.
Files changed (76) hide show
  1. data/AUTHORS +48 -0
  2. data/LICENSE +59 -0
  3. data/README +114 -0
  4. data/Rakefile +93 -0
  5. data/examples/RWEmerson.jpg +0 -0
  6. data/examples/anon.rb +43 -0
  7. data/examples/btree/commaleon/commaleon.rb +263 -0
  8. data/examples/btree/commaleon/sample_data/ticket_count.csv +124 -0
  9. data/examples/btree/commaleon/sample_data/ticket_count2.csv +119 -0
  10. data/examples/centered_pdf_text_box.rb +83 -0
  11. data/examples/data/tattle.dump +82 -0
  12. data/examples/example.csv +3 -0
  13. data/examples/line_plotter.rb +61 -0
  14. data/examples/pdf_report_with_common_base.rb +72 -0
  15. data/examples/png_embed.rb +54 -0
  16. data/examples/roadmap.png +0 -0
  17. data/examples/row_renderer.rb +39 -0
  18. data/examples/simple_pdf_lines.rb +25 -0
  19. data/examples/simple_templating_example.rb +34 -0
  20. data/examples/tattle_ruby_version.rb +39 -0
  21. data/examples/tattle_rubygems_version.rb +37 -0
  22. data/examples/trac_ticket_status.rb +59 -0
  23. data/lib/ruport.rb +127 -0
  24. data/lib/ruport/controller.rb +616 -0
  25. data/lib/ruport/controller/grouping.rb +71 -0
  26. data/lib/ruport/controller/table.rb +54 -0
  27. data/lib/ruport/data.rb +4 -0
  28. data/lib/ruport/data/feeder.rb +111 -0
  29. data/lib/ruport/data/grouping.rb +399 -0
  30. data/lib/ruport/data/record.rb +297 -0
  31. data/lib/ruport/data/table.rb +950 -0
  32. data/lib/ruport/extensions.rb +4 -0
  33. data/lib/ruport/formatter.rb +254 -0
  34. data/lib/ruport/formatter/csv.rb +149 -0
  35. data/lib/ruport/formatter/html.rb +161 -0
  36. data/lib/ruport/formatter/pdf.rb +591 -0
  37. data/lib/ruport/formatter/template.rb +187 -0
  38. data/lib/ruport/formatter/text.rb +231 -0
  39. data/lib/uport.rb +1 -0
  40. data/test/controller_test.rb +743 -0
  41. data/test/csv_formatter_test.rb +164 -0
  42. data/test/data_feeder_test.rb +88 -0
  43. data/test/grouping_test.rb +410 -0
  44. data/test/helpers.rb +11 -0
  45. data/test/html_formatter_test.rb +201 -0
  46. data/test/pdf_formatter_test.rb +354 -0
  47. data/test/record_test.rb +332 -0
  48. data/test/samples/addressbook.csv +6 -0
  49. data/test/samples/data.csv +3 -0
  50. data/test/samples/data.tsv +3 -0
  51. data/test/samples/dates.csv +1409 -0
  52. data/test/samples/erb_test.sql +1 -0
  53. data/test/samples/query_test.sql +1 -0
  54. data/test/samples/ruport_test.sql +8 -0
  55. data/test/samples/test.sql +2 -0
  56. data/test/samples/test.yaml +3 -0
  57. data/test/samples/ticket_count.csv +124 -0
  58. data/test/table_pivot_test.rb +134 -0
  59. data/test/table_test.rb +838 -0
  60. data/test/template_test.rb +48 -0
  61. data/test/text_formatter_test.rb +258 -0
  62. data/util/bench/data/record/bench_as_vs_to.rb +18 -0
  63. data/util/bench/data/record/bench_constructor.rb +46 -0
  64. data/util/bench/data/record/bench_indexing.rb +65 -0
  65. data/util/bench/data/record/bench_reorder.rb +35 -0
  66. data/util/bench/data/record/bench_to_a.rb +19 -0
  67. data/util/bench/data/table/bench_column_manip.rb +103 -0
  68. data/util/bench/data/table/bench_dup.rb +24 -0
  69. data/util/bench/data/table/bench_init.rb +67 -0
  70. data/util/bench/data/table/bench_manip.rb +125 -0
  71. data/util/bench/formatter/bench_csv.rb +14 -0
  72. data/util/bench/formatter/bench_html.rb +14 -0
  73. data/util/bench/formatter/bench_pdf.rb +14 -0
  74. data/util/bench/formatter/bench_text.rb +14 -0
  75. data/util/bench/samples/tattle.csv +1237 -0
  76. metadata +176 -0
data/test/helpers.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "test/unit"
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require "ruport"
4
+ begin; require "rubygems"; rescue LoadError; nil; end
5
+ require "spec-unit"
6
+ require "mocha"
7
+ require "stubba"
8
+
9
+ class Test::Unit::TestCase
10
+ include SpecUnit
11
+ end
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env ruby -w
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
3
+
4
+ class TestRenderHTMLTable < Test::Unit::TestCase
5
+
6
+ def setup
7
+ Ruport::Formatter::Template.create(:simple) do |format|
8
+ format.table = {
9
+ :show_headings => false
10
+ }
11
+ format.grouping = {
12
+ :style => :justified,
13
+ :show_headings => false
14
+ }
15
+ end
16
+ end
17
+
18
+ def test_html_table
19
+ a = Ruport::Formatter::HTML.new
20
+
21
+ actual = a.html_table { "<tr><td>1</td></tr>\n" }
22
+ assert_equal "<table>\n<tr><td>1</td></tr>\n</table>\n", actual
23
+ end
24
+
25
+ def test_render_html_basic
26
+
27
+ actual = Ruport::Controller::Table.render_html { |r|
28
+ r.data = Table([], :data => [[1,2,3],[4,5,6]])
29
+ }
30
+
31
+ assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
32
+ "</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t"+
33
+ "\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
34
+ "\t</tr>\n\t</table>\n",actual)
35
+
36
+ actual = Ruport::Controller::Table.render_html { |r|
37
+ r.data = Table(%w[a b c], :data => [ [1,2,3],[4,5,6]])
38
+ }
39
+
40
+ assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
41
+ "\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>"+
42
+ "\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
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
+
46
+ end
47
+
48
+ def test_render_with_template
49
+ formatter = Ruport::Formatter::HTML.new
50
+ formatter.options = Ruport::Controller::Options.new
51
+ formatter.options.template = :simple
52
+ formatter.apply_template
53
+
54
+ assert_equal false, formatter.options.show_table_headers
55
+
56
+ assert_equal :justified, formatter.options.style
57
+ assert_equal false, formatter.options.show_group_headers
58
+ end
59
+
60
+ def test_options_hashes_override_template
61
+ opts = nil
62
+ table = Table(%w[a b c])
63
+ table.to_html(
64
+ :template => :simple,
65
+ :table_format => {
66
+ :show_headings => true
67
+ },
68
+ :grouping_format => {
69
+ :style => :inline,
70
+ :show_headings => true
71
+ }
72
+ ) do |r|
73
+ opts = r.options
74
+ end
75
+
76
+ assert_equal true, opts.show_table_headers
77
+
78
+ assert_equal :inline, opts.style
79
+ assert_equal true, opts.show_group_headers
80
+ end
81
+
82
+ def test_individual_options_override_template
83
+ opts = nil
84
+ table = Table(%w[a b c])
85
+ table.to_html(
86
+ :template => :simple,
87
+ :show_table_headers => true,
88
+ :style => :inline,
89
+ :show_group_headers => true
90
+ ) do |r|
91
+ opts = r.options
92
+ end
93
+
94
+ assert_equal true, opts.show_table_headers
95
+
96
+ assert_equal :inline, opts.style
97
+ assert_equal true, opts.show_group_headers
98
+ end
99
+ end
100
+
101
+
102
+ class TestRenderHTMLRow < Test::Unit::TestCase
103
+
104
+ def test_render_html_row
105
+ actual = Ruport::Controller::Row.render_html { |r| r.data = [1,2,3] }
106
+ assert_equal("\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
107
+ "</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n",actual)
108
+ end
109
+ end
110
+
111
+
112
+ class TestRenderHTMLGroup < Test::Unit::TestCase
113
+
114
+ def test_render_html_group
115
+ group = Ruport::Data::Group.new(:name => 'test',
116
+ :data => [[1,2,3],[4,5,6]],
117
+ :column_names => %w[a b c])
118
+ actual = Ruport::Controller::Group.render(:html, :data => group)
119
+ assert_equal "\t<p>test</p>\n"+
120
+ "\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
121
+ "\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>"+
122
+ "\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
123
+ "\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
124
+ "\t</tr>\n\t</table>\n", actual
125
+ end
126
+
127
+ def test_render_html_group_without_headers
128
+ group = Ruport::Data::Group.new(:name => 'test',
129
+ :data => [[1,2,3],[4,5,6]],
130
+ :column_names => %w[a b c])
131
+ actual = Ruport::Controller::Group.render(:html, :data => group,
132
+ :show_table_headers => false)
133
+ assert_equal "\t<p>test</p>\n\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>"+
134
+ "\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
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
+ "\t</tr>\n\t</table>\n", actual
137
+ end
138
+ end
139
+
140
+
141
+ class TestRenderHTMLGrouping < Test::Unit::TestCase
142
+
143
+ def test_render_html_grouping
144
+ table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
145
+ g = Grouping(table,:by => "a")
146
+ actual = Ruport::Controller::Grouping.render(:html, :data => g,
147
+ :show_table_headers => false)
148
+
149
+ assert_equal "\t<p>1</p>\n\t<table>\n\t\t<tr>\n\t\t\t<td>2</td>\n"+
150
+ "\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t"+
151
+ "<td>3</td>\n\t\t</tr>\n\t</table>\n\n\t<p>2</p>\n\t<table>\n\t\t<tr>"+
152
+ "\n\t\t\t<td>7</td>\n\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n\n", actual
153
+ end
154
+
155
+ def test_render_html_grouping_with_table_headers
156
+ table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
157
+ g = Grouping(table,:by => "a")
158
+ actual = Ruport::Controller::Grouping.render(:html, :data => g)
159
+
160
+ assert_equal "\t<p>1</p>\n\t<table>\n\t\t<tr>\n\t\t\t<th>b</th>\n"+
161
+ "\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>"+
162
+ "2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t"+
163
+ "\t<td>1</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t</table>\n\n"+
164
+ "\t<p>2</p>\n\t<table>\n\t\t<tr>\n\t\t\t<th>b</th>\n\t\t"+
165
+ "\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>7</td>\n"+
166
+ "\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n\n", actual
167
+ end
168
+
169
+ def test_render_justified_html_grouping
170
+ table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
171
+ g = Grouping(table,:by => "a")
172
+ actual = Ruport::Controller::Grouping.render(:html, :data => g,
173
+ :style => :justified)
174
+
175
+ assert_equal "\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>\n"+
176
+ "\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+
177
+ "<td class=\"groupName\">1</td>\n\t\t\t<td>"+
178
+ "2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+
179
+ "<td>&nbsp;</td>\n\t\t\t<td>1</td>\n\t\t\t<td>3</td>"+
180
+ "\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+
181
+ "<td class=\"groupName\">2</td>\n\t\t\t<td>7</td>\n"+
182
+ "\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n", actual
183
+ end
184
+ end
185
+
186
+
187
+ class TestHTMLFormatterHelpers < Test::Unit::TestCase
188
+ begin
189
+ require "rubygems"
190
+ rescue LoadError
191
+ nil
192
+ end
193
+
194
+ def test_textile
195
+ require "redcloth"
196
+ a = Ruport::Formatter::HTML.new
197
+ assert_equal "<p><strong>foo</strong></p>", a.textile("*foo*")
198
+ rescue LoadError
199
+ STDERR.puts "Skipping textile test... needs redcloth"
200
+ end
201
+ end
@@ -0,0 +1,354 @@
1
+ #!/usr/bin/env ruby -w
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
3
+
4
+ class TestRenderPDFTable < Test::Unit::TestCase
5
+
6
+ def setup
7
+ Ruport::Formatter::Template.create(:simple) do |format|
8
+ format.page = {
9
+ :size => "LETTER",
10
+ :layout => :landscape
11
+ }
12
+ format.text = {
13
+ :font_size => 16
14
+ }
15
+ format.table = {
16
+ :show_headings => false
17
+ }
18
+ format.column = {
19
+ :alignment => :center,
20
+ :width => 50
21
+ }
22
+ format.heading = {
23
+ :alignment => :right,
24
+ :bold => false,
25
+ :title => "Test"
26
+ }
27
+ format.grouping = {
28
+ :style => :separated
29
+ }
30
+ end
31
+ end
32
+
33
+ def test_render_pdf_basic
34
+ # can't render without column names
35
+ data = Table([], :data => [[1,2],[3,4]])
36
+ assert_raise(Ruport::FormatterError) do
37
+ data.to_pdf
38
+ end
39
+
40
+ data.column_names = %w[a b]
41
+ assert_nothing_raised { data.to_pdf }
42
+
43
+ assert_nothing_raised { Table(%w[a b c]).to_pdf }
44
+ end
45
+
46
+ # this is mostly to check that the transaction hack gets called
47
+ def test_relatively_large_pdf
48
+ table = Table(File.join(File.expand_path(File.dirname(__FILE__)),
49
+ %w[samples dates.csv]))
50
+ table.reduce(0..99)
51
+ assert_nothing_raised { table.to_pdf }
52
+ end
53
+
54
+ # this is just to make sure that the column_opts code is being called.
55
+ # FIXME: add mocks to be sure
56
+ def test_table_with_options
57
+ data = Table(%w[a b], :data => [[1,2],[3,4]])
58
+ assert_nothing_raised do
59
+ data.to_pdf(:table_format => {
60
+ :column_options => { :justification => :center } } )
61
+ end
62
+ end
63
+
64
+ def test_render_with_template
65
+ formatter = Ruport::Formatter::PDF.new
66
+ formatter.options = Ruport::Controller::Options.new
67
+ formatter.options.template = :simple
68
+ formatter.apply_template
69
+
70
+ assert_equal "LETTER", formatter.options.paper_size
71
+ assert_equal :landscape, formatter.options.paper_orientation
72
+
73
+ assert_equal 16, formatter.options.text_format[:font_size]
74
+
75
+ assert_equal false, formatter.options.table_format[:show_headings]
76
+
77
+ assert_equal :center,
78
+ formatter.options.table_format[:column_options][:justification]
79
+ assert_equal 50,
80
+ formatter.options.table_format[:column_options][:width]
81
+
82
+ assert_equal :right,
83
+ formatter.options.table_format[:column_options][:heading][:justification]
84
+ assert_equal false,
85
+ formatter.options.table_format[:column_options][:heading][:bold]
86
+ assert_equal "Test",
87
+ formatter.options.table_format[:column_options][:heading][:title]
88
+
89
+ assert_equal :separated, formatter.options.style
90
+ end
91
+
92
+ def test_options_hashes_override_template
93
+ opts = nil
94
+ table = Table(%w[a b c])
95
+ table.to_pdf(
96
+ :template => :simple,
97
+ :page_format => {
98
+ :size => "LEGAL",
99
+ :layout => :portrait
100
+ },
101
+ :text_format => {
102
+ :font_size => 20
103
+ },
104
+ :table_format => {
105
+ :show_headings => true
106
+ },
107
+ :column_format => {
108
+ :alignment => :left,
109
+ :width => 25
110
+ },
111
+ :heading_format => {
112
+ :alignment => :left,
113
+ :bold => true,
114
+ :title => "Replace"
115
+ },
116
+ :grouping_format => {
117
+ :style => :inline
118
+ }
119
+ ) do |r|
120
+ opts = r.options
121
+ end
122
+
123
+ assert_equal "LEGAL", opts.paper_size
124
+ assert_equal :portrait, opts.paper_orientation
125
+
126
+ assert_equal 20, opts.text_format[:font_size]
127
+
128
+ assert_equal true, opts.table_format[:show_headings]
129
+
130
+ assert_equal :left, opts.table_format[:column_options][:justification]
131
+ assert_equal 25, opts.table_format[:column_options][:width]
132
+
133
+ assert_equal :left,
134
+ opts.table_format[:column_options][:heading][:justification]
135
+ assert_equal true, opts.table_format[:column_options][:heading][:bold]
136
+ assert_equal "Replace", opts.table_format[:column_options][:heading][:title]
137
+
138
+ assert_equal :inline, opts.style
139
+ end
140
+
141
+ def test_individual_options_override_template
142
+ opts = nil
143
+ table = Table(%w[a b c])
144
+ table.to_pdf(
145
+ :template => :simple,
146
+ :paper_size => "LEGAL",
147
+ :paper_orientation => :portrait,
148
+ :text_format => { :font_size => 20 },
149
+ :table_format => {
150
+ :show_headings => true,
151
+ :column_options => {
152
+ :justification => :left,
153
+ :width => 25,
154
+ :heading => {
155
+ :justification => :left,
156
+ :bold => true,
157
+ :title => "Replace"
158
+ }
159
+ }
160
+ },
161
+ :style => :inline
162
+ ) do |r|
163
+ opts = r.options
164
+ end
165
+
166
+ assert_equal "LEGAL", opts.paper_size
167
+ assert_equal :portrait, opts.paper_orientation
168
+
169
+ assert_equal 20, opts.text_format[:font_size]
170
+
171
+ assert_equal true, opts.table_format[:show_headings]
172
+
173
+ assert_equal :left, opts.table_format[:column_options][:justification]
174
+ assert_equal 25, opts.table_format[:column_options][:width]
175
+
176
+ assert_equal :left,
177
+ opts.table_format[:column_options][:heading][:justification]
178
+ assert_equal true, opts.table_format[:column_options][:heading][:bold]
179
+ assert_equal "Replace", opts.table_format[:column_options][:heading][:title]
180
+
181
+ assert_equal :inline, opts.style
182
+ end
183
+
184
+ #--------BUG TRAPS--------#
185
+
186
+ # PDF::SimpleTable does not handle symbols as column names
187
+ # Ruport should smartly fix this surprising behaviour (#283)
188
+ def test_tables_should_render_with_symbol_column_name
189
+ data = Table([:a,:b,:c], :data => [[1,2,3],[4,5,6]])
190
+ assert_nothing_raised { data.to_pdf }
191
+ end
192
+
193
+ # draw_table has destructive behavior on nested rendering options (#359)
194
+ def test_draw_table_should_not_destroy_nested_rendering_options
195
+ f = Ruport::Formatter::PDF.new
196
+ f.options = Ruport::Controller::Options.new
197
+ f.options[:table_format] =
198
+ { :column_options => { :heading => {:justification => :center }}}
199
+ f.draw_table Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
200
+ assert_equal({ :justification => :center },
201
+ f.options[:table_format][:column_options][:heading])
202
+ end
203
+
204
+ end
205
+
206
+ class TestRenderPDFGrouping < Test::Unit::TestCase
207
+
208
+ #--------BUG TRAPS----------#
209
+
210
+ # As of Ruport 0.10.0, PDF's justified group output was throwing
211
+ # UnknownFormatError (#288)
212
+ def test_group_styles_should_not_throw_error
213
+ table = Table(%w[a b c], :data => [[1,2,3],[4,5,6],[1,7,9]])
214
+ grouping = Grouping(table,:by => "a")
215
+ assert_nothing_raised { grouping.to_pdf }
216
+ assert_nothing_raised { grouping.to_pdf(:style => :inline) }
217
+ assert_nothing_raised { grouping.to_pdf(:style => :offset) }
218
+ assert_nothing_raised { grouping.to_pdf(:style => :justified) }
219
+ assert_nothing_raised { grouping.to_pdf(:style => :separated) }
220
+ assert_raises(NotImplementedError) do
221
+ grouping.to_pdf(:style => :red_snapper)
222
+ end
223
+ end
224
+
225
+ def test_grouping_should_have_consistent_font_size
226
+ a = Table(%w[a b c]) << %w[eye like chicken] << %w[eye like liver] <<
227
+ %w[meow mix meow ] << %w[mix please deliver ]
228
+ b = Grouping(a, :by => "a")
229
+ splat = b.to_pdf.split("\n")
230
+ splat.grep(/meow/).each do |m|
231
+ assert_equal '10.0', m.split[5]
232
+ end
233
+ splat.grep(/mix/).each do |m|
234
+ assert_equal '10.0', m.split[5]
235
+ end
236
+ splat.grep(/eye/).each do |m|
237
+ assert_equal '10.0', m.split[5]
238
+ end
239
+ end
240
+
241
+ end
242
+
243
+ class TestPDFFormatterHelpers < Test::Unit::TestCase
244
+
245
+ def test_boundaries
246
+ a = Ruport::Formatter::PDF.new
247
+
248
+ assert_equal 36, a.left_boundary
249
+ a.pdf_writer.left_margin = 50
250
+ assert_equal 50, a.left_boundary
251
+
252
+ assert_equal 576, a.right_boundary
253
+ a.pdf_writer.right_margin -= 10
254
+ assert_equal 586, a.right_boundary
255
+
256
+ assert_equal 756, a.top_boundary
257
+ a.pdf_writer.top_margin -= 10
258
+ assert_equal 766, a.top_boundary
259
+
260
+ assert_equal 36, a.bottom_boundary
261
+ a.pdf_writer.bottom_margin -= 10
262
+ assert_equal 26, a.bottom_boundary
263
+ end
264
+
265
+ def test_move_cursor
266
+ a = Ruport::Formatter::PDF.new
267
+ a.move_cursor_to(500)
268
+ assert_equal(500,a.cursor)
269
+ a.move_cursor(-25)
270
+ assert_equal(475,a.cursor)
271
+ a.move_cursor(50)
272
+ assert_equal(525,a.cursor)
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
283
+
284
+ def test_padding
285
+ a = Ruport::Formatter::PDF.new
286
+ a.move_cursor_to(100)
287
+
288
+ # padding on top and bottom
289
+ a.pad(10) do
290
+ assert_equal 90, a.cursor
291
+ a.move_cursor(-10)
292
+ assert_equal 80, a.cursor
293
+ end
294
+ assert_equal(70,a.cursor)
295
+
296
+ a.move_cursor_to(100)
297
+
298
+ # padding just on top
299
+ a.pad_top(10) do
300
+ assert_equal 90, a.cursor
301
+ a.move_cursor(-10)
302
+ assert_equal 80, a.cursor
303
+ end
304
+
305
+ assert_equal 80, a.cursor
306
+
307
+ a.move_cursor_to(100)
308
+
309
+ # padding just on bottom
310
+ a.pad_bottom(10) do
311
+ assert_equal 100, a.cursor
312
+ a.move_cursor(-10)
313
+ assert_equal 90, a.cursor
314
+ end
315
+
316
+ assert_equal 80, a.cursor
317
+ end
318
+
319
+ def test_draw_text_retains_cursor
320
+ a = Ruport::Formatter::PDF.new
321
+ a.move_cursor_to(100)
322
+
323
+ a.draw_text "foo", :left => a.left_boundary
324
+ assert_equal 100, a.cursor
325
+
326
+ a.draw_text "foo", :left => a.left_boundary + 50, :y => 500
327
+ assert_equal 100, a.cursor
328
+ end
329
+ end
330
+
331
+ class SimpleController < Ruport::Controller
332
+ stage :foo
333
+
334
+ class PDF < Ruport::Formatter::PDF
335
+ renders :pdf, :for => SimpleController
336
+
337
+ build :foo do
338
+ add_text "Blah"
339
+ end
340
+ end
341
+ end
342
+
343
+ class TestPDFFinalize < Test::Unit::TestCase
344
+
345
+ context "When rendering a PDF" do
346
+ def specify_finalize_should_be_called
347
+ SimpleController.render_pdf do |r|
348
+ r.formatter.expects(:render_pdf)
349
+ end
350
+ end
351
+ end
352
+
353
+ end
354
+