ruport 1.6.3 → 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.
- checksums.yaml +7 -0
- data/AUTHORS +11 -0
- data/README.rdoc +105 -0
- data/Rakefile +13 -44
- data/examples/add_row_table.rb +46 -0
- data/examples/data/wine.csv +255 -0
- data/examples/pdf_grouping.rb +39 -0
- data/examples/pdf_table.rb +28 -0
- data/examples/pdf_table_from_csv.rb +26 -0
- data/examples/pdf_table_prawn.rb +30 -0
- data/examples/pdf_table_simple.rb +13 -0
- data/lib/ruport.rb +0 -12
- data/lib/ruport/controller.rb +16 -20
- data/lib/ruport/data/feeder.rb +2 -2
- data/lib/ruport/data/grouping.rb +2 -2
- data/lib/ruport/data/table.rb +314 -202
- data/lib/ruport/formatter.rb +53 -52
- data/lib/ruport/formatter/csv.rb +6 -7
- data/lib/ruport/formatter/html.rb +13 -11
- data/lib/ruport/formatter/pdf.rb +73 -75
- data/lib/ruport/formatter/prawn_pdf.rb +72 -0
- data/lib/ruport/formatter/template.rb +1 -1
- data/lib/ruport/version.rb +1 -1
- data/test/controller_test.rb +100 -122
- data/test/csv_formatter_test.rb +15 -15
- data/test/data_feeder_test.rb +26 -26
- data/test/grouping_test.rb +30 -29
- data/test/helpers.rb +18 -10
- data/test/html_formatter_test.rb +24 -24
- data/test/record_test.rb +14 -14
- data/test/samples/sales.csv +21 -0
- data/test/table_pivot_test.rb +68 -24
- data/test/table_test.rb +365 -336
- data/test/template_test.rb +1 -1
- data/test/text_formatter_test.rb +19 -19
- data/util/bench/data/table/bench_init.rb +1 -1
- metadata +123 -75
- data/README +0 -114
- data/test/pdf_formatter_test.rb +0 -354
data/test/csv_formatter_test.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby -w
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
3
3
|
|
4
|
-
class TestRenderCSVRow < Test
|
4
|
+
class TestRenderCSVRow < Minitest::Test
|
5
5
|
def test_render_csv_row
|
6
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
|
10
10
|
|
11
|
-
class TestRenderCSVTable < Test
|
11
|
+
class TestRenderCSVTable < Minitest::Test
|
12
12
|
|
13
13
|
def setup
|
14
14
|
Ruport::Formatter::Template.create(:simple) do |format|
|
@@ -25,18 +25,18 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
25
25
|
|
26
26
|
def test_render_csv_table
|
27
27
|
actual = Ruport::Controller::Table.render_csv do |r|
|
28
|
-
r.data = Table([], :data => [[1,2,3],[4,5,6]])
|
28
|
+
r.data = Ruport.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
32
|
actual = Ruport::Controller::Table.render_csv do |r|
|
33
|
-
r.data = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
33
|
+
r.data = Ruport.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)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_format_options
|
39
|
-
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
39
|
+
a = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
40
40
|
assert_equal "a\tb\tc\n1\t2\t3\n4\t5\t6\n",
|
41
41
|
a.as(:csv,:format_options => { :col_sep => "\t" })
|
42
42
|
end
|
@@ -44,7 +44,7 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
44
44
|
def test_table_headers
|
45
45
|
actual = Ruport::Controller::Table.
|
46
46
|
render_csv(:show_table_headers => false,
|
47
|
-
:data => Table(%w[a b c], :data => [[1,2,3],[4,5,6]]))
|
47
|
+
:data => Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]]))
|
48
48
|
assert_equal("1,2,3\n4,5,6\n",actual)
|
49
49
|
end
|
50
50
|
|
@@ -64,7 +64,7 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
64
64
|
|
65
65
|
def test_options_hashes_override_template
|
66
66
|
opts = nil
|
67
|
-
table = Table(%w[a b c])
|
67
|
+
table = Ruport.Table(%w[a b c])
|
68
68
|
table.to_csv(
|
69
69
|
:template => :simple,
|
70
70
|
:table_format => {
|
@@ -86,7 +86,7 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
86
86
|
|
87
87
|
def test_individual_options_override_template
|
88
88
|
opts = nil
|
89
|
-
table = Table(%w[a b c])
|
89
|
+
table = Ruport.Table(%w[a b c])
|
90
90
|
table.to_csv(
|
91
91
|
:template => :simple,
|
92
92
|
:show_table_headers => true,
|
@@ -106,7 +106,7 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
class TestRenderCSVGroup < Test
|
109
|
+
class TestRenderCSVGroup < Minitest::Test
|
110
110
|
|
111
111
|
def test_render_csv_group
|
112
112
|
group = Ruport::Data::Group.new(:name => 'test',
|
@@ -119,9 +119,9 @@ class TestRenderCSVGroup < Test::Unit::TestCase
|
|
119
119
|
|
120
120
|
end
|
121
121
|
|
122
|
-
class RenderCSVGrouping < Test
|
122
|
+
class RenderCSVGrouping < Minitest::Test
|
123
123
|
def test_render_csv_grouping
|
124
|
-
table = Table(%w[hi red snapper]) << %w[is this annoying] <<
|
124
|
+
table = Ruport.Table(%w[hi red snapper]) << %w[is this annoying] <<
|
125
125
|
%w[is it funny]
|
126
126
|
grouping = Grouping(table,:by => "hi")
|
127
127
|
|
@@ -131,7 +131,7 @@ class RenderCSVGrouping < Test::Unit::TestCase
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def test_render_csv_grouping_without_header
|
134
|
-
table = Table(%w[hi red snapper]) << %w[is this annoying] <<
|
134
|
+
table = Ruport.Table(%w[hi red snapper]) << %w[is this annoying] <<
|
135
135
|
%w[is it funny]
|
136
136
|
grouping = Grouping(table,:by => "hi")
|
137
137
|
|
@@ -141,10 +141,10 @@ class RenderCSVGrouping < Test::Unit::TestCase
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def test_alternative_styles
|
144
|
-
g = Grouping((Table(%w[a b c]) << [1,2,3] << [1,1,4] <<
|
144
|
+
g = Grouping((Ruport.Table(%w[a b c]) << [1,2,3] << [1,1,4] <<
|
145
145
|
[2,1,2] << [1,9,1] ), :by => "a")
|
146
146
|
|
147
|
-
|
147
|
+
assert_raises(NotImplementedError) { g.to_csv :style => :not_real }
|
148
148
|
|
149
149
|
assert_equal "a,b,c\n1,2,3\n,1,4\n,9,1\n\n2,1,2\n\n",
|
150
150
|
g.to_csv(:style => :justified)
|
@@ -158,7 +158,7 @@ class RenderCSVGrouping < Test::Unit::TestCase
|
|
158
158
|
# ------------------------------------------------------------------------
|
159
159
|
|
160
160
|
def test_ensure_group_names_are_converted_to_string
|
161
|
-
g = Grouping((Table(%w[a b c])<<[1,2,3]<<[1,1,4]), :by => "a")
|
161
|
+
g = Grouping((Ruport.Table(%w[a b c])<<[1,2,3]<<[1,1,4]), :by => "a")
|
162
162
|
assert_equal "1\n\nb,c\n2,3\n1,4\n\n", g.to_csv
|
163
163
|
end
|
164
164
|
end
|
data/test/data_feeder_test.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby -w
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
3
3
|
|
4
|
-
class DataFeederTest < Test
|
4
|
+
class DataFeederTest < Minitest::Test
|
5
5
|
|
6
6
|
context "when using a default data feeder" do
|
7
7
|
|
8
|
-
|
9
|
-
@feeder = Ruport::Data::Feeder.new(Table(%w[a b c]))
|
8
|
+
setup do
|
9
|
+
@feeder = Ruport::Data::Feeder.new(Ruport.Table(%w[a b c]))
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
assert_equal Table(%w[a b c]), @feeder.data
|
12
|
+
should "data attribute should return wrapped data" do
|
13
|
+
assert_equal Ruport.Table(%w[a b c]), @feeder.data
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
t = Table(%w[a b c])
|
16
|
+
should "append should forward to wrapped data by default" do
|
17
|
+
t = Ruport.Table(%w[a b c])
|
18
18
|
t << [1,2,3] << {"a" => 2, "b" => 3, "c" => 4}
|
19
19
|
@feeder << [1,2,3] << {"a" => 2, "b" => 3, "c" => 4}
|
20
20
|
assert_equal t, @feeder.data
|
@@ -23,66 +23,66 @@ class DataFeederTest < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when using a feeder with a filter" do
|
26
|
-
|
27
|
-
@feeder = Ruport::Data::Feeder.new(Table(%w[a b c]))
|
26
|
+
setup do
|
27
|
+
@feeder = Ruport::Data::Feeder.new(Ruport.Table(%w[a b c]))
|
28
28
|
@feeder.filter { |r| r.a != 1 }
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
should "filter should only append rows for which block is true" do
|
32
32
|
@feeder << [1,2,3] << [4,1,2] << [3,1,1] << [1,2,5]
|
33
|
-
assert_equal Table(%w[a b c], :data => [[4,1,2],[3,1,1]]), @feeder.data
|
33
|
+
assert_equal Ruport.Table(%w[a b c], :data => [[4,1,2],[3,1,1]]), @feeder.data
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
context "when using a feeder with a transform" do
|
38
|
-
|
39
|
-
@feeder = Ruport::Data::Feeder.new(Table(%w[a b c]))
|
38
|
+
setup do
|
39
|
+
@feeder = Ruport::Data::Feeder.new(Ruport.Table(%w[a b c]))
|
40
40
|
@feeder.transform { |r| r.a += 1 }
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
should "filter should be applied to all rows" do
|
44
44
|
@feeder << [1,2,3] << [4,1,2] << [3,1,1] << [1,2,5]
|
45
|
-
assert_equal Table(%w[a b c], :data => [[2,2,3],[5,1,2],[4,1,1],[2,2,5]]),
|
45
|
+
assert_equal Ruport.Table(%w[a b c], :data => [[2,2,3],[5,1,2],[4,1,1],[2,2,5]]),
|
46
46
|
@feeder.data
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
context "when using a feeder and a filter together" do
|
51
|
-
|
52
|
-
@feeder = Ruport::Data::Feeder.new(Table(%w[a b c]))
|
51
|
+
setup do
|
52
|
+
@feeder = Ruport::Data::Feeder.new(Ruport.Table(%w[a b c]))
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
should "filter is called first when defined first" do
|
56
56
|
@feeder.filter { |r| r.b != 2 }
|
57
57
|
@feeder.transform { |r| r.b += 1 }
|
58
58
|
@feeder << [1,2,3] << [4,1,2] << [3,1,1] << [1,2,5]
|
59
|
-
assert_equal Table(%w[a b c], :data => [[4,2,2],[3,2,1]]),
|
59
|
+
assert_equal Ruport.Table(%w[a b c], :data => [[4,2,2],[3,2,1]]),
|
60
60
|
@feeder.data
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
should "transform is called first when defined first" do
|
64
64
|
@feeder.transform { |r| r.b += 1 }
|
65
65
|
@feeder.filter { |r| r.b != 2 }
|
66
66
|
@feeder << [1,2,3] << [4,1,2] << [3,1,1] << [1,2,5]
|
67
|
-
assert_equal Table(%w[a b c], :data => [[1,3,3],[1,3,5]]),
|
67
|
+
assert_equal Ruport.Table(%w[a b c], :data => [[1,3,3],[1,3,5]]),
|
68
68
|
@feeder.data
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
context "when using many feeders and filters together" do
|
73
|
-
|
74
|
-
@feeder = Ruport::Data::Feeder.new(Table(%w[a b c]))
|
73
|
+
setup do
|
74
|
+
@feeder = Ruport::Data::Feeder.new(Ruport.Table(%w[a b c]))
|
75
75
|
@feeder.transform { |r| r.a += 1 }
|
76
76
|
@feeder.filter { |r| r.a > 5 }
|
77
77
|
@feeder.transform { |r| r.b = r.b.to_s }
|
78
78
|
@feeder.filter { |r| r.b == "3" }
|
79
79
|
end
|
80
80
|
|
81
|
-
|
81
|
+
should "all blocks are executed in order" do
|
82
82
|
@feeder << [1,2,3] << [4,1,9] << [5,3,1] << [2,3,0] << [7,3,5]
|
83
|
-
assert_equal Table(%w[a b c], :data => [[6,"3",1],[8,"3",5]]),
|
83
|
+
assert_equal Ruport.Table(%w[a b c], :data => [[6,"3",1],[8,"3",5]]),
|
84
84
|
@feeder.data
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
end
|
88
|
+
end
|
data/test/grouping_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby -w
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
3
3
|
|
4
|
-
class TestGroup < Test
|
4
|
+
class TestGroup < Minitest::Test
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@group = Ruport::Data::Group.new(:name => 'test',
|
@@ -34,7 +34,7 @@ class TestGroup < Test::Unit::TestCase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_eql
|
37
|
-
table = Table(%w[a b c], :data => [[1,2,3]])
|
37
|
+
table = Ruport.Table(%w[a b c], :data => [[1,2,3]])
|
38
38
|
|
39
39
|
group2 = Ruport::Data::Group.new(:name => 'test',
|
40
40
|
:data => [[1,2,3]],
|
@@ -79,7 +79,7 @@ class TestGroup < Test::Unit::TestCase
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
class TestGroupRendering < Test
|
82
|
+
class TestGroupRendering < Minitest::Test
|
83
83
|
|
84
84
|
def setup
|
85
85
|
@group = Ruport::Data::Group.new(:name => 'test',
|
@@ -88,15 +88,16 @@ class TestGroupRendering < Test::Unit::TestCase
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_group_as
|
91
|
-
assert_equal(7, @group.to_text.
|
91
|
+
assert_equal(7, @group.to_text.split("\n").size)
|
92
92
|
assert_equal(5, @group.as(:text,
|
93
|
-
:show_table_headers => false).
|
94
|
-
assert_equal(
|
93
|
+
:show_table_headers => false).split("\n").size)
|
94
|
+
assert_equal(15, @group.to_html.split("\n").size)
|
95
|
+
assert_equal(8, @group.to_html(:show_table_headers => false).split("\n").size)
|
95
96
|
end
|
96
97
|
|
97
98
|
def test_as_throws_proper_errors
|
98
|
-
|
99
|
-
|
99
|
+
@group.as(:csv)
|
100
|
+
@group.to_csv
|
100
101
|
assert_raises(Ruport::Controller::UnknownFormatError) {
|
101
102
|
@group.as(:nothing) }
|
102
103
|
assert_raises(Ruport::Controller::UnknownFormatError) {
|
@@ -111,15 +112,15 @@ class TestGroupRendering < Test::Unit::TestCase
|
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
114
|
-
class TestGrouping < Test
|
115
|
+
class TestGrouping < Minitest::Test
|
115
116
|
|
116
117
|
def setup
|
117
|
-
table = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
118
|
+
table = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
118
119
|
@grouping = Ruport::Data::Grouping.new(table, :by => "a")
|
119
120
|
end
|
120
121
|
|
121
122
|
def test_grouping_constructor
|
122
|
-
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
123
|
+
a = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
123
124
|
b = Ruport::Data::Grouping.new(a, :by => "a")
|
124
125
|
c = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
125
126
|
:column_names => %w[b c],
|
@@ -174,7 +175,7 @@ class TestGrouping < Test::Unit::TestCase
|
|
174
175
|
end
|
175
176
|
|
176
177
|
def test_append
|
177
|
-
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
178
|
+
a = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
178
179
|
@grouping << a.to_group("red snapper")
|
179
180
|
assert_equal @grouping["red snapper"], a.to_group("red snapper")
|
180
181
|
|
@@ -186,7 +187,7 @@ class TestGrouping < Test::Unit::TestCase
|
|
186
187
|
end
|
187
188
|
|
188
189
|
def test_grouping_on_multiple_columns
|
189
|
-
a = Table(%w[a b c d], :data => [[1,2,3,4],[4,5,6,7]])
|
190
|
+
a = Ruport.Table(%w[a b c d], :data => [[1,2,3,4],[4,5,6,7]])
|
190
191
|
b = Ruport::Data::Grouping.new(a, :by => %w[a b c])
|
191
192
|
c = { 1 => Ruport::Data::Group.new( :data => [[2,3,4]],
|
192
193
|
:column_names => %w[b c d],
|
@@ -207,7 +208,7 @@ class TestGrouping < Test::Unit::TestCase
|
|
207
208
|
end
|
208
209
|
|
209
210
|
def test_subgrouping
|
210
|
-
a = Table(%w[first_name last_name id])
|
211
|
+
a = Ruport.Table(%w[first_name last_name id])
|
211
212
|
a << %w[ greg brown awesome ]
|
212
213
|
a << %w[ mike milner schweet ]
|
213
214
|
a << %w[ greg brown sick ]
|
@@ -233,12 +234,12 @@ class TestGrouping < Test::Unit::TestCase
|
|
233
234
|
end
|
234
235
|
|
235
236
|
def test_grouping_summary
|
236
|
-
source = Table(File.join(File.expand_path(File.dirname(__FILE__)),
|
237
|
+
source = Ruport.Table(File.join(File.expand_path(File.dirname(__FILE__)),
|
237
238
|
*%w[samples ticket_count.csv]),
|
238
239
|
:record_class => TicketStatus)
|
239
240
|
grouping = Grouping(source,:by => "date")
|
240
241
|
|
241
|
-
expected = Table(:date, :opened,:closed)
|
242
|
+
expected = Ruport.Table(:date, :opened,:closed)
|
242
243
|
grouping.each do |date,group|
|
243
244
|
opened = group.sigma { |r| r.opened }
|
244
245
|
closed = group.sigma { |r| r.closed }
|
@@ -284,10 +285,10 @@ class TestGrouping < Test::Unit::TestCase
|
|
284
285
|
end
|
285
286
|
end
|
286
287
|
|
287
|
-
|
288
|
+
describe "when sorting groupings" do
|
288
289
|
|
289
290
|
def setup
|
290
|
-
@table = Table(%w[a b c]) << ["dog",1,2] << ["cat",3,5] <<
|
291
|
+
@table = Ruport.Table(%w[a b c]) << ["dog",1,2] << ["cat",3,5] <<
|
291
292
|
["banana",8,1] << ["dog",5,6] << ["dog",2,4] << ["banana",7,9]
|
292
293
|
end
|
293
294
|
|
@@ -346,7 +347,7 @@ class TestGrouping < Test::Unit::TestCase
|
|
346
347
|
class MyRecord < Ruport::Data::Record; end
|
347
348
|
|
348
349
|
def test_grouping_should_set_record_class
|
349
|
-
a = Table(%w[a b c], :record_class => MyRecord) { |t|
|
350
|
+
a = Ruport.Table(%w[a b c], :record_class => MyRecord) { |t|
|
350
351
|
t << [1,2,3]
|
351
352
|
t << [4,5,6]
|
352
353
|
}
|
@@ -357,28 +358,28 @@ class TestGrouping < Test::Unit::TestCase
|
|
357
358
|
class MyGroupingSub < Ruport::Data::Grouping; end
|
358
359
|
|
359
360
|
def test_ensure_grouping_subclasses_render_properly
|
360
|
-
t = Table(%w[a b c]) << [1,2,3]
|
361
|
+
t = Ruport.Table(%w[a b c]) << [1,2,3]
|
361
362
|
a = MyGroupingSub.new(t, :by => "a")
|
362
363
|
assert_equal "1\n\nb,c\n2,3\n\n", a.to_csv
|
363
364
|
end
|
364
365
|
end
|
365
366
|
|
366
|
-
class TestGroupingRendering < Test
|
367
|
+
class TestGroupingRendering < Minitest::Test
|
367
368
|
|
368
369
|
def setup
|
369
|
-
table = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
370
|
+
table = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
370
371
|
@grouping = Ruport::Data::Grouping.new(table, :by => "a")
|
371
372
|
end
|
372
373
|
|
373
374
|
def test_grouping_as
|
374
|
-
assert_equal(
|
375
|
-
assert_equal(
|
376
|
-
:show_table_headers => false).
|
375
|
+
assert_equal(15, @grouping.to_text.split("\n").size)
|
376
|
+
assert_equal(11, @grouping.as(:text,
|
377
|
+
:show_table_headers => false).split("\n").size)
|
377
378
|
end
|
378
379
|
|
379
380
|
def test_as_throws_proper_errors
|
380
|
-
|
381
|
-
|
381
|
+
@grouping.as(:csv)
|
382
|
+
@grouping.to_csv
|
382
383
|
assert_raises(Ruport::Controller::UnknownFormatError) {
|
383
384
|
@grouping.as(:nothing) }
|
384
385
|
assert_raises(Ruport::Controller::UnknownFormatError) {
|
@@ -386,7 +387,7 @@ class TestGroupingRendering < Test::Unit::TestCase
|
|
386
387
|
end
|
387
388
|
end
|
388
389
|
|
389
|
-
class TestGroupingKernelHacks < Test
|
390
|
+
class TestGroupingKernelHacks < Minitest::Test
|
390
391
|
|
391
392
|
def test_group_kernel_hack
|
392
393
|
group = Ruport::Data::Group.new( :name => 'test',
|
@@ -397,7 +398,7 @@ class TestGroupingKernelHacks < Test::Unit::TestCase
|
|
397
398
|
end
|
398
399
|
|
399
400
|
def test_grouping_kernel_hack
|
400
|
-
table = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
401
|
+
table = Ruport.Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
|
401
402
|
grouping = Ruport::Data::Grouping.new(table, :by => "a")
|
402
403
|
a = { 1 => Ruport::Data::Group.new( :data => [[2,3]],
|
403
404
|
:column_names => %w[b c],
|
data/test/helpers.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
-
require
|
4
|
-
begin; require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
require 'ruport'
|
4
|
+
begin; require 'rubygems'; rescue LoadError; nil; end
|
5
|
+
|
6
|
+
|
7
|
+
require 'minitest'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
|
10
|
+
require 'minitest/spec'
|
11
|
+
require 'minitest/unit'
|
12
|
+
require 'shoulda-context'
|
13
|
+
require 'mocha/mini_test'
|
14
|
+
class Minitest::Test
|
15
|
+
include Ruport
|
16
|
+
end
|
17
|
+
|
18
|
+
TEST_SAMPLES = File.join(File.expand_path(File.dirname(__FILE__)), "samples")
|
data/test/html_formatter_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby -w
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
3
3
|
|
4
|
-
class TestRenderHTMLTable < Test
|
4
|
+
class TestRenderHTMLTable < Minitest::Test
|
5
5
|
|
6
6
|
def setup
|
7
7
|
Ruport::Formatter::Template.create(:simple) do |format|
|
@@ -25,7 +25,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
25
25
|
def test_render_html_basic
|
26
26
|
|
27
27
|
actual = Ruport::Controller::Table.render_html { |r|
|
28
|
-
r.data = Table([], :data => [[1,2,3],[4,5,6]])
|
28
|
+
r.data = Ruport.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"+
|
@@ -33,12 +33,12 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
33
33
|
"\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
34
34
|
"\t</tr>\n\t</table>\n",actual)
|
35
35
|
|
36
|
-
actual = Ruport::Controller::Table.render_html { |r|
|
37
|
-
r.data = Table(%w[a b c], :data => [ [1,2,3],[4,5,6]])
|
36
|
+
actual = Ruport::Controller::Table.render_html { |r|
|
37
|
+
r.data = Ruport.Table(%w[a b c], :data => [ [1,2,3],[4,5,6]])
|
38
38
|
}
|
39
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>"+
|
40
|
+
assert_equal("\t<table>\n\t\t<thead>\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</thead>\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
44
|
"\t</tr>\n\t</table>\n",actual)
|
@@ -59,7 +59,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
59
59
|
|
60
60
|
def test_options_hashes_override_template
|
61
61
|
opts = nil
|
62
|
-
table = Table(%w[a b c])
|
62
|
+
table = Ruport.Table(%w[a b c])
|
63
63
|
table.to_html(
|
64
64
|
:template => :simple,
|
65
65
|
:table_format => {
|
@@ -81,7 +81,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
81
81
|
|
82
82
|
def test_individual_options_override_template
|
83
83
|
opts = nil
|
84
|
-
table = Table(%w[a b c])
|
84
|
+
table = Ruport.Table(%w[a b c])
|
85
85
|
table.to_html(
|
86
86
|
:template => :simple,
|
87
87
|
:show_table_headers => true,
|
@@ -99,7 +99,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
99
99
|
end
|
100
100
|
|
101
101
|
|
102
|
-
class TestRenderHTMLRow < Test
|
102
|
+
class TestRenderHTMLRow < Minitest::Test
|
103
103
|
|
104
104
|
def test_render_html_row
|
105
105
|
actual = Ruport::Controller::Row.render_html { |r| r.data = [1,2,3] }
|
@@ -109,7 +109,7 @@ class TestRenderHTMLRow < Test::Unit::TestCase
|
|
109
109
|
end
|
110
110
|
|
111
111
|
|
112
|
-
class TestRenderHTMLGroup < Test
|
112
|
+
class TestRenderHTMLGroup < Minitest::Test
|
113
113
|
|
114
114
|
def test_render_html_group
|
115
115
|
group = Ruport::Data::Group.new(:name => 'test',
|
@@ -117,8 +117,8 @@ class TestRenderHTMLGroup < Test::Unit::TestCase
|
|
117
117
|
:column_names => %w[a b c])
|
118
118
|
actual = Ruport::Controller::Group.render(:html, :data => group)
|
119
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>"+
|
120
|
+
"\t<table>\n\t\t<thead>\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</thead>\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
124
|
"\t</tr>\n\t</table>\n", actual
|
@@ -138,10 +138,10 @@ class TestRenderHTMLGroup < Test::Unit::TestCase
|
|
138
138
|
end
|
139
139
|
|
140
140
|
|
141
|
-
class TestRenderHTMLGrouping < Test
|
141
|
+
class TestRenderHTMLGrouping < Minitest::Test
|
142
142
|
|
143
143
|
def test_render_html_grouping
|
144
|
-
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
144
|
+
table = Ruport.Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
145
145
|
g = Grouping(table,:by => "a")
|
146
146
|
actual = Ruport::Controller::Grouping.render(:html, :data => g,
|
147
147
|
:show_table_headers => false)
|
@@ -153,27 +153,27 @@ class TestRenderHTMLGrouping < Test::Unit::TestCase
|
|
153
153
|
end
|
154
154
|
|
155
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]
|
156
|
+
table = Ruport.Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
157
157
|
g = Grouping(table,:by => "a")
|
158
158
|
actual = Ruport::Controller::Grouping.render(:html, :data => g)
|
159
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>"+
|
160
|
+
assert_equal "\t<p>1</p>\n\t<table>\n\t\t<thead>\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</thead>\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
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"+
|
164
|
+
"\t<p>2</p>\n\t<table>\n\t\t<thead>\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</thead>\n\t\t<tr>\n\t\t\t<td>7</td>\n"+
|
166
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
|
-
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
170
|
+
table = Ruport.Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
171
171
|
g = Grouping(table,:by => "a")
|
172
172
|
actual = Ruport::Controller::Grouping.render(:html, :data => g,
|
173
173
|
:style => :justified)
|
174
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"+
|
175
|
+
assert_equal "\t<table>\n\t\t<thead>\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</thead>\n\t\t<tr>\n\t\t\t"+
|
177
177
|
"<td class=\"groupName\">1</td>\n\t\t\t<td>"+
|
178
178
|
"2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+
|
179
179
|
"<td> </td>\n\t\t\t<td>1</td>\n\t\t\t<td>3</td>"+
|
@@ -184,7 +184,7 @@ class TestRenderHTMLGrouping < Test::Unit::TestCase
|
|
184
184
|
end
|
185
185
|
|
186
186
|
|
187
|
-
class TestHTMLFormatterHelpers < Test
|
187
|
+
class TestHTMLFormatterHelpers < Minitest::Test
|
188
188
|
begin
|
189
189
|
require "rubygems"
|
190
190
|
rescue LoadError
|
@@ -196,6 +196,6 @@ class TestHTMLFormatterHelpers < Test::Unit::TestCase
|
|
196
196
|
a = Ruport::Formatter::HTML.new
|
197
197
|
assert_equal "<p><strong>foo</strong></p>", a.textile("*foo*")
|
198
198
|
rescue LoadError
|
199
|
-
STDERR.puts "Skipping textile test... needs
|
199
|
+
STDERR.puts "Skipping textile test... needs RedCloth gem"
|
200
200
|
end
|
201
201
|
end
|