ruport 0.8.14 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +42 -107
- data/Rakefile +29 -32
- data/examples/centered_pdf_text_box.rb +13 -19
- data/examples/example.csv +3 -0
- data/examples/line_plotter.rb +15 -15
- data/examples/pdf_complex_report.rb +10 -23
- data/examples/pdf_table_with_title.rb +12 -12
- data/examples/rope_examples/itunes/Rakefile +22 -1
- data/examples/rope_examples/itunes/config/environment.rb +4 -0
- data/examples/rope_examples/itunes/lib/init.rb +32 -2
- data/examples/rope_examples/itunes/util/build +50 -16
- data/examples/rope_examples/sales_report/README +1 -1
- data/examples/rope_examples/sales_report/Rakefile +22 -1
- data/examples/rope_examples/sales_report/config/environment.rb +4 -0
- data/examples/rope_examples/sales_report/lib/init.rb +32 -2
- data/examples/rope_examples/sales_report/lib/reports/sales.rb +10 -16
- data/examples/rope_examples/sales_report/util/build +50 -16
- data/examples/row_renderer.rb +39 -0
- data/examples/ruport_list/png_embed.rb +61 -0
- data/examples/ruport_list/roadmap.png +0 -0
- data/examples/sample.rb +16 -0
- data/examples/simple_pdf_lines.rb +24 -0
- data/lib/ruport.rb +143 -57
- data/lib/ruport/acts_as_reportable.rb +246 -0
- data/lib/ruport/data.rb +1 -2
- data/lib/ruport/data/grouping.rb +311 -0
- data/lib/ruport/data/record.rb +113 -84
- data/lib/ruport/data/table.rb +275 -174
- data/lib/ruport/formatter.rb +149 -0
- data/lib/ruport/formatter/csv.rb +87 -0
- data/lib/ruport/formatter/html.rb +89 -0
- data/lib/ruport/formatter/pdf.rb +357 -0
- data/lib/ruport/formatter/text.rb +151 -0
- data/lib/ruport/generator.rb +127 -30
- data/lib/ruport/query.rb +46 -99
- data/lib/ruport/renderer.rb +238 -194
- data/lib/ruport/renderer/grouping.rb +67 -0
- data/lib/ruport/renderer/table.rb +25 -98
- data/lib/ruport/report.rb +45 -96
- data/test/acts_as_reportable_test.rb +229 -0
- data/test/csv_formatter_test.rb +97 -0
- data/test/{_test_database.rb → database_test_.rb} +0 -0
- data/test/grouping_test.rb +305 -0
- data/test/html_formatter_test.rb +104 -0
- data/test/pdf_formatter_test.rb +25 -0
- data/test/{test_query.rb → query_test.rb} +32 -121
- data/test/{test_record.rb → record_test.rb} +40 -23
- data/test/renderer_test.rb +344 -0
- data/test/{test_report.rb → report_test.rb} +74 -44
- data/test/samples/ticket_count.csv +124 -0
- data/test/{test_sql_split.rb → sql_split_test.rb} +0 -0
- data/test/{test_table.rb → table_test.rb} +255 -44
- data/test/text_formatter_test.rb +144 -0
- data/util/bench/data/record/bench_as_vs_to.rb +17 -0
- data/util/bench/data/record/bench_constructor.rb +46 -0
- data/util/bench/data/record/bench_indexing.rb +65 -0
- data/util/bench/data/record/bench_reorder.rb +35 -0
- data/util/bench/data/record/bench_to_a.rb +19 -0
- data/util/bench/data/table/bench_column_manip.rb +103 -0
- data/util/bench/data/table/bench_dup.rb +24 -0
- data/util/bench/data/table/bench_init.rb +67 -0
- data/util/bench/data/table/bench_manip.rb +125 -0
- data/util/bench/formatter/bench_csv.rb +14 -0
- data/util/bench/formatter/bench_html.rb +14 -0
- data/util/bench/formatter/bench_pdf.rb +14 -0
- data/util/bench/formatter/bench_text.rb +14 -0
- data/util/bench/samples/tattle.csv +1237 -0
- metadata +121 -143
- data/TODO +0 -21
- data/examples/invoice.rb +0 -142
- data/examples/invoice_report.rb +0 -29
- data/examples/line_graph.rb +0 -38
- data/examples/rope_examples/itunes/config/ruport_config.rb +0 -8
- data/examples/rope_examples/sales_report/config/ruport_config.rb +0 -8
- data/lib/ruport/attempt.rb +0 -63
- data/lib/ruport/config.rb +0 -204
- data/lib/ruport/data/groupable.rb +0 -93
- data/lib/ruport/data/taggable.rb +0 -80
- data/lib/ruport/format.rb +0 -1
- data/lib/ruport/format/csv.rb +0 -29
- data/lib/ruport/format/html.rb +0 -42
- data/lib/ruport/format/latex.rb +0 -47
- data/lib/ruport/format/pdf.rb +0 -233
- data/lib/ruport/format/plugin.rb +0 -31
- data/lib/ruport/format/svg.rb +0 -60
- data/lib/ruport/format/text.rb +0 -103
- data/lib/ruport/format/xml.rb +0 -32
- data/lib/ruport/layout.rb +0 -1
- data/lib/ruport/layout/component.rb +0 -7
- data/lib/ruport/mailer.rb +0 -99
- data/lib/ruport/renderer/graph.rb +0 -46
- data/lib/ruport/report/graph.rb +0 -14
- data/lib/ruport/system_extensions.rb +0 -71
- data/test/test_config.rb +0 -88
- data/test/test_format_text.rb +0 -63
- data/test/test_graph_renderer.rb +0 -97
- data/test/test_groupable.rb +0 -56
- data/test/test_mailer.rb +0 -170
- data/test/test_renderer.rb +0 -151
- data/test/test_ruport.rb +0 -58
- data/test/test_table_renderer.rb +0 -141
- data/test/test_taggable.rb +0 -52
@@ -0,0 +1,97 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "ruport"
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "rubygems"
|
6
|
+
rescue LoadError
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestFormatCSV < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def test_render_csv_table
|
13
|
+
actual = Ruport::Renderer::Table.render_csv { |r|
|
14
|
+
r.data = [[1,2,3],[4,5,6]].to_table
|
15
|
+
}
|
16
|
+
assert_equal("1,2,3\n4,5,6\n",actual)
|
17
|
+
|
18
|
+
actual = Ruport::Renderer::Table.render_csv { |r|
|
19
|
+
r.data = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
20
|
+
}
|
21
|
+
assert_equal("a,b,c\n1,2,3\n4,5,6\n",actual)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_render_csv_group
|
25
|
+
group = Ruport::Data::Group.new(:name => 'test',
|
26
|
+
:data => [[1,2,3],[4,5,6]],
|
27
|
+
:column_names => %w[a b c])
|
28
|
+
actual = Ruport::Renderer::Group.render(:csv, :data => group,
|
29
|
+
:show_table_headers => false )
|
30
|
+
assert_equal("test\n\n1,2,3\n4,5,6\n",actual)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_render_csv_grouping
|
34
|
+
table = Table(%w[hi chris carter]) << %w[is this annoying] <<
|
35
|
+
%w[is it funny]
|
36
|
+
grouping = Grouping(table,:by => "hi")
|
37
|
+
|
38
|
+
actual = grouping.to_csv #(:show_group_headers => false)
|
39
|
+
|
40
|
+
assert_equal "is\n\nchris,carter\nthis,annoying\nit,funny\n\n", actual
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_render_csv_grouping_without_header
|
44
|
+
table = Table(%w[hi chris carter]) << %w[is this annoying] <<
|
45
|
+
%w[is it funny]
|
46
|
+
grouping = Grouping(table,:by => "hi")
|
47
|
+
|
48
|
+
actual = grouping.to_csv :show_table_headers => false
|
49
|
+
|
50
|
+
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
|
+
end
|
71
|
+
|
72
|
+
def test_alternative_styles
|
73
|
+
|
74
|
+
g = Grouping((Table(%w[a b c]) << [1,2,3] << [1,1,4] <<
|
75
|
+
[2,1,2] << [1,9,1] ), :by => "a")
|
76
|
+
|
77
|
+
assert_raise(NotImplementedError) { g.to_csv :style => :not_real }
|
78
|
+
|
79
|
+
assert_equal "a,b,c\n1,2,3\n,1,4\n,9,1\n\n2,1,2\n\n",
|
80
|
+
g.to_csv(:style => :justified)
|
81
|
+
|
82
|
+
assert_equal "a,b,c\n1,2,3\n1,1,4\n1,9,1\n\n2,1,2\n\n",
|
83
|
+
g.to_csv(:style => :raw)
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
# -----------------------------------------------------------------------
|
88
|
+
# BUG TRAPS
|
89
|
+
# ------------------------------------------------------------------------
|
90
|
+
|
91
|
+
def test_ensure_group_names_are_converted_to_string
|
92
|
+
g = Grouping((Table(%w[a b c])<<[1,2,3]<<[1,1,4]), :by => "a")
|
93
|
+
assert_equal "1\n\nb,c\n2,3\n1,4\n\n", g.to_csv
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
end
|
File without changes
|
@@ -0,0 +1,305 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "ruport"
|
3
|
+
begin; require "rubygems"; rescue LoadError; nil; end
|
4
|
+
|
5
|
+
class TestGroup < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_group_constructor
|
8
|
+
group = Ruport::Data::Group.new(:name => 'test',
|
9
|
+
:data => [[1,2,3]],
|
10
|
+
:column_names => %w[a b c])
|
11
|
+
assert_equal 'test', group.name
|
12
|
+
assert_equal Ruport::Data::Record.new([1,2,3],:attributes => %w[a b c]),
|
13
|
+
group.data[0]
|
14
|
+
assert_equal %w[a b c], group.column_names
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_copy_group
|
18
|
+
group = Ruport::Data::Group.new(:name => 'test',
|
19
|
+
:data => [[1,2,3]],
|
20
|
+
:column_names => %w[a b c])
|
21
|
+
group.create_subgroups("a")
|
22
|
+
copy = group.dup
|
23
|
+
assert_equal 'test', copy.name
|
24
|
+
assert_equal Ruport::Data::Record.new([1,2,3],:attributes => %w[a b c]),
|
25
|
+
copy.data[0]
|
26
|
+
assert_equal %w[a b c], copy.column_names
|
27
|
+
|
28
|
+
b = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
29
|
+
:column_names => %w[b c],
|
30
|
+
:name => 1 ) }
|
31
|
+
assert_equal b, copy.subgroups
|
32
|
+
end
|
33
|
+
|
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
|
+
def test_eql
|
44
|
+
group = Ruport::Data::Group.new(:name => 'test',
|
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])
|
48
|
+
|
49
|
+
group2 = Ruport::Data::Group.new(:name => 'test',
|
50
|
+
:data => [%w[ruport is sexy]],
|
51
|
+
:column_names => %w[software isnt sexy])
|
52
|
+
|
53
|
+
assert_raises(NoMethodError) { group == table }
|
54
|
+
assert_equal group, group2
|
55
|
+
assert_equal group, group.dup
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_create_subgroups
|
59
|
+
group = Ruport::Data::Group.new(:name => 'test',
|
60
|
+
:data => [[1,2,3],[4,5,6]],
|
61
|
+
:column_names => %w[a b c])
|
62
|
+
group.create_subgroups("a")
|
63
|
+
b = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
64
|
+
:column_names => %w[b c],
|
65
|
+
:name => 1 ),
|
66
|
+
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
67
|
+
:column_names => %w[b c],
|
68
|
+
:name => 4 ) }
|
69
|
+
assert_equal b, group.subgroups
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_grouped_data
|
73
|
+
a = Group(nil, :data => [[1,2,3],[4,5,6]],
|
74
|
+
:column_names => %w[a b c]).send(:grouped_data, "a")
|
75
|
+
b = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
76
|
+
:column_names => %w[b c],
|
77
|
+
:name => 1 ),
|
78
|
+
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
79
|
+
:column_names => %w[b c],
|
80
|
+
:name => 4 ) }
|
81
|
+
assert_equal b, a
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_kernel_hack
|
85
|
+
expected = Ruport::Data::Group.new( :data => [[2,3]],
|
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
|
91
|
+
|
92
|
+
def test_as_throws_proper_errors
|
93
|
+
group = Ruport::Data::Group.new(:name => 'test',
|
94
|
+
:data => [[1,2,3]],
|
95
|
+
:column_names => %w[a b c])
|
96
|
+
|
97
|
+
assert_nothing_raised { group.as(:csv) }
|
98
|
+
assert_nothing_raised { group.to_csv }
|
99
|
+
assert_raises(Ruport::Renderer::UnknownFormatError) { group.as(:nothing) }
|
100
|
+
assert_raises(Ruport::Renderer::UnknownFormatError) { group.to_nothing }
|
101
|
+
end
|
102
|
+
|
103
|
+
class MyGroupSub < Ruport::Data::Group; end
|
104
|
+
|
105
|
+
def test_ensure_group_subclasses_render_properly
|
106
|
+
t = MyGroupSub.new(:column_names => %w[b c],:name => "1") << [2,3]
|
107
|
+
assert_equal "1\n\nb,c\n2,3\n", t.to_csv
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
class TestGrouping < Test::Unit::TestCase
|
114
|
+
|
115
|
+
def test_grouping_constructor
|
116
|
+
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
117
|
+
b = Ruport::Data::Grouping.new(a, :by => "a")
|
118
|
+
c = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
119
|
+
:column_names => %w[b c],
|
120
|
+
:name => 1 ),
|
121
|
+
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
122
|
+
:column_names => %w[b c],
|
123
|
+
:name => 4 ) }
|
124
|
+
assert_equal c, b.data
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_grouping_indexing
|
128
|
+
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
129
|
+
b = Ruport::Data::Grouping.new(a, :by => "a")
|
130
|
+
c = [Ruport::Data::Group.new( :data => [[2,3]],
|
131
|
+
:column_names => %w[b c],
|
132
|
+
:name => 1 ),
|
133
|
+
Ruport::Data::Group.new( :data => [[5,6]],
|
134
|
+
:column_names => %w[b c],
|
135
|
+
:name => 4 ),
|
136
|
+
Ruport::Data::Group.new( :data => [],
|
137
|
+
:column_names => %w[b c],
|
138
|
+
:name => 2)]
|
139
|
+
assert_equal c[0], b[1]
|
140
|
+
assert_equal c[1], b[4]
|
141
|
+
assert_raises(IndexError) { b[2] }
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_should_copy_grouping
|
145
|
+
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
146
|
+
b = Ruport::Data::Grouping.new(a, :by => "a")
|
147
|
+
c = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
148
|
+
:column_names => %w[b c],
|
149
|
+
:name => 1 ),
|
150
|
+
4 => Ruport::Data::Group.new( :data => [[5,6]],
|
151
|
+
:column_names => %w[b c],
|
152
|
+
:name => 4 ) }
|
153
|
+
copy = b.dup
|
154
|
+
assert_equal c, copy.data
|
155
|
+
assert_equal "a", copy.grouped_by
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_append
|
159
|
+
a =[[1,2,3],[4,5,6]].to_table(%w[a b c])
|
160
|
+
b = Ruport::Data::Grouping.new(a, :by => "a")
|
161
|
+
c = [Ruport::Data::Group.new( :data => [[2,3]],
|
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")
|
169
|
+
|
170
|
+
assert_raises(ArgumentError) { b << a.to_group("hand banana") }
|
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)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_grouped_by
|
182
|
+
a = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
183
|
+
b = Grouping(a, :by => "a")
|
184
|
+
assert_equal "a", b.grouped_by
|
185
|
+
end
|
186
|
+
|
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
|
+
def test_grouping_on_multiple_columns
|
200
|
+
a = [[1,2,3,4],[4,5,6,7]].to_table(%w[a b c d])
|
201
|
+
b = Ruport::Data::Grouping.new(a, :by => %w[a b c])
|
202
|
+
c = { 1 => Ruport::Data::Group.new( :data => [[2,3,4]],
|
203
|
+
:column_names => %w[b c d],
|
204
|
+
:name => 1 ),
|
205
|
+
4 => Ruport::Data::Group.new( :data => [[5,6,7]],
|
206
|
+
:column_names => %w[b c d],
|
207
|
+
:name => 4 ) }
|
208
|
+
assert_equal c, b.data
|
209
|
+
|
210
|
+
d = { 2 => Ruport::Data::Group.new( :data => [[3,4]],
|
211
|
+
:column_names => %w[c d],
|
212
|
+
:name => 2 ) }
|
213
|
+
e = { 5 => Ruport::Data::Group.new( :data => [[6,7]],
|
214
|
+
:column_names => %w[c d],
|
215
|
+
:name => 5 ) }
|
216
|
+
assert_equal d, b[1].subgroups
|
217
|
+
assert_equal e, b[4].subgroups
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_subgrouping
|
221
|
+
a = Table(%w[first_name last_name id])
|
222
|
+
a << %w[ greg brown awesome ]
|
223
|
+
a << %w[ mike milner schweet ]
|
224
|
+
a << %w[ greg brown sick ]
|
225
|
+
g = Grouping(a,:by => %w[first_name last_name])
|
226
|
+
|
227
|
+
sub = g.subgrouping("greg")["brown"]
|
228
|
+
assert_equal %w[awesome sick], sub.column("id")
|
229
|
+
|
230
|
+
sub = (g / "mike")["milner"]
|
231
|
+
assert_equal %w[schweet], sub.column("id")
|
232
|
+
end
|
233
|
+
|
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
|
+
class TicketStatus < Ruport::Data::Record
|
247
|
+
|
248
|
+
def closed
|
249
|
+
title =~ /Ticket.+(\w+ closed)/ ? 1 : 0
|
250
|
+
end
|
251
|
+
|
252
|
+
def opened
|
253
|
+
title =~ /Ticket.+(\w+ created)|(\w+ reopened)/ ? 1 : 0
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_grouping_summary
|
259
|
+
|
260
|
+
source = Table("test/samples/ticket_count.csv",
|
261
|
+
:record_class => TicketStatus)
|
262
|
+
grouping = Grouping(source,:by => "date")
|
263
|
+
|
264
|
+
expected = Table(:date, :opened,:closed)
|
265
|
+
grouping.each do |date,group|
|
266
|
+
opened = group.sigma { |r| r.opened }
|
267
|
+
closed = group.sigma { |r| r.closed }
|
268
|
+
expected << { :date => date, :opened => opened, :closed => closed }
|
269
|
+
end
|
270
|
+
|
271
|
+
actual = grouping.summary :date,
|
272
|
+
:opened => lambda { |g| g.sigma(:opened) },
|
273
|
+
:closed => lambda { |g| g.sigma(:closed) },
|
274
|
+
:order => [:date,:opened,:closed]
|
275
|
+
|
276
|
+
assert_equal expected, actual
|
277
|
+
|
278
|
+
actual = grouping.summary :date,
|
279
|
+
:opened => lambda { |g| g.sigma(:opened) },
|
280
|
+
:closed => lambda { |g| g.sigma(:closed) }
|
281
|
+
|
282
|
+
assert_equal [], expected.column_names - actual.column_names
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_grouping_should_set_record_class
|
286
|
+
a = Table(%w[a b c], :record_class => MyRecord) { |t|
|
287
|
+
t << [1,2,3]
|
288
|
+
t << [4,5,6]
|
289
|
+
}
|
290
|
+
b = Ruport::Data::Grouping.new(a, :by => "a")
|
291
|
+
assert_equal MyRecord, b[1].record_class
|
292
|
+
end
|
293
|
+
|
294
|
+
class MyGroupingSub < Ruport::Data::Grouping; end
|
295
|
+
|
296
|
+
def test_ensure_grouping_subclasses_render_properly
|
297
|
+
t = Table(%w[a b c]) << [1,2,3]
|
298
|
+
a = MyGroupingSub.new(t, :by => "a")
|
299
|
+
assert_equal "1\n\nb,c\n2,3\n\n", a.to_csv
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
303
|
+
|
304
|
+
class MyRecord < Ruport::Data::Record
|
305
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "ruport"
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "rubygems"
|
6
|
+
rescue LoadError
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestFormatHTML < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def test_html_table
|
13
|
+
a = Ruport::Formatter::HTML.new
|
14
|
+
|
15
|
+
actual = a.html_table { "<tr><td>1</td></tr>\n" }
|
16
|
+
assert_equal "<table>\n<tr><td>1</td></tr>\n</table>\n", actual
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_render_html_basic
|
20
|
+
|
21
|
+
actual = Ruport::Renderer::Table.render_html { |r|
|
22
|
+
r.data = [[1,2,3],[4,5,6]].to_table
|
23
|
+
}
|
24
|
+
|
25
|
+
assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
|
26
|
+
"</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t"+
|
27
|
+
"\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
28
|
+
"\t</tr>\n\t</table>",actual)
|
29
|
+
|
30
|
+
actual = Ruport::Renderer::Table.render_html { |r|
|
31
|
+
r.data = [ [1,2,3],[4,5,6]].to_table(%w[a b c])
|
32
|
+
}
|
33
|
+
|
34
|
+
assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
|
35
|
+
"\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
36
|
+
"\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
|
37
|
+
"\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
38
|
+
"\t</tr>\n\t</table>",actual)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_render_html_row
|
43
|
+
actual = Ruport::Renderer::Row.render_html { |r| r.data = [1,2,3] }
|
44
|
+
assert_equal("\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
|
45
|
+
"</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n",actual)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_render_html_group
|
49
|
+
group = Ruport::Data::Group.new(:name => 'test',
|
50
|
+
:data => [[1,2,3],[4,5,6]],
|
51
|
+
:column_names => %w[a b c])
|
52
|
+
actual = Ruport::Renderer::Group.render(:html, :data => group)
|
53
|
+
assert_equal "\t<p>test</p>\n"+
|
54
|
+
"\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
|
55
|
+
"\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
56
|
+
"\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
|
57
|
+
"\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
58
|
+
"\t</tr>\n\t</table>", actual
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_render_html_group_without_headers
|
62
|
+
group = Ruport::Data::Group.new(:name => 'test',
|
63
|
+
:data => [[1,2,3],[4,5,6]],
|
64
|
+
:column_names => %w[a b c])
|
65
|
+
actual = Ruport::Renderer::Group.render(:html, :data => group,
|
66
|
+
:show_table_headers => false)
|
67
|
+
assert_equal "\t<p>test</p>\n\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
68
|
+
"\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
|
69
|
+
"\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
70
|
+
"\t</tr>\n\t</table>", actual
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_render_html_grouping
|
74
|
+
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
75
|
+
g = Grouping(table,:by => "a")
|
76
|
+
actual = Ruport::Renderer::Grouping.render(:html, :data => g,
|
77
|
+
:show_table_headers => false)
|
78
|
+
|
79
|
+
assert_equal "\t<p>1</p>\n\t<table>\n\t\t<tr>\n\t\t\t<td>2</td>\n"+
|
80
|
+
"\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"+
|
81
|
+
"<td>3</td>\n\t\t</tr>\n\t</table>\n\t<p>2</p>\n\t<table>\n\t\t<tr>"+
|
82
|
+
"\n\t\t\t<td>7</td>\n\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n", actual
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_render_html_grouping_with_table_headers
|
86
|
+
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
87
|
+
g = Grouping(table,:by => "a")
|
88
|
+
actual = Ruport::Renderer::Grouping.render(:html, :data => g)
|
89
|
+
|
90
|
+
assert_equal "\t<p>1</p>\n\t<table>\n\t\t<tr>\n\t\t\t<th>b</th>\n"+
|
91
|
+
"\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>"+
|
92
|
+
"2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t"+
|
93
|
+
"\t<td>1</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t</table>\n"+
|
94
|
+
"\t<p>2</p>\n\t<table>\n\t\t<tr>\n\t\t\t<th>b</th>\n\t\t"+
|
95
|
+
"\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>7</td>\n"+
|
96
|
+
"\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n", actual
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_textile
|
100
|
+
a = Ruport::Formatter::HTML.new
|
101
|
+
assert_equal "<p><strong>foo</strong></p>", a.textile("*foo*")
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|