ruport 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -4
- data/Rakefile +1 -1
- data/lib/ruport.rb +1 -1
- data/lib/ruport/acts_as_reportable.rb +34 -2
- data/lib/ruport/data/grouping.rb +6 -4
- data/lib/ruport/formatter/pdf.rb +54 -17
- data/lib/ruport/formatter/text.rb +6 -3
- data/test/acts_as_reportable_test.rb +95 -72
- data/test/csv_formatter_test.rb +40 -36
- data/test/grouping_test.rb +139 -134
- data/test/html_formatter_test.rb +24 -10
- data/test/pdf_formatter_test.rb +102 -8
- data/test/query_test.rb +0 -1
- data/test/record_test.rb +45 -33
- data/test/renderer_test.rb +236 -211
- data/test/sql_split_test.rb +8 -7
- data/test/table_test.rb +437 -425
- data/test/text_formatter_test.rb +62 -45
- metadata +2 -2
data/test/csv_formatter_test.rb
CHANGED
@@ -5,72 +5,79 @@ begin
|
|
5
5
|
require "rubygems"
|
6
6
|
rescue LoadError
|
7
7
|
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestRenderCSVRow < Test::Unit::TestCase
|
11
|
+
def test_render_csv_row
|
12
|
+
actual = Ruport::Renderer::Row.render_csv(:data => [1,2,3])
|
13
|
+
assert_equal("1,2,3\n", actual)
|
14
|
+
end
|
8
15
|
end
|
9
16
|
|
10
|
-
class
|
17
|
+
class TestRenderCSVTable < Test::Unit::TestCase
|
11
18
|
|
12
19
|
def test_render_csv_table
|
13
|
-
actual = Ruport::Renderer::Table.render_csv
|
20
|
+
actual = Ruport::Renderer::Table.render_csv do |r|
|
14
21
|
r.data = [[1,2,3],[4,5,6]].to_table
|
15
|
-
|
22
|
+
end
|
16
23
|
assert_equal("1,2,3\n4,5,6\n",actual)
|
17
24
|
|
18
|
-
actual = Ruport::Renderer::Table.render_csv
|
25
|
+
actual = Ruport::Renderer::Table.render_csv do |r|
|
19
26
|
r.data = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
20
|
-
|
27
|
+
end
|
21
28
|
assert_equal("a,b,c\n1,2,3\n4,5,6\n",actual)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_format_options
|
32
|
+
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
33
|
+
assert_equal "a\tb\tc\n1\t2\t3\n4\t5\t6\n",
|
34
|
+
a.as(:csv,:format_options => { :col_sep => "\t" })
|
22
35
|
end
|
23
36
|
|
37
|
+
def test_table_headers
|
38
|
+
actual = Ruport::Renderer::Table.
|
39
|
+
render_csv(:show_table_headers => false,
|
40
|
+
:data => [[1,2,3],[4,5,6]].to_table(%w[a b c]))
|
41
|
+
assert_equal("1,2,3\n4,5,6\n",actual)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class TestRenderCSVGroup < Test::Unit::TestCase
|
47
|
+
|
24
48
|
def test_render_csv_group
|
25
49
|
group = Ruport::Data::Group.new(:name => 'test',
|
26
50
|
:data => [[1,2,3],[4,5,6]],
|
27
51
|
:column_names => %w[a b c])
|
28
|
-
actual = Ruport::Renderer::Group.
|
29
|
-
|
52
|
+
actual = Ruport::Renderer::Group.
|
53
|
+
render_csv(:data => group, :show_table_headers => false )
|
30
54
|
assert_equal("test\n\n1,2,3\n4,5,6\n",actual)
|
31
|
-
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
32
58
|
|
59
|
+
class RenderCSVGrouping < Test::Unit::TestCase
|
33
60
|
def test_render_csv_grouping
|
34
|
-
table = Table(%w[hi
|
61
|
+
table = Table(%w[hi red snapper]) << %w[is this annoying] <<
|
35
62
|
%w[is it funny]
|
36
63
|
grouping = Grouping(table,:by => "hi")
|
37
64
|
|
38
|
-
actual = grouping.to_csv
|
65
|
+
actual = grouping.to_csv
|
39
66
|
|
40
|
-
assert_equal "is\n\
|
67
|
+
assert_equal "is\n\nred,snapper\nthis,annoying\nit,funny\n\n", actual
|
41
68
|
end
|
42
69
|
|
43
70
|
def test_render_csv_grouping_without_header
|
44
|
-
table = Table(%w[hi
|
71
|
+
table = Table(%w[hi red snapper]) << %w[is this annoying] <<
|
45
72
|
%w[is it funny]
|
46
73
|
grouping = Grouping(table,:by => "hi")
|
47
74
|
|
48
75
|
actual = grouping.to_csv :show_table_headers => false
|
49
76
|
|
50
77
|
assert_equal "is\n\nthis,annoying\nit,funny\n\n", actual
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_render_csv_row
|
54
|
-
actual = Ruport::Renderer::Row.render_csv { |r| r.data = [1,2,3] }
|
55
|
-
assert_equal("1,2,3\n", actual)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_format_options
|
59
|
-
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
60
|
-
assert_equal "a\tb\tc\n1\t2\t3\n4\t5\t6\n",
|
61
|
-
a.as(:csv,:format_options => { :col_sep => "\t" })
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_layout_header
|
65
|
-
actual = Ruport::Renderer::Table.render_csv { |r|
|
66
|
-
r.data = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
67
|
-
r.options { |o| o.show_table_headers = false }
|
68
|
-
}
|
69
|
-
assert_equal("1,2,3\n4,5,6\n",actual)
|
70
78
|
end
|
71
79
|
|
72
80
|
def test_alternative_styles
|
73
|
-
|
74
81
|
g = Grouping((Table(%w[a b c]) << [1,2,3] << [1,1,4] <<
|
75
82
|
[2,1,2] << [1,9,1] ), :by => "a")
|
76
83
|
|
@@ -81,7 +88,6 @@ class TestFormatCSV < Test::Unit::TestCase
|
|
81
88
|
|
82
89
|
assert_equal "a,b,c\n1,2,3\n1,1,4\n1,9,1\n\n2,1,2\n\n",
|
83
90
|
g.to_csv(:style => :raw)
|
84
|
-
|
85
91
|
end
|
86
92
|
|
87
93
|
# -----------------------------------------------------------------------
|
@@ -92,6 +98,4 @@ class TestFormatCSV < Test::Unit::TestCase
|
|
92
98
|
g = Grouping((Table(%w[a b c])<<[1,2,3]<<[1,1,4]), :by => "a")
|
93
99
|
assert_equal "1\n\nb,c\n2,3\n1,4\n\n", g.to_csv
|
94
100
|
end
|
95
|
-
|
96
|
-
|
97
|
-
end
|
101
|
+
end
|
data/test/grouping_test.rb
CHANGED
@@ -4,6 +4,12 @@ begin; require "rubygems"; rescue LoadError; nil; end
|
|
4
4
|
|
5
5
|
class TestGroup < Test::Unit::TestCase
|
6
6
|
|
7
|
+
def setup
|
8
|
+
@group = Ruport::Data::Group.new(:name => 'test',
|
9
|
+
:data => [[1,2,3]],
|
10
|
+
:column_names => %w[a b c])
|
11
|
+
end
|
12
|
+
|
7
13
|
def test_group_constructor
|
8
14
|
group = Ruport::Data::Group.new(:name => 'test',
|
9
15
|
:data => [[1,2,3]],
|
@@ -15,11 +21,8 @@ class TestGroup < Test::Unit::TestCase
|
|
15
21
|
end
|
16
22
|
|
17
23
|
def test_should_copy_group
|
18
|
-
group
|
19
|
-
|
20
|
-
:column_names => %w[a b c])
|
21
|
-
group.create_subgroups("a")
|
22
|
-
copy = group.dup
|
24
|
+
@group.create_subgroups("a")
|
25
|
+
copy = @group.dup
|
23
26
|
assert_equal 'test', copy.name
|
24
27
|
assert_equal Ruport::Data::Record.new([1,2,3],:attributes => %w[a b c]),
|
25
28
|
copy.data[0]
|
@@ -31,73 +34,74 @@ class TestGroup < Test::Unit::TestCase
|
|
31
34
|
assert_equal b, copy.subgroups
|
32
35
|
end
|
33
36
|
|
34
|
-
def test_group_as
|
35
|
-
group = Ruport::Data::Group.new(:name => 'test',
|
36
|
-
:data => [%w[Ruport Is Sexy]],
|
37
|
-
:column_names => %w[Software Isnt Sexy])
|
38
|
-
assert_equal(7,group.to_text.to_a.length)
|
39
|
-
assert_equal(5,group.as(:text, :show_table_headers => false).to_a.length)
|
40
|
-
assert_equal(13,group.to_html.to_a.length)
|
41
|
-
end
|
42
|
-
|
43
37
|
def test_eql
|
44
|
-
|
45
|
-
:data => [%w[ruport is sexy]],
|
46
|
-
:column_names => %w[software isnt sexy])
|
47
|
-
table = [%w[ruport is sexy]].to_table(%w[software isnt sexy])
|
38
|
+
table = [[1,2,3]].to_table(%w[a b c])
|
48
39
|
|
49
40
|
group2 = Ruport::Data::Group.new(:name => 'test',
|
50
|
-
:data => [
|
51
|
-
:column_names => %w[
|
41
|
+
:data => [[1,2,3]],
|
42
|
+
:column_names => %w[a b c])
|
52
43
|
|
53
|
-
assert_raises(NoMethodError) { group == table }
|
54
|
-
assert_equal group, group2
|
55
|
-
assert_equal group, group.dup
|
44
|
+
assert_raises(NoMethodError) { @group == table }
|
45
|
+
assert_equal @group, group2
|
46
|
+
assert_equal @group, @group.dup
|
56
47
|
end
|
57
48
|
|
58
49
|
def test_create_subgroups
|
59
|
-
group =
|
60
|
-
:data => [[1,2,3],[4,5,6]],
|
61
|
-
:column_names => %w[a b c])
|
50
|
+
group = @group << [4,5,6]
|
62
51
|
group.create_subgroups("a")
|
63
52
|
b = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
64
|
-
|
65
|
-
|
53
|
+
:column_names => %w[b c],
|
54
|
+
:name => 1 ),
|
66
55
|
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
67
|
-
|
68
|
-
|
56
|
+
:column_names => %w[b c],
|
57
|
+
:name => 4 ) }
|
69
58
|
assert_equal b, group.subgroups
|
59
|
+
|
60
|
+
group.create_subgroups("b")
|
61
|
+
c = { 2 => Ruport::Data::Group.new( :data => [[3]],
|
62
|
+
:column_names => %w[c],
|
63
|
+
:name => 2 ) }
|
64
|
+
d = { 5 => Ruport::Data::Group.new( :data => [[6]],
|
65
|
+
:column_names => %w[c],
|
66
|
+
:name => 5 ) }
|
67
|
+
assert_equal c, group.subgroups[1].subgroups
|
68
|
+
assert_equal d, group.subgroups[4].subgroups
|
70
69
|
end
|
71
70
|
|
72
71
|
def test_grouped_data
|
73
|
-
a =
|
74
|
-
:column_names => %w[a b c]).send(:grouped_data, "a")
|
72
|
+
a = @group << [4,5,6]
|
75
73
|
b = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
76
|
-
|
77
|
-
|
74
|
+
:column_names => %w[b c],
|
75
|
+
:name => 1 ),
|
78
76
|
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
79
|
-
|
80
|
-
|
81
|
-
assert_equal b, a
|
77
|
+
:column_names => %w[b c],
|
78
|
+
:name => 4 ) }
|
79
|
+
assert_equal b, a.send(:grouped_data, "a")
|
82
80
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
:column_names => %w[b c],
|
87
|
-
:name => 1 )
|
88
|
-
assert_equal expected, Group(1, :data => [[2,3]],
|
89
|
-
:column_names => %w[b c])
|
90
|
-
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class TestGroupRendering < Test::Unit::TestCase
|
91
84
|
|
85
|
+
def setup
|
86
|
+
@group = Ruport::Data::Group.new(:name => 'test',
|
87
|
+
:data => [[1,2,3]],
|
88
|
+
:column_names => %w[a b c])
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_group_as
|
92
|
+
assert_equal(7, @group.to_text.to_a.length)
|
93
|
+
assert_equal(5, @group.as(:text,
|
94
|
+
:show_table_headers => false).to_a.length)
|
95
|
+
assert_equal(13, @group.to_html.to_a.length)
|
96
|
+
end
|
97
|
+
|
92
98
|
def test_as_throws_proper_errors
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
assert_raises(Ruport::Renderer::UnknownFormatError) { group.as(:nothing) }
|
100
|
-
assert_raises(Ruport::Renderer::UnknownFormatError) { group.to_nothing }
|
99
|
+
assert_nothing_raised { @group.as(:csv) }
|
100
|
+
assert_nothing_raised { @group.to_csv }
|
101
|
+
assert_raises(Ruport::Renderer::UnknownFormatError) {
|
102
|
+
@group.as(:nothing) }
|
103
|
+
assert_raises(Ruport::Renderer::UnknownFormatError) {
|
104
|
+
@group.to_nothing }
|
101
105
|
end
|
102
106
|
|
103
107
|
class MyGroupSub < Ruport::Data::Group; end
|
@@ -106,113 +110,83 @@ class TestGroup < Test::Unit::TestCase
|
|
106
110
|
t = MyGroupSub.new(:column_names => %w[b c],:name => "1") << [2,3]
|
107
111
|
assert_equal "1\n\nb,c\n2,3\n", t.to_csv
|
108
112
|
end
|
109
|
-
|
110
|
-
|
111
113
|
end
|
112
|
-
|
114
|
+
|
113
115
|
class TestGrouping < Test::Unit::TestCase
|
114
116
|
|
117
|
+
def setup
|
118
|
+
table = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
119
|
+
@grouping = Ruport::Data::Grouping.new(table, :by => "a")
|
120
|
+
end
|
121
|
+
|
115
122
|
def test_grouping_constructor
|
116
123
|
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
117
124
|
b = Ruport::Data::Grouping.new(a, :by => "a")
|
118
125
|
c = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
126
|
+
:column_names => %w[b c],
|
127
|
+
:name => 1 ),
|
128
|
+
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
129
|
+
:column_names => %w[b c],
|
130
|
+
:name => 4 ) }
|
124
131
|
assert_equal c, b.data
|
125
132
|
end
|
126
133
|
|
127
|
-
def test_grouping_indexing
|
128
|
-
a = [[
|
129
|
-
b = Ruport::Data::Grouping.new(a, :by => "a")
|
130
|
-
c = [Ruport::Data::Group.new( :data => [[2,3]],
|
134
|
+
def test_grouping_indexing
|
135
|
+
a = [Ruport::Data::Group.new( :data => [[2,3]],
|
131
136
|
:column_names => %w[b c],
|
132
137
|
:name => 1 ),
|
133
138
|
Ruport::Data::Group.new( :data => [[5,6]],
|
134
139
|
:column_names => %w[b c],
|
135
|
-
:name => 4 ),
|
140
|
+
:name => 4 ),
|
136
141
|
Ruport::Data::Group.new( :data => [],
|
137
142
|
:column_names => %w[b c],
|
138
143
|
:name => 2)]
|
139
|
-
assert_equal
|
140
|
-
assert_equal
|
141
|
-
assert_raises(IndexError) {
|
144
|
+
assert_equal a[0], @grouping[1]
|
145
|
+
assert_equal a[1], @grouping[4]
|
146
|
+
assert_raises(IndexError) { @grouping[2] }
|
142
147
|
end
|
143
148
|
|
144
149
|
def test_should_copy_grouping
|
145
|
-
a = [[
|
146
|
-
b = Ruport::Data::Grouping.new(a, :by => "a")
|
147
|
-
c = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
150
|
+
a = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
148
151
|
:column_names => %w[b c],
|
149
152
|
:name => 1 ),
|
150
153
|
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
151
154
|
:column_names => %w[b c],
|
152
155
|
:name => 4 ) }
|
153
|
-
copy =
|
154
|
-
assert_equal
|
156
|
+
copy = @grouping.dup
|
157
|
+
assert_equal a, copy.data
|
155
158
|
assert_equal "a", copy.grouped_by
|
156
159
|
end
|
157
160
|
|
158
161
|
def test_append
|
159
162
|
a =[[1,2,3],[4,5,6]].to_table(%w[a b c])
|
160
|
-
|
161
|
-
|
162
|
-
:column_names => %w[b c],
|
163
|
-
:name => 1 ),
|
164
|
-
Ruport::Data::Group.new( :data => [[5,6]],
|
165
|
-
:column_names => %w[b c],
|
166
|
-
:name => 4 )]
|
167
|
-
b << a.to_group("hand banana")
|
168
|
-
assert_equal b["hand banana"], a.to_group("hand banana")
|
163
|
+
@grouping << a.to_group("red snapper")
|
164
|
+
assert_equal @grouping["red snapper"], a.to_group("red snapper")
|
169
165
|
|
170
|
-
assert_raises(ArgumentError) {
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_grouping_as
|
174
|
-
table = Ruport::Data::Table.new(:data => [%w[Ruport Is Sexy]],
|
175
|
-
:column_names => %w[Software Isnt Sexy])
|
176
|
-
grouping = Ruport::Data::Grouping.new(table, :by => 'Software')
|
177
|
-
assert_equal(8,grouping.to_text.to_a.length)
|
178
|
-
assert_equal(6,grouping.as(:text, :show_table_headers => false).to_a.length)
|
166
|
+
assert_raises(ArgumentError) { @grouping << a.to_group("red snapper") }
|
179
167
|
end
|
180
|
-
|
168
|
+
|
181
169
|
def test_grouped_by
|
182
|
-
a
|
183
|
-
b = Grouping(a, :by => "a")
|
184
|
-
assert_equal "a", b.grouped_by
|
170
|
+
assert_equal "a", @grouping.grouped_by
|
185
171
|
end
|
186
172
|
|
187
|
-
def test_kernel_hack
|
188
|
-
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
189
|
-
b = Grouping(a, :by => "a")
|
190
|
-
c = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
191
|
-
:column_names => %w[b c],
|
192
|
-
:name => 1 ),
|
193
|
-
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
194
|
-
:column_names => %w[b c],
|
195
|
-
:name => 4 ) }
|
196
|
-
assert_equal c, b.data
|
197
|
-
end
|
198
|
-
|
199
173
|
def test_grouping_on_multiple_columns
|
200
174
|
a = [[1,2,3,4],[4,5,6,7]].to_table(%w[a b c d])
|
201
175
|
b = Ruport::Data::Grouping.new(a, :by => %w[a b c])
|
202
176
|
c = { 1 => Ruport::Data::Group.new( :data => [[2,3,4]],
|
203
|
-
|
204
|
-
|
177
|
+
:column_names => %w[b c d],
|
178
|
+
:name => 1 ),
|
205
179
|
4 => Ruport::Data::Group.new( :data => [[5,6,7]],
|
206
|
-
|
207
|
-
|
180
|
+
:column_names => %w[b c d],
|
181
|
+
:name => 4 ) }
|
208
182
|
assert_equal c, b.data
|
209
183
|
|
210
184
|
d = { 2 => Ruport::Data::Group.new( :data => [[3,4]],
|
211
|
-
|
212
|
-
|
185
|
+
:column_names => %w[c d],
|
186
|
+
:name => 2 ) }
|
213
187
|
e = { 5 => Ruport::Data::Group.new( :data => [[6,7]],
|
214
|
-
|
215
|
-
|
188
|
+
:column_names => %w[c d],
|
189
|
+
:name => 5 ) }
|
216
190
|
assert_equal d, b[1].subgroups
|
217
191
|
assert_equal e, b[4].subgroups
|
218
192
|
end
|
@@ -231,18 +205,6 @@ class TestGrouping < Test::Unit::TestCase
|
|
231
205
|
assert_equal %w[schweet], sub.column("id")
|
232
206
|
end
|
233
207
|
|
234
|
-
def test_as_throws_proper_errors
|
235
|
-
|
236
|
-
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
237
|
-
b = Grouping(a, :by => "a")
|
238
|
-
|
239
|
-
|
240
|
-
assert_nothing_raised { b.as(:csv) }
|
241
|
-
assert_nothing_raised { b.to_csv }
|
242
|
-
assert_raises(Ruport::Renderer::UnknownFormatError) { b.as(:nothing) }
|
243
|
-
assert_raises(Ruport::Renderer::UnknownFormatError) { b.to_nothing }
|
244
|
-
end
|
245
|
-
|
246
208
|
class TicketStatus < Ruport::Data::Record
|
247
209
|
|
248
210
|
def closed
|
@@ -255,9 +217,8 @@ class TestGrouping < Test::Unit::TestCase
|
|
255
217
|
|
256
218
|
end
|
257
219
|
|
258
|
-
def test_grouping_summary
|
259
|
-
|
260
|
-
source = Table("test/samples/ticket_count.csv",
|
220
|
+
def test_grouping_summary
|
221
|
+
source = Table("test/samples/ticket_count.csv",
|
261
222
|
:record_class => TicketStatus)
|
262
223
|
grouping = Grouping(source,:by => "date")
|
263
224
|
|
@@ -266,14 +227,14 @@ class TestGrouping < Test::Unit::TestCase
|
|
266
227
|
opened = group.sigma { |r| r.opened }
|
267
228
|
closed = group.sigma { |r| r.closed }
|
268
229
|
expected << { :date => date, :opened => opened, :closed => closed }
|
269
|
-
end
|
230
|
+
end
|
270
231
|
|
271
232
|
actual = grouping.summary :date,
|
272
233
|
:opened => lambda { |g| g.sigma(:opened) },
|
273
234
|
:closed => lambda { |g| g.sigma(:closed) },
|
274
235
|
:order => [:date,:opened,:closed]
|
275
236
|
|
276
|
-
assert_equal expected, actual
|
237
|
+
assert_equal expected, actual
|
277
238
|
|
278
239
|
actual = grouping.summary :date,
|
279
240
|
:opened => lambda { |g| g.sigma(:opened) },
|
@@ -282,6 +243,8 @@ class TestGrouping < Test::Unit::TestCase
|
|
282
243
|
assert_equal [], expected.column_names - actual.column_names
|
283
244
|
end
|
284
245
|
|
246
|
+
class MyRecord < Ruport::Data::Record; end
|
247
|
+
|
285
248
|
def test_grouping_should_set_record_class
|
286
249
|
a = Table(%w[a b c], :record_class => MyRecord) { |t|
|
287
250
|
t << [1,2,3]
|
@@ -298,8 +261,50 @@ class TestGrouping < Test::Unit::TestCase
|
|
298
261
|
a = MyGroupingSub.new(t, :by => "a")
|
299
262
|
assert_equal "1\n\nb,c\n2,3\n\n", a.to_csv
|
300
263
|
end
|
264
|
+
end
|
265
|
+
|
266
|
+
class TestGroupingRendering < Test::Unit::TestCase
|
267
|
+
|
268
|
+
def setup
|
269
|
+
table = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
270
|
+
@grouping = Ruport::Data::Grouping.new(table, :by => "a")
|
271
|
+
end
|
301
272
|
|
273
|
+
def test_grouping_as
|
274
|
+
assert_equal(16, @grouping.to_text.to_a.length)
|
275
|
+
assert_equal(12, @grouping.as(:text,
|
276
|
+
:show_table_headers => false).to_a.length)
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_as_throws_proper_errors
|
280
|
+
assert_nothing_raised { @grouping.as(:csv) }
|
281
|
+
assert_nothing_raised { @grouping.to_csv }
|
282
|
+
assert_raises(Ruport::Renderer::UnknownFormatError) {
|
283
|
+
@grouping.as(:nothing) }
|
284
|
+
assert_raises(Ruport::Renderer::UnknownFormatError) {
|
285
|
+
@grouping.to_nothing }
|
286
|
+
end
|
302
287
|
end
|
303
288
|
|
304
|
-
class
|
289
|
+
class TestGroupingKernelHacks < Test::Unit::TestCase
|
290
|
+
|
291
|
+
def test_group_kernel_hack
|
292
|
+
group = Ruport::Data::Group.new( :name => 'test',
|
293
|
+
:data => [[1,2,3]],
|
294
|
+
:column_names => %w[a b c])
|
295
|
+
assert_equal group, Group('test', :data => [[1,2,3]],
|
296
|
+
:column_names => %w[a b c])
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_grouping_kernel_hack
|
300
|
+
table = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
301
|
+
grouping = Ruport::Data::Grouping.new(table, :by => "a")
|
302
|
+
a = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
303
|
+
:column_names => %w[b c],
|
304
|
+
:name => 1 ),
|
305
|
+
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
306
|
+
:column_names => %w[b c],
|
307
|
+
:name => 4 ) }
|
308
|
+
assert_equal a, grouping.data
|
309
|
+
end
|
305
310
|
end
|