ruport 1.4.0 → 1.6.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 +3 -3
- data/examples/anon.rb +43 -0
- data/examples/btree/commaleon/commaleon.rb +9 -9
- data/examples/centered_pdf_text_box.rb +7 -7
- data/examples/line_plotter.rb +1 -1
- data/examples/pdf_report_with_common_base.rb +4 -4
- data/examples/png_embed.rb +4 -4
- data/examples/row_renderer.rb +4 -4
- data/examples/simple_pdf_lines.rb +1 -1
- data/examples/trac_ticket_status.rb +1 -1
- data/lib/ruport.rb +15 -3
- data/lib/ruport/{renderer.rb → controller.rb} +183 -87
- data/lib/ruport/{renderer → controller}/grouping.rb +5 -5
- data/lib/ruport/{renderer → controller}/table.rb +5 -5
- data/lib/ruport/data/grouping.rb +2 -2
- data/lib/ruport/data/record.rb +4 -2
- data/lib/ruport/data/table.rb +128 -4
- data/lib/ruport/formatter.rb +36 -37
- data/lib/ruport/formatter/csv.rb +37 -20
- data/lib/ruport/formatter/html.rb +11 -12
- data/lib/ruport/formatter/pdf.rb +10 -6
- data/lib/ruport/formatter/template.rb +1 -1
- data/lib/ruport/formatter/text.rb +8 -15
- data/test/{renderer_test.rb → controller_test.rb} +179 -74
- data/test/csv_formatter_test.rb +6 -6
- data/test/grouping_test.rb +4 -4
- data/test/helpers.rb +1 -0
- data/test/html_formatter_test.rb +18 -18
- data/test/pdf_formatter_test.rb +28 -3
- data/test/record_test.rb +2 -2
- data/test/table_pivot_test.rb +134 -0
- data/test/table_test.rb +10 -3
- data/test/text_formatter_test.rb +6 -6
- data/util/bench/data/record/bench_as_vs_to.rb +1 -1
- metadata +19 -16
data/test/csv_formatter_test.rb
CHANGED
@@ -3,7 +3,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
|
3
3
|
|
4
4
|
class TestRenderCSVRow < Test::Unit::TestCase
|
5
5
|
def test_render_csv_row
|
6
|
-
actual = Ruport::
|
6
|
+
actual = Ruport::Controller::Row.render_csv(:data => [1,2,3])
|
7
7
|
assert_equal("1,2,3\n", actual)
|
8
8
|
end
|
9
9
|
end
|
@@ -24,12 +24,12 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_render_csv_table
|
27
|
-
actual = Ruport::
|
27
|
+
actual = Ruport::Controller::Table.render_csv do |r|
|
28
28
|
r.data = Table([], :data => [[1,2,3],[4,5,6]])
|
29
29
|
end
|
30
30
|
assert_equal("1,2,3\n4,5,6\n",actual)
|
31
31
|
|
32
|
-
actual = Ruport::
|
32
|
+
actual = Ruport::Controller::Table.render_csv do |r|
|
33
33
|
r.data = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
34
34
|
end
|
35
35
|
assert_equal("a,b,c\n1,2,3\n4,5,6\n",actual)
|
@@ -42,7 +42,7 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_table_headers
|
45
|
-
actual = Ruport::
|
45
|
+
actual = Ruport::Controller::Table.
|
46
46
|
render_csv(:show_table_headers => false,
|
47
47
|
:data => Table(%w[a b c], :data => [[1,2,3],[4,5,6]]))
|
48
48
|
assert_equal("1,2,3\n4,5,6\n",actual)
|
@@ -50,7 +50,7 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
50
50
|
|
51
51
|
def test_render_with_template
|
52
52
|
formatter = Ruport::Formatter::CSV.new
|
53
|
-
formatter.options = Ruport::
|
53
|
+
formatter.options = Ruport::Controller::Options.new
|
54
54
|
formatter.options.template = :simple
|
55
55
|
formatter.apply_template
|
56
56
|
|
@@ -112,7 +112,7 @@ class TestRenderCSVGroup < Test::Unit::TestCase
|
|
112
112
|
group = Ruport::Data::Group.new(:name => 'test',
|
113
113
|
:data => [[1,2,3],[4,5,6]],
|
114
114
|
:column_names => %w[a b c])
|
115
|
-
actual = Ruport::
|
115
|
+
actual = Ruport::Controller::Group.
|
116
116
|
render_csv(:data => group, :show_table_headers => false )
|
117
117
|
assert_equal("test\n\n1,2,3\n4,5,6\n",actual)
|
118
118
|
end
|
data/test/grouping_test.rb
CHANGED
@@ -97,9 +97,9 @@ class TestGroupRendering < Test::Unit::TestCase
|
|
97
97
|
def test_as_throws_proper_errors
|
98
98
|
assert_nothing_raised { @group.as(:csv) }
|
99
99
|
assert_nothing_raised { @group.to_csv }
|
100
|
-
assert_raises(Ruport::
|
100
|
+
assert_raises(Ruport::Controller::UnknownFormatError) {
|
101
101
|
@group.as(:nothing) }
|
102
|
-
assert_raises(Ruport::
|
102
|
+
assert_raises(Ruport::Controller::UnknownFormatError) {
|
103
103
|
@group.to_nothing }
|
104
104
|
end
|
105
105
|
|
@@ -379,9 +379,9 @@ class TestGroupingRendering < Test::Unit::TestCase
|
|
379
379
|
def test_as_throws_proper_errors
|
380
380
|
assert_nothing_raised { @grouping.as(:csv) }
|
381
381
|
assert_nothing_raised { @grouping.to_csv }
|
382
|
-
assert_raises(Ruport::
|
382
|
+
assert_raises(Ruport::Controller::UnknownFormatError) {
|
383
383
|
@grouping.as(:nothing) }
|
384
|
-
assert_raises(Ruport::
|
384
|
+
assert_raises(Ruport::Controller::UnknownFormatError) {
|
385
385
|
@grouping.to_nothing }
|
386
386
|
end
|
387
387
|
end
|
data/test/helpers.rb
CHANGED
data/test/html_formatter_test.rb
CHANGED
@@ -24,16 +24,16 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
def test_render_html_basic
|
26
26
|
|
27
|
-
actual = Ruport::
|
27
|
+
actual = Ruport::Controller::Table.render_html { |r|
|
28
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"+
|
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"+
|
34
|
-
"\t</tr>\n\t</table
|
34
|
+
"\t</tr>\n\t</table>\n",actual)
|
35
35
|
|
36
|
-
actual = Ruport::
|
36
|
+
actual = Ruport::Controller::Table.render_html { |r|
|
37
37
|
r.data = Table(%w[a b c], :data => [ [1,2,3],[4,5,6]])
|
38
38
|
}
|
39
39
|
|
@@ -41,13 +41,13 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
41
41
|
"\n\t\t\t<th>c</th>\n\t\t</tr>\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
|
44
|
+
"\t</tr>\n\t</table>\n",actual)
|
45
45
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_render_with_template
|
49
49
|
formatter = Ruport::Formatter::HTML.new
|
50
|
-
formatter.options = Ruport::
|
50
|
+
formatter.options = Ruport::Controller::Options.new
|
51
51
|
formatter.options.template = :simple
|
52
52
|
formatter.apply_template
|
53
53
|
|
@@ -102,7 +102,7 @@ end
|
|
102
102
|
class TestRenderHTMLRow < Test::Unit::TestCase
|
103
103
|
|
104
104
|
def test_render_html_row
|
105
|
-
actual = Ruport::
|
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
|
@@ -115,25 +115,25 @@ class TestRenderHTMLGroup < Test::Unit::TestCase
|
|
115
115
|
group = Ruport::Data::Group.new(:name => 'test',
|
116
116
|
:data => [[1,2,3],[4,5,6]],
|
117
117
|
:column_names => %w[a b c])
|
118
|
-
actual = Ruport::
|
118
|
+
actual = Ruport::Controller::Group.render(:html, :data => group)
|
119
119
|
assert_equal "\t<p>test</p>\n"+
|
120
120
|
"\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
|
121
121
|
"\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
122
122
|
"\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
|
123
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
|
124
|
+
"\t</tr>\n\t</table>\n", actual
|
125
125
|
end
|
126
126
|
|
127
127
|
def test_render_html_group_without_headers
|
128
128
|
group = Ruport::Data::Group.new(:name => 'test',
|
129
129
|
:data => [[1,2,3],[4,5,6]],
|
130
130
|
:column_names => %w[a b c])
|
131
|
-
actual = Ruport::
|
131
|
+
actual = Ruport::Controller::Group.render(:html, :data => group,
|
132
132
|
:show_table_headers => false)
|
133
133
|
assert_equal "\t<p>test</p>\n\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
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
|
-
"\t</tr>\n\t</table
|
136
|
+
"\t</tr>\n\t</table>\n", actual
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
@@ -143,33 +143,33 @@ class TestRenderHTMLGrouping < Test::Unit::TestCase
|
|
143
143
|
def test_render_html_grouping
|
144
144
|
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
145
145
|
g = Grouping(table,:by => "a")
|
146
|
-
actual = Ruport::
|
146
|
+
actual = Ruport::Controller::Grouping.render(:html, :data => g,
|
147
147
|
:show_table_headers => false)
|
148
148
|
|
149
149
|
assert_equal "\t<p>1</p>\n\t<table>\n\t\t<tr>\n\t\t\t<td>2</td>\n"+
|
150
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\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", actual
|
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
153
|
end
|
154
154
|
|
155
155
|
def test_render_html_grouping_with_table_headers
|
156
156
|
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
157
157
|
g = Grouping(table,:by => "a")
|
158
|
-
actual = Ruport::
|
158
|
+
actual = Ruport::Controller::Grouping.render(:html, :data => g)
|
159
159
|
|
160
160
|
assert_equal "\t<p>1</p>\n\t<table>\n\t\t<tr>\n\t\t\t<th>b</th>\n"+
|
161
161
|
"\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>"+
|
162
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"+
|
163
|
+
"\t<td>1</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t</table>\n\n"+
|
164
164
|
"\t<p>2</p>\n\t<table>\n\t\t<tr>\n\t\t\t<th>b</th>\n\t\t"+
|
165
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", actual
|
166
|
+
"\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n\n", actual
|
167
167
|
end
|
168
168
|
|
169
169
|
def test_render_justified_html_grouping
|
170
170
|
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
171
171
|
g = Grouping(table,:by => "a")
|
172
|
-
actual = Ruport::
|
172
|
+
actual = Ruport::Controller::Grouping.render(:html, :data => g,
|
173
173
|
:style => :justified)
|
174
174
|
|
175
175
|
assert_equal "\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>\n"+
|
@@ -179,7 +179,7 @@ class TestRenderHTMLGrouping < Test::Unit::TestCase
|
|
179
179
|
"<td> </td>\n\t\t\t<td>1</td>\n\t\t\t<td>3</td>"+
|
180
180
|
"\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+
|
181
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
|
182
|
+
"\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n", actual
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
data/test/pdf_formatter_test.rb
CHANGED
@@ -63,7 +63,7 @@ class TestRenderPDFTable < Test::Unit::TestCase
|
|
63
63
|
|
64
64
|
def test_render_with_template
|
65
65
|
formatter = Ruport::Formatter::PDF.new
|
66
|
-
formatter.options = Ruport::
|
66
|
+
formatter.options = Ruport::Controller::Options.new
|
67
67
|
formatter.options.template = :simple
|
68
68
|
formatter.apply_template
|
69
69
|
|
@@ -193,13 +193,13 @@ class TestRenderPDFTable < Test::Unit::TestCase
|
|
193
193
|
# draw_table has destructive behavior on nested rendering options (#359)
|
194
194
|
def test_draw_table_should_not_destroy_nested_rendering_options
|
195
195
|
f = Ruport::Formatter::PDF.new
|
196
|
-
f.options = Ruport::
|
196
|
+
f.options = Ruport::Controller::Options.new
|
197
197
|
f.options[:table_format] =
|
198
198
|
{ :column_options => { :heading => {:justification => :center }}}
|
199
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
|
-
end
|
202
|
+
end
|
203
203
|
|
204
204
|
end
|
205
205
|
|
@@ -326,4 +326,29 @@ class TestPDFFormatterHelpers < Test::Unit::TestCase
|
|
326
326
|
a.draw_text "foo", :left => a.left_boundary + 50, :y => 500
|
327
327
|
assert_equal 100, a.cursor
|
328
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
|
+
|
329
353
|
end
|
354
|
+
|
data/test/record_test.rb
CHANGED
@@ -313,11 +313,11 @@ class TestRecord < Test::Unit::TestCase
|
|
313
313
|
end
|
314
314
|
|
315
315
|
def specify_as_should_throw_proper_errors
|
316
|
-
assert_raises(Ruport::
|
316
|
+
assert_raises(Ruport::Controller::UnknownFormatError) { @a.as(:nothing) }
|
317
317
|
end
|
318
318
|
|
319
319
|
def specify_to_format_should_throw_proper_errors
|
320
|
-
assert_raises(Ruport::
|
320
|
+
assert_raises(Ruport::Controller::UnknownFormatError) { @a.to_nothing }
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
3
|
+
|
4
|
+
class TablePivotSimpleCaseTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
table = Table('a', 'b', 'c')
|
8
|
+
table << [1,3,6]
|
9
|
+
table << [1,4,7]
|
10
|
+
table << [2,3,8]
|
11
|
+
table << [2,4,9]
|
12
|
+
@pivoted = table.pivot('b', :group_by => 'a', :values => 'c')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_produces_correct_columns
|
16
|
+
assert_equal(['a', 3, 4], @pivoted.column_names)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_produces_correct_full_table
|
20
|
+
expected = Table("a",3,4) { |t| t << [1,6,7] << [2,8,9] }
|
21
|
+
assert_equal(expected, @pivoted)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class PivotConvertRowOrderToGroupOrderTest < Test::Unit::TestCase
|
27
|
+
|
28
|
+
def convert(src)
|
29
|
+
Ruport::Data::Table::Pivot.new(
|
30
|
+
nil, nil, nil, nil
|
31
|
+
).convert_row_order_to_group_order(src)
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup
|
35
|
+
@group = mock('group')
|
36
|
+
@row = mock('row')
|
37
|
+
@group.stubs(:[]).with(0).returns(@row)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_bare_field_name
|
41
|
+
converted = convert(:field_name)
|
42
|
+
@row.expects(:[]).with(:field_name)
|
43
|
+
converted.call(@group)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_array_of_field_names
|
47
|
+
converted = convert([:field1, :field2])
|
48
|
+
@row.stubs(:[]).with(:field1).returns('f1val')
|
49
|
+
@row.stubs(:[]).with(:field2).returns('f2val')
|
50
|
+
assert_equal(['f1val', 'f2val'], converted.call(@group))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_proc_operating_on_row
|
54
|
+
converted = convert(proc {|row| row[:field1] })
|
55
|
+
@row.stubs(:[]).with(:field1).returns('f1val')
|
56
|
+
assert_equal('f1val', converted.call(@group))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_nil
|
60
|
+
assert_equal(nil, convert(nil))
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
class PivotPreservesOrdering < Test::Unit::TestCase
|
66
|
+
|
67
|
+
def test_group_column_entries_preserves_order_of_occurrence
|
68
|
+
table = Table('group', 'a', 'b')
|
69
|
+
[
|
70
|
+
[1, 0, 0],
|
71
|
+
[9, 0, 0],
|
72
|
+
[1, 0, 0],
|
73
|
+
[9, 0, 0],
|
74
|
+
[1, 0, 0],
|
75
|
+
[8, 0, 0],
|
76
|
+
[1, 0, 0]
|
77
|
+
].each {|e| table << e}
|
78
|
+
assert_equal([1,9,8],
|
79
|
+
Ruport::Data::Table::Pivot.
|
80
|
+
new(table, 'group', 'a', 'b').group_column_entries)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_resulting_columns_preserve_ordering_of_rows
|
84
|
+
table = Table('group', 'a', 'b', 'c')
|
85
|
+
[
|
86
|
+
[200, 1, 2, 1],
|
87
|
+
[200, 4, 5, 2],
|
88
|
+
[200, 5, 0, 3],
|
89
|
+
[100, 1, 8, 4],
|
90
|
+
[100, 4,11, 5]
|
91
|
+
].each {|e| table << e}
|
92
|
+
assert_equal(
|
93
|
+
[1,4,5],
|
94
|
+
Ruport::Data::Table::Pivot.new(
|
95
|
+
table, 'group', 'a', 'b', :pivot_order => ['c']
|
96
|
+
).columns_from_pivot)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_preserves_ordering
|
100
|
+
table = Table('group', 'a', 'b', 'c')
|
101
|
+
[
|
102
|
+
[200, 1, 2, 3],
|
103
|
+
[200, 4, 5, 6],
|
104
|
+
[100, 1, 8, 9],
|
105
|
+
[100, 4,11,12]
|
106
|
+
].each {|e| table << e}
|
107
|
+
pivoted = table.pivot('a', :group_by => 'group', :values => 'b')
|
108
|
+
expected = Table("group",1,4) { |t| t << [200,2,5] << [100,8,11] }
|
109
|
+
assert_equal(expected, pivoted)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_preserves_ordering_on_calculated_column
|
113
|
+
table = Table('group', 'a')
|
114
|
+
[
|
115
|
+
[1, 1], [2, 2], [3, 3]
|
116
|
+
].each {|e| table << e}
|
117
|
+
table.add_column('pivotme') {|row| 10 - row.group.to_i}
|
118
|
+
pivoted = table.pivot('pivotme', :group_by => 'group', :values => 'a',
|
119
|
+
:pivot_order => :name)
|
120
|
+
assert_equal(['group', 7, 8, 9], pivoted.column_names)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_preserves_ordering_on_calculated_column_with_proc_pivot_order
|
124
|
+
table = Table('group', 'a')
|
125
|
+
[
|
126
|
+
[1, 1], [2, 2], [3, 3]
|
127
|
+
].each {|e| table << e}
|
128
|
+
table.add_column('pivotme') {|row| 10 - row.group.to_i}
|
129
|
+
pivoted = table.pivot('pivotme', :group_by => 'group', :values => 'a',
|
130
|
+
:pivot_order => proc {|row, pivot| pivot })
|
131
|
+
assert_equal(['group', 7, 8, 9], pivoted.column_names)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
data/test/table_test.rb
CHANGED
@@ -438,15 +438,15 @@ class TestTableFormattingHooks < Test::Unit::TestCase
|
|
438
438
|
table = Ruport::Data::Table.new :column_names => %w[a b],
|
439
439
|
:data => [[1,2],[3,4],[5,6]]
|
440
440
|
assert_equal("a,b\n1,2\n3,4\n5,6\n",table.to_csv)
|
441
|
-
assert_raises(Ruport::
|
441
|
+
assert_raises(Ruport::Controller::UnknownFormatError) { table.to_nothing }
|
442
442
|
end
|
443
443
|
|
444
444
|
def test_as_throws_proper_errors
|
445
445
|
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
446
446
|
assert_nothing_raised { a.as(:csv) }
|
447
447
|
assert_nothing_raised { a.to_csv }
|
448
|
-
assert_raises(Ruport::
|
449
|
-
assert_raises(Ruport::
|
448
|
+
assert_raises(Ruport::Controller::UnknownFormatError) { a.as(:nothing) }
|
449
|
+
assert_raises(Ruport::Controller::UnknownFormatError) { a.to_nothing }
|
450
450
|
end
|
451
451
|
|
452
452
|
end
|
@@ -662,6 +662,13 @@ class TestTableColumnOperations < Test::Unit::TestCase
|
|
662
662
|
assert_equal Table(%w[a foo c], :data => [[1,6,6],[4,9,9]]), a
|
663
663
|
end
|
664
664
|
|
665
|
+
def test_ensure_renaming_a_missing_column_fails_silently
|
666
|
+
a = Table(%w[a b c])
|
667
|
+
assert_nothing_raised do
|
668
|
+
a.rename_column("d", "z")
|
669
|
+
end
|
670
|
+
end
|
671
|
+
|
665
672
|
end
|
666
673
|
|
667
674
|
class TestTableFromCSV < Test::Unit::TestCase
|
data/test/text_formatter_test.rb
CHANGED
@@ -79,7 +79,7 @@ class TestRenderTextTable < Test::Unit::TestCase
|
|
79
79
|
|
80
80
|
def test_render_with_template
|
81
81
|
formatter = Ruport::Formatter::Text.new
|
82
|
-
formatter.options = Ruport::
|
82
|
+
formatter.options = Ruport::Controller::Options.new
|
83
83
|
formatter.options.template = :simple
|
84
84
|
formatter.apply_template
|
85
85
|
|
@@ -165,7 +165,7 @@ end
|
|
165
165
|
class TestRenderTextRow < Test::Unit::TestCase
|
166
166
|
|
167
167
|
def test_row_basic
|
168
|
-
actual = Ruport::
|
168
|
+
actual = Ruport::Controller::Row.render_text(:data => [1,2,3])
|
169
169
|
assert_equal("| 1 | 2 | 3 |\n", actual)
|
170
170
|
end
|
171
171
|
|
@@ -180,7 +180,7 @@ class TestRenderTextGroup < Test::Unit::TestCase
|
|
180
180
|
%w[interesting red snapper]],
|
181
181
|
:column_names => %w[i hope so])
|
182
182
|
|
183
|
-
actual = Ruport::
|
183
|
+
actual = Ruport::Controller::Group.render_text(:data => group)
|
184
184
|
expected = "test:\n\n"+
|
185
185
|
"+------------------------------+\n"+
|
186
186
|
"| i | hope | so |\n"+
|
@@ -197,7 +197,7 @@ class TestRenderTextGroup < Test::Unit::TestCase
|
|
197
197
|
%w[interesting red snapper]],
|
198
198
|
:column_names => %w[i hope so])
|
199
199
|
|
200
|
-
actual = Ruport::
|
200
|
+
actual = Ruport::Controller::Group.render(:text, :data => group,
|
201
201
|
:show_table_headers => false )
|
202
202
|
expected = "test:\n\n"+
|
203
203
|
"+------------------------------+\n"+
|
@@ -217,7 +217,7 @@ class TestRenderTextGrouping < Test::Unit::TestCase
|
|
217
217
|
:column_names => %w[i hope so])
|
218
218
|
grouping = Grouping(table, :by => "i")
|
219
219
|
|
220
|
-
actual = Ruport::
|
220
|
+
actual = Ruport::Controller::Grouping.render(:text, :data => grouping)
|
221
221
|
expected = "interesting:\n\n"+
|
222
222
|
"+----------------+\n"+
|
223
223
|
"| hope | so |\n"+
|
@@ -242,7 +242,7 @@ class TestRenderTextGrouping < Test::Unit::TestCase
|
|
242
242
|
:column_names => %w[i hope so])
|
243
243
|
grouping = Grouping(table, :by => "i")
|
244
244
|
|
245
|
-
actual = Ruport::
|
245
|
+
actual = Ruport::Controller::Grouping.render(:text, :data => grouping,
|
246
246
|
:show_table_headers => false)
|
247
247
|
expected = "interesting:\n\n"+
|
248
248
|
"+----------------+\n"+
|