ruport 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +13 -4
- data/CHANGELOG +15 -1
- data/Rakefile +1 -1
- data/bin/rope +5 -1
- data/examples/basic_grouping.rb +13 -3
- data/examples/latex_table.rb +17 -0
- data/examples/line_graph_report.rb +23 -0
- data/examples/line_graph_report.rb.rej +15 -0
- data/examples/line_graph_report.rb~ +23 -0
- data/examples/line_plotter.rb +1 -0
- data/examples/sql_erb.rb +20 -0
- data/examples/template.rb +1 -1
- data/examples/text_processors.rb +3 -9
- data/lib/ruport.rb +2 -3
- data/lib/ruport.rb~ +69 -0
- data/lib/ruport/attempt.rb +63 -0
- data/lib/ruport/data.rb +1 -1
- data/lib/ruport/data.rb.rej +5 -0
- data/lib/ruport/data.rb~ +1 -0
- data/lib/ruport/data/groupable.rb +20 -0
- data/lib/ruport/data/record.rb +18 -13
- data/lib/ruport/data/table.rb +92 -26
- data/lib/ruport/data/table.rb~ +329 -0
- data/lib/ruport/format.rb +7 -1
- data/lib/ruport/format/engine/table.rb +2 -1
- data/lib/ruport/format/plugin.rb +8 -8
- data/lib/ruport/format/plugin/csv_plugin.rb +5 -1
- data/lib/ruport/format/plugin/html_plugin.rb +12 -8
- data/lib/ruport/format/plugin/latex_plugin.rb +50 -0
- data/lib/ruport/format/plugin/text_plugin.rb +38 -33
- data/lib/ruport/meta_tools.rb +3 -3
- data/lib/ruport/query.rb +21 -9
- data/lib/ruport/report.rb +35 -20
- data/lib/ruport/report/graph.rb +14 -0
- data/lib/ruport/system_extensions.rb +9 -8
- data/test/_test_groupable.rb +0 -0
- data/test/samples/data.tsv +3 -0
- data/test/samples/erb_test.sql +1 -0
- data/test/samples/query_test.sql +1 -0
- data/test/test_collection.rb +1 -1
- data/test/test_format.rb +1 -1
- data/test/test_format_engine.rb +17 -0
- data/test/test_groupable.rb +41 -0
- data/test/test_invoice.rb +1 -1
- data/test/test_latex.rb +20 -0
- data/test/test_plugin.rb +59 -29
- data/test/test_query.rb +12 -6
- data/test/test_record.rb +23 -4
- data/test/test_record.rb.rej +46 -0
- data/test/test_report.rb +32 -7
- data/test/test_table.rb +152 -4
- data/test/ts_all.rb +21 -0
- data/test/unit.log +61 -154
- metadata +32 -12
- data/lib/ruport/rails.rb +0 -2
- data/lib/ruport/rails/reportable.rb +0 -58
@@ -58,16 +58,17 @@ module Ruport
|
|
58
58
|
# A Unix savvy method to fetch the console columns, and rows.
|
59
59
|
def terminal_size
|
60
60
|
`stty size`.split.map { |x| x.to_i }.reverse
|
61
|
-
end
|
62
|
-
end
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
end
|
64
|
+
|
65
|
+
def terminal_width
|
66
|
+
terminal_size.first
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
def terminal_height
|
70
|
+
terminal_size.last
|
71
|
+
end
|
71
72
|
|
72
73
|
end
|
73
74
|
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
select * from <%= @table %>
|
@@ -0,0 +1 @@
|
|
1
|
+
select * from foo
|
data/test/test_collection.rb
CHANGED
data/test/test_format.rb
CHANGED
data/test/test_format_engine.rb
CHANGED
@@ -42,6 +42,16 @@ class MockPlugin < Ruport::Format::Plugin
|
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
+
class MockForTestingTableEngine < Ruport::Format::Plugin
|
46
|
+
|
47
|
+
renderer(:table) {}
|
48
|
+
|
49
|
+
format_field_names { raise }
|
50
|
+
plugin_name :table_mock
|
51
|
+
register_on :table_engine
|
52
|
+
|
53
|
+
end
|
54
|
+
|
45
55
|
class TestFormatEngine < Test::Unit::TestCase
|
46
56
|
|
47
57
|
def test_no_data_required
|
@@ -79,6 +89,13 @@ class TestTabularFormatEngine < Test::Unit::TestCase
|
|
79
89
|
@engine.active_plugin.apple = :banana
|
80
90
|
assert_equal :banana, @engine.active_plugin.apple
|
81
91
|
end
|
92
|
+
|
93
|
+
def test_ensure_column_names_only_rendered_if_non_empty
|
94
|
+
@engine.plugin = :mock
|
95
|
+
@engine.data = [[1,2,3]].to_table
|
96
|
+
assert_nothing_raised { @engine.render }
|
97
|
+
end
|
98
|
+
|
82
99
|
def test_basic_render
|
83
100
|
@engine.plugin = :mock
|
84
101
|
@engine.data = [[1,2,3],[4,5,6],[7,8,9]]
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "ruport"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class Ruport::Data::Table
|
5
|
+
include Ruport::Data::Groupable
|
6
|
+
end
|
7
|
+
|
8
|
+
# ticket:96
|
9
|
+
class TestGroupable < Test::Unit::TestCase
|
10
|
+
def test_simple
|
11
|
+
a = [[1,2],[3,4],[5,6],[7,8]].to_table(%w[a b])
|
12
|
+
a[0].tag(:foo); a[1].tag(:bar);
|
13
|
+
a[2].tag(:bar); a[3].tag(:foo);
|
14
|
+
|
15
|
+
|
16
|
+
expected = Ruport::Data::Record.new( [ [[1,2],[7,8]].to_table(%w[a b]),
|
17
|
+
[[3,4],[5,6]].to_table(%w[a b]) ],
|
18
|
+
:attributes => ["foo","bar"] )
|
19
|
+
assert_equal expected, a.group_by_tag
|
20
|
+
|
21
|
+
a[0].tag(:bar)
|
22
|
+
|
23
|
+
expected = Ruport::Data::Record.new( [ [[1,2],[7,8]].to_table(%w[a b]),
|
24
|
+
[[1,2],[3,4],[5,6]].to_table(%w[a b]) ],
|
25
|
+
:attributes => ["foo","bar"] )
|
26
|
+
assert_equal expected, a.group_by_tag
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_create_tag_group
|
30
|
+
a = [[1,2,3],[4,5,6],[7,8,9]].to_table(%w[a b c])
|
31
|
+
expected = Ruport::Data::Record.new( [ [[1,2,3],[7,8,9]].to_table(%w[a b c]),
|
32
|
+
[[4,5,6]].to_table(%w[a b c]) ],
|
33
|
+
:attributes => %w[starts_odd starts_even])
|
34
|
+
a.create_tag_group(:starts_odd) { |r| (r[0] % 2) != 0 }
|
35
|
+
a.create_tag_group(:starts_even) { |r| (r[0] % 2).zero? }
|
36
|
+
|
37
|
+
assert_equal expected, a.group_by_tag
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
data/test/test_invoice.rb
CHANGED
data/test/test_latex.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "ruport"
|
2
|
+
begin; require 'rubygems'; rescue LoadError; nil; end
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
class TestLatex < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@data = [[1,2,3,2],[3,4,5,6]].to_table(%w[a b c d])
|
9
|
+
end
|
10
|
+
|
11
|
+
# basic test to ensure bar charts render
|
12
|
+
def test_table_to_latex
|
13
|
+
report = Ruport::Format.table_object :plugin => :latex, :data => @data
|
14
|
+
output = report.render
|
15
|
+
assert_equal "\\documentclass", output[/\\documentclass/]
|
16
|
+
assert_equal "\\begin{document}", output[/\\begin\{document\}/]
|
17
|
+
assert_equal "\\end{document}", output[/\\end\{document\}/]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/test/test_plugin.rb
CHANGED
@@ -33,6 +33,11 @@ class TSVPlugin < Format::Plugin
|
|
33
33
|
|
34
34
|
end
|
35
35
|
|
36
|
+
class NakedPlugin < Ruport::Format::Plugin
|
37
|
+
plugin_name :naked
|
38
|
+
end
|
39
|
+
|
40
|
+
|
36
41
|
class TestPlugin < Test::Unit::TestCase
|
37
42
|
def test_helper
|
38
43
|
t = Ruport::Format.table_object :data => [[1,2]], :plugin => :tsv
|
@@ -58,9 +63,26 @@ class TestPlugin < Test::Unit::TestCase
|
|
58
63
|
assert_nil t.options
|
59
64
|
end
|
60
65
|
|
66
|
+
def test_register_on
|
67
|
+
a = NakedPlugin.dup
|
68
|
+
assert a.respond_to?(:register_on)
|
69
|
+
assert_raise(InvalidPluginError) {
|
70
|
+
Ruport::Format.table_object(:plugin => :naked)
|
71
|
+
}
|
72
|
+
assert_raise(InvalidPluginError) {
|
73
|
+
Ruport::Format.document_object(:plugin => :naked)
|
74
|
+
}
|
75
|
+
a.register_on :table_engine, :document_engine
|
76
|
+
assert_nothing_raised {
|
77
|
+
Ruport::Format.table_object(:plugin => :naked)
|
78
|
+
Ruport::Format.document_object(:plugin => :naked)
|
79
|
+
}
|
80
|
+
|
81
|
+
end
|
82
|
+
|
61
83
|
end
|
62
84
|
|
63
|
-
class
|
85
|
+
class TestCSVPlugin < Test::Unit::TestCase
|
64
86
|
|
65
87
|
def test_basic
|
66
88
|
a = Format.table_object :plugin => :csv, :data => [[1,2],[3,4]]
|
@@ -83,7 +105,7 @@ class CSVPluginTest < Test::Unit::TestCase
|
|
83
105
|
|
84
106
|
end
|
85
107
|
|
86
|
-
class
|
108
|
+
class TestPDFPlugin < Test::Unit::TestCase
|
87
109
|
|
88
110
|
def test_ensure_fails_on_array
|
89
111
|
begin
|
@@ -124,28 +146,35 @@ class PDFPluginTest < Test::Unit::TestCase
|
|
124
146
|
|
125
147
|
end
|
126
148
|
|
127
|
-
class
|
149
|
+
class TestHTMLPlugin < Test::Unit::TestCase
|
128
150
|
|
129
151
|
def test_basic
|
130
152
|
a = Format.table_object :plugin => :html, :data => [[1,2],[3,nil]]
|
131
|
-
assert_equal("<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2</td>"+
|
153
|
+
assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2</td>"+
|
132
154
|
"\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>3</td>\n\t\t\t<td> "+
|
133
155
|
"</td>\n\t\t</tr>\n\t</table>",a.render)
|
134
156
|
a.data = a.data.to_table(:column_names => %w[a b])
|
135
|
-
assert_equal("<table>\n\t\t<tr>\n\t\t\t<th>a
|
157
|
+
assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
|
136
158
|
"\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>"+
|
137
159
|
"2</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>3</td>\n\t\t\t<td>"+
|
138
160
|
" </td>\n\t\t</tr>\n\t</table>",a.render)
|
139
161
|
a.show_field_names = false
|
140
|
-
assert_equal("<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2</td>"+
|
162
|
+
assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2</td>"+
|
141
163
|
"\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>3</td>\n\t\t\t<td> "+
|
142
164
|
"</td>\n\t\t</tr>\n\t</table>",a.render)
|
165
|
+
a.data[0].tag(:odd)
|
166
|
+
a.data[1].tag(:even)
|
167
|
+
assert_equal("\t<table>\n\t\t<tr class='odd'>\n\t\t\t<td class='odd'>"+
|
168
|
+
"1</td>\n\t\t\t<td class='odd'>2</td>\n\t\t</tr>\n\t\t"+
|
169
|
+
"<tr class='even'>\n\t\t\t<td class='even'>3</td>\n\t\t\t"+
|
170
|
+
"<td class='even'> </td>\n\t\t</tr>\n\t</table>",
|
171
|
+
a.render)
|
143
172
|
end
|
144
173
|
end
|
145
174
|
|
146
175
|
|
147
176
|
#this test is intended to ensure proper functionality of the plugin system.
|
148
|
-
class
|
177
|
+
class TestNewPlugin < Test::Unit::TestCase
|
149
178
|
|
150
179
|
def test_basic
|
151
180
|
a = Format.table_object :plugin => :tsv, :data => [[1,2],[3,4]]
|
@@ -160,7 +189,7 @@ class NewPluginTest < Test::Unit::TestCase
|
|
160
189
|
|
161
190
|
end
|
162
191
|
|
163
|
-
class
|
192
|
+
class TestTextPlugin < Test::Unit::TestCase
|
164
193
|
|
165
194
|
def test_basic
|
166
195
|
|
@@ -176,38 +205,29 @@ class TextPluginTest < Test::Unit::TestCase
|
|
176
205
|
|
177
206
|
def test_max_col_width
|
178
207
|
a = Format.table_object :plugin => :text, :data => [[1,2],[300,4]]
|
179
|
-
|
180
|
-
assert_equal(
|
181
|
-
|
182
|
-
a.data = [[1,2],[300,4]].to_table(:column_names => %w[a b])
|
208
|
+
a.active_plugin.calculate_max_col_widths
|
209
|
+
assert_equal(3,a.active_plugin.max_col_width[0])
|
210
|
+
assert_equal(1,a.active_plugin.max_col_width[1])
|
183
211
|
|
184
|
-
|
185
|
-
|
186
|
-
assert_equal(3,a.active_plugin.max_col_width
|
212
|
+
a.data = [[1,2],[300,4]].to_table(:column_names => %w[a ba])
|
213
|
+
a.active_plugin.calculate_max_col_widths
|
214
|
+
assert_equal(3,a.active_plugin.max_col_width[0])
|
215
|
+
assert_equal(2,a.active_plugin.max_col_width[1])
|
187
216
|
|
188
217
|
a.data = [[1,2],[3,40000]].to_table(:column_names => %w[foo bazz])
|
189
|
-
|
190
|
-
assert_equal(
|
191
|
-
|
192
|
-
assert_equal(3,a.active_plugin.max_col_width(0))
|
193
|
-
assert_equal(5,a.active_plugin.max_col_width(1))
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_table_width
|
197
|
-
a = Format.table_object :plugin => :text, :data => [[1,2],[300,4]]
|
198
|
-
assert_equal(4,a.active_plugin.table_width)
|
199
|
-
|
200
|
-
a.data = [[1,2],[3,40000]].to_table(:column_names =>%w[foo bazz])
|
201
|
-
assert_equal(8,a.active_plugin.table_width)
|
218
|
+
a.active_plugin.calculate_max_col_widths
|
219
|
+
assert_equal(3,a.active_plugin.max_col_width[0])
|
220
|
+
assert_equal(5,a.active_plugin.max_col_width[1])
|
202
221
|
end
|
203
222
|
|
204
223
|
def test_hr
|
205
224
|
a = Format.table_object :plugin => :text, :data => [[1,2],[300,4]]
|
206
|
-
|
225
|
+
a.active_plugin.calculate_max_col_widths
|
207
226
|
assert_equal("+---------+\n",a.active_plugin.hr)
|
208
227
|
|
209
228
|
|
210
229
|
a.data = [[1,2],[3,40000]].to_table(:column_names => %w[foo bazz])
|
230
|
+
a.active_plugin.calculate_max_col_widths
|
211
231
|
assert_equal "+-------------+\n", a.active_plugin.hr
|
212
232
|
|
213
233
|
end
|
@@ -237,6 +257,16 @@ class TextPluginTest < Test::Unit::TestCase
|
|
237
257
|
assert_equal(nil,a.active_plugin.right_margin)
|
238
258
|
end
|
239
259
|
|
260
|
+
|
261
|
+
def test_make_sure_this_damn_column_names_bug_dies_a_horrible_death!
|
262
|
+
a = Format.table :plugin => :text, :data => [[1,2,3]].to_table
|
263
|
+
expected = "+-----------+\n"+
|
264
|
+
"| 1 | 2 | 3 |\n"+
|
265
|
+
"+-----------+\n"
|
266
|
+
assert_equal(expected,a)
|
267
|
+
|
268
|
+
end
|
269
|
+
|
240
270
|
def test_graceful_failure_on_empty_table
|
241
271
|
assert_nothing_raised { [].to_table.to_text }
|
242
272
|
assert_nothing_raised { [].to_table(%w[a b c]).to_text }
|
data/test/test_query.rb
CHANGED
@@ -19,7 +19,18 @@ class TestQuery < Test::Unit::TestCase
|
|
19
19
|
assert_nothing_raised { @query1.result }
|
20
20
|
assert_equal([[1,2,3],[4,5,6],[7,8,9]],@query1.result)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
|
+
def test_auto_resolve_file
|
24
|
+
q = Ruport::Query.new "test/samples/query_test.sql"
|
25
|
+
assert_equal "select * from foo", q.sql
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_erb_replacement
|
29
|
+
@table = 'bar'
|
30
|
+
q = Ruport::Query.new "test/samples/erb_test.sql", :binding => binding
|
31
|
+
assert_equal "select * from bar", q.sql
|
32
|
+
end
|
33
|
+
|
23
34
|
def test_each
|
24
35
|
data = [[1,2,3],[4,5,6],[7,8,9]]
|
25
36
|
@query1.each do |r|
|
@@ -61,11 +72,6 @@ class TestQuery < Test::Unit::TestCase
|
|
61
72
|
assert_raise(EOFError) { gen.next }
|
62
73
|
end
|
63
74
|
|
64
|
-
def test_to_dataset
|
65
|
-
# query needs to be re-worked for a test like this
|
66
|
-
# to be written
|
67
|
-
end
|
68
|
-
|
69
75
|
def test_caching_triggers
|
70
76
|
assert_nothing_raised { @query1.enable_caching }
|
71
77
|
assert_nothing_raised { @query1.disable_caching }
|
data/test/test_record.rb
CHANGED
@@ -2,7 +2,7 @@ require "test/unit"
|
|
2
2
|
require "ruport"
|
3
3
|
|
4
4
|
|
5
|
-
class
|
5
|
+
class TestRecord < Test::Unit::TestCase
|
6
6
|
|
7
7
|
include Ruport::Data
|
8
8
|
|
@@ -170,11 +170,30 @@ class RecordTest < Test::Unit::TestCase
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_records_with_differing_attrs_and_data_hash_differently
|
173
|
-
r = Record.new
|
174
|
-
s = Record.new
|
173
|
+
r = Record.new [1,2],:attributes => %w[a b]
|
174
|
+
s = Record.new [nil,nil],:attributes => %w[a b]
|
175
175
|
assert r.hash != s.hash
|
176
176
|
|
177
|
-
t = Record.new
|
177
|
+
t = Record.new [1,3],:attributes => %w[a b]
|
178
178
|
assert r.hash != t.hash
|
179
179
|
end
|
180
|
+
|
181
|
+
# ticket:71
|
182
|
+
def test_record_has_indifferent_access
|
183
|
+
t = Record.new [1,2,3], :attributes => %w[a b c]
|
184
|
+
assert_equal [1,2,3], [t[0],t[1],t[2]]
|
185
|
+
assert_equal [1,2,3], [t["a"],t["b"],t["c"]]
|
186
|
+
assert_equal [1,2,3], [t.a,t.b,t.c]
|
187
|
+
|
188
|
+
assert_equal [1,2,3], [t[:a],t[:b],t[:c]]
|
189
|
+
|
190
|
+
x = Record.new [1,2,3], :attributes => [:a,:b,:c]
|
191
|
+
assert_equal [1,2,3], [x[0],x[1],x[2]]
|
192
|
+
assert_equal [1,2,3], [x[:a],x[:b],x[:c]]
|
193
|
+
|
194
|
+
#FIXME: ...
|
195
|
+
|
196
|
+
assert_equal [1,2,3], [x["a"],x["b"],x["c"]]
|
197
|
+
assert_equal [1,2,3], [x.a,x.b,x.c]
|
198
|
+
end
|
180
199
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
***************
|
2
|
+
*** 170,180 ****
|
3
|
+
end
|
4
|
+
|
5
|
+
def test_records_with_differing_attrs_and_data_hash_differently
|
6
|
+
- r = Record.new :attributes => %w[a b], :data => [1,2]
|
7
|
+
- s = Record.new :attributes => %w[a b]
|
8
|
+
assert r.hash != s.hash
|
9
|
+
|
10
|
+
- t = Record.new :attributes => %w[a b], :data => [1,3]
|
11
|
+
assert r.hash != t.hash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
--- 170,201 ----
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_records_with_differing_attrs_and_data_hash_differently
|
18
|
+
+ r = Record.new [1,2],:attributes => %w[a b]
|
19
|
+
+ s = Record.new [nil,nil],:attributes => %w[a b]
|
20
|
+
assert r.hash != s.hash
|
21
|
+
|
22
|
+
+ t = Record.new [1,3],:attributes => %w[a b]
|
23
|
+
assert r.hash != t.hash
|
24
|
+
end
|
25
|
+
+
|
26
|
+
+ # ticket:71
|
27
|
+
+ def test_record_has_indifferent_access
|
28
|
+
+ t = Record.new [1,2,3], :attributes => %w[a b c]
|
29
|
+
+ assert_equal [1,2,3], [t[0],t[1],t[2]]
|
30
|
+
+ assert_equal [1,2,3], [t["a"],t["b"],t["c"]]
|
31
|
+
+ assert_equal [1,2,3], [t.a,t.b,t.c]
|
32
|
+
+
|
33
|
+
+ #FIXME: Dinko, the commented out tests need to pass
|
34
|
+
+
|
35
|
+
+ # assert_equal [1,2,3], [t[:a],t[:b],t[:c]]
|
36
|
+
+
|
37
|
+
+ x = Record.new [1,2,3], :attributes => [:a,:b,:c]
|
38
|
+
+ assert_equal [1,2,3], [x[0],x[1],x[2]]
|
39
|
+
+ assert_equal [1,2,3], [x[:a],x[:b],x[:c]]
|
40
|
+
+
|
41
|
+
+ #FIXME: ...
|
42
|
+
+
|
43
|
+
+ #assert_equal [1,2,3], [x["a"],x["b"],x["c"]]
|
44
|
+
+ #assert_equal [1,2,3], [x.a,x.b,x.c]
|
45
|
+
+ end
|
46
|
+
end
|