ruport 0.4.13 → 0.4.15
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +23 -1
- data/Rakefile +1 -1
- data/TODO +0 -4
- data/lib/ruport/data/collection.rb +20 -0
- data/lib/ruport/data/record.rb +81 -0
- data/lib/ruport/data/table.rb +57 -0
- data/lib/ruport/data/taggable.rb +27 -0
- data/lib/ruport/data.rb +1 -0
- data/lib/ruport/data_row.rb +8 -2
- data/lib/ruport/data_set.rb +10 -1
- data/lib/ruport/format/engine.rb +38 -12
- data/lib/ruport/format/plugin.rb +32 -24
- data/lib/ruport/meta_tools.rb +19 -0
- data/lib/ruport/rails/reportable.rb +2 -2
- data/lib/ruport/report.rb +2 -2
- data/lib/ruport.rb +2 -2
- data/test/tc_data_row.rb +8 -0
- data/test/tc_data_set.rb +17 -0
- data/test/tc_format_engine.rb +94 -4
- data/test/tc_record.rb +140 -0
- data/test/tc_table.rb +39 -0
- data/test/tc_taggable.rb +53 -0
- data/test/ts_all.rb +3 -0
- data/test/unit.log +2080 -0
- metadata +12 -2
data/test/tc_format_engine.rb
CHANGED
@@ -10,11 +10,22 @@ class MockPlugin < Ruport::Format::Plugin
|
|
10
10
|
|
11
11
|
renderer(:document) { data }
|
12
12
|
|
13
|
-
register_on :table_engine
|
14
|
-
register_on :document_engine
|
15
|
-
|
16
13
|
rendering_options :red_cloth_enabled => true,
|
17
14
|
:erb_enabled => true
|
15
|
+
|
16
|
+
action(:reverse_data) { data.reverse }
|
17
|
+
action(:mock_action) { "mock" }
|
18
|
+
|
19
|
+
helper(:test) { |eng| eng }
|
20
|
+
|
21
|
+
attribute :apple
|
22
|
+
|
23
|
+
helper(:complex_test) { |eng|
|
24
|
+
eng.rewrite_column(0) { "a" } if apple
|
25
|
+
}
|
26
|
+
|
27
|
+
register_on :table_engine
|
28
|
+
register_on :document_engine
|
18
29
|
|
19
30
|
end
|
20
31
|
|
@@ -25,13 +36,36 @@ class TestTabularFormatEngine < Test::Unit::TestCase
|
|
25
36
|
def setup
|
26
37
|
@engine = Format::Engine::Table.dup
|
27
38
|
end
|
28
|
-
|
39
|
+
|
40
|
+
def test_plugin_attributes
|
41
|
+
assert_equal nil, @engine.active_plugin.apple
|
42
|
+
@engine.active_plugin.apple = :banana
|
43
|
+
assert_equal :banana, @engine.active_plugin.apple
|
44
|
+
end
|
29
45
|
def test_basic_render
|
30
46
|
@engine.plugin = :mock
|
31
47
|
@engine.data = [[1,2,3],[4,5,6],[7,8,9]]
|
32
48
|
assert_equal( "#{@engine.data}", @engine.render )
|
33
49
|
end
|
34
50
|
|
51
|
+
def test_plugin_actions
|
52
|
+
@engine.plugin = :mock
|
53
|
+
@engine.data = [1,2,3,4]
|
54
|
+
assert_equal( [4,3,2,1], @engine.active_plugin.reverse_data )
|
55
|
+
assert_equal( "mock", @engine.active_plugin.mock_action )
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_helper
|
59
|
+
@engine.plugin = :mock
|
60
|
+
assert_equal @engine, @engine.test
|
61
|
+
@engine.data = [[1,2,3],[4,5,6]]
|
62
|
+
@engine.complex_test
|
63
|
+
assert_equal([[1,2,3],[4,5,6]],@engine.data)
|
64
|
+
@engine.active_plugin.apple = true
|
65
|
+
@engine.complex_test
|
66
|
+
assert_equal([['a',2,3],['a',5,6]],@engine.data)
|
67
|
+
end
|
68
|
+
|
35
69
|
def test_render_without_field_names
|
36
70
|
@engine.plugin = :mock
|
37
71
|
@engine.show_field_names = false
|
@@ -68,7 +102,63 @@ class TestTabularFormatEngine < Test::Unit::TestCase
|
|
68
102
|
@engine.data = [[1,2,3],[4,5,6]].to_ds(%w[a b c])
|
69
103
|
assert_equal(3,@engine.num_cols)
|
70
104
|
end
|
105
|
+
|
106
|
+
def test_plugin_access
|
107
|
+
@engine.plugin = :mock
|
108
|
+
@engine.data = [[1,5],[3,8]]
|
109
|
+
|
110
|
+
#normal access
|
111
|
+
assert_equal :mock, @engine.active_plugin.plugin_name
|
112
|
+
assert_equal [[1,5],[3,8]], @engine.active_plugin.data
|
113
|
+
|
114
|
+
#block access
|
115
|
+
@engine.active_plugin do |p|
|
116
|
+
assert_equal :mock, p.plugin_name
|
117
|
+
assert_equal [[1,5],[3,8]], p.data
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_prune
|
122
|
+
@engine.plugin = :mock
|
123
|
+
@engine.data = [[1,2,3],[1,4,3],[2,4,1]]
|
124
|
+
@engine.prune
|
125
|
+
assert_equal([[1,2,3],[nil,4,3],[2,4,1]],@engine.data)
|
126
|
+
@engine.data = [[1,2,3],[2,4,1],[2,7,9],[1,2,3],[1,7,9]]
|
127
|
+
@engine.prune
|
128
|
+
assert_equal([[1,2,3],[2,4,1],[nil,7,9],[1,2,3],[nil,7,9]],
|
129
|
+
@engine.data)
|
130
|
+
@engine.data = [[1,2,3],[1,2,4],[1,3,7],[2,1,9],[2,2,3],[2,2,9]]
|
131
|
+
@engine.prune
|
132
|
+
assert_equal( [[1,2,3],[nil,nil,4],[nil,3,7],
|
133
|
+
[2,1,9],[nil,2,3],[nil,nil,9]], @engine.data)
|
134
|
+
|
135
|
+
@engine.data = [[1,2,3],[1,2,4],[1,3,7],[2,1,9],[2,2,3],[2,2,9]]
|
136
|
+
@engine.prune(1)
|
137
|
+
assert_equal( [[1,2,3],[nil,2,4],[nil,3,7],
|
138
|
+
[2,1,9],[nil,2,3],[nil,2,9]], @engine.data)
|
139
|
+
|
140
|
+
data = DataSet.new %w[name date service amount]
|
141
|
+
data << [ "Greg Gibson", "1/1/2000", "Prophy", "100.00" ] <<
|
142
|
+
[ "Greg Gibson", "1/1/2000", "Filling", "100.00" ] <<
|
143
|
+
[ "Greg Gibson", "1/12/2000", "Prophy", "100.00" ] <<
|
144
|
+
[ "Greg Gibson", "1/12/2000", "Filling", "100.00" ] <<
|
145
|
+
[ "Greg Brown", "1/12/2000", "Prophy", "100.00" ]
|
146
|
+
|
147
|
+
@engine.data = data
|
148
|
+
@engine.prune(1)
|
149
|
+
data2 = data.dup
|
150
|
+
data2[1][0] = data2[2][0] = data2[3][0] = nil
|
151
|
+
assert_equal(data2, @engine.data)
|
71
152
|
|
153
|
+
@engine.data=data
|
154
|
+
|
155
|
+
data3 = data2.dup
|
156
|
+
data3[1][1] = data3[3][1] = nil
|
157
|
+
@engine.prune(2)
|
158
|
+
|
159
|
+
assert_equal(data3, @engine.data)
|
160
|
+
end
|
161
|
+
|
72
162
|
end
|
73
163
|
|
74
164
|
class TestDocumentFormatEngine < Test::Unit::TestCase
|
data/test/tc_record.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "ruport"
|
3
|
+
|
4
|
+
|
5
|
+
class RecordTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Ruport::Data
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@attributes = %w[a b c d]
|
11
|
+
@record = Ruport::Data::Record.new [1,2,3,4], :attributes => @attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_init
|
15
|
+
record = Ruport::Data::Record.new [1,2,3,4]
|
16
|
+
assert_equal 1, record[0]
|
17
|
+
assert_equal 2, record[1]
|
18
|
+
assert_equal 3, record[2]
|
19
|
+
assert_equal 4, record[3]
|
20
|
+
|
21
|
+
assert_equal 1, @record["a"]
|
22
|
+
assert_equal 4, @record["d"]
|
23
|
+
assert_equal 2, @record.b
|
24
|
+
assert_equal 3, @record.c
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_brackets
|
29
|
+
assert_equal 1, @record[0]
|
30
|
+
assert_equal 2, @record[1]
|
31
|
+
assert_equal 3, @record[2]
|
32
|
+
assert_equal 4, @record[3]
|
33
|
+
|
34
|
+
assert_equal 1, @record["a"]
|
35
|
+
assert_equal 2, @record["b"]
|
36
|
+
assert_equal 3, @record["c"]
|
37
|
+
assert_equal 4, @record["d"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_bracket_equals
|
41
|
+
@record[1] = "godzilla"
|
42
|
+
@record["d"] = "mothra"
|
43
|
+
|
44
|
+
assert_equal @record[1], "godzilla"
|
45
|
+
assert_equal @record["b"], "godzilla"
|
46
|
+
|
47
|
+
assert_equal @record[3], "mothra"
|
48
|
+
assert_equal @record["d"], "mothra"
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_accessors
|
52
|
+
assert_equal @record.a, @record["a"]
|
53
|
+
assert_equal @record.b, @record["b"]
|
54
|
+
assert_equal @record.c, @record["c"]
|
55
|
+
assert_equal @record.d, @record["d"]
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_attribute_setting
|
59
|
+
@record.a = 10
|
60
|
+
@record.b = 20
|
61
|
+
assert_equal 10, @record.a
|
62
|
+
assert_equal 20, @record.b
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_to_a
|
66
|
+
assert_equal [1,2,3,4], a = @record.to_a; a[0] = "q"
|
67
|
+
assert_equal [1,2,3,4], @record.to_a
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_to_h
|
71
|
+
assert_nothing_raised { @record.to_h }
|
72
|
+
assert_equal({ "a" => 1, "b" => 2, "c" => 3, "d" => 4 }, @record.to_h)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_equality
|
76
|
+
|
77
|
+
dc = %w[a b c d]
|
78
|
+
dc2 = %w[a b c d]
|
79
|
+
dc3 = %w[a b c]
|
80
|
+
|
81
|
+
rec1 = Record.new [1,2,3,4]
|
82
|
+
rec2 = Record.new [1,2,3,4]
|
83
|
+
rec3 = Record.new [1,2]
|
84
|
+
rec4 = Record.new [1,2,3,4], :attributes => dc
|
85
|
+
rec5 = Record.new [1,2,3,4], :attributes => dc2
|
86
|
+
rec6 = Record.new [1,2,3,4], :attributes => dc3
|
87
|
+
rec7 = Record.new [1,2], :attributes => dc
|
88
|
+
|
89
|
+
[:==, :eql?].each do |op|
|
90
|
+
assert rec1.send(op, rec2)
|
91
|
+
assert rec4.send(op, rec5)
|
92
|
+
assert ! rec1.send(op,rec3)
|
93
|
+
assert ! rec1.send(op,rec4)
|
94
|
+
assert ! rec6.send(op,rec7)
|
95
|
+
assert ! rec3.send(op,rec4)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_attributes
|
101
|
+
assert_equal %w[a b c d], @record.attributes
|
102
|
+
@record.attributes = %w[apple banana courier django]
|
103
|
+
assert_equal %w[apple banana courier django], @record.attributes
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_reordering
|
107
|
+
r = @record.reorder "a","d","b","c"
|
108
|
+
assert_equal [1,4,2,3], r.data
|
109
|
+
assert_equal %w[a d b c], r.attributes
|
110
|
+
|
111
|
+
assert_equal [1,2,3,4], @record.data
|
112
|
+
assert_equal %w[a b c d], @record.attributes
|
113
|
+
|
114
|
+
@record.reorder! "a","d","b","c"
|
115
|
+
assert_equal [1,4,2,3], @record.data
|
116
|
+
assert_equal %w[a d b c], @record.attributes
|
117
|
+
|
118
|
+
@record.reorder! 3,1,2
|
119
|
+
assert_equal [3,4,2], @record.data
|
120
|
+
assert_equal %w[c d b], @record.attributes
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_dup
|
124
|
+
rec1 = Record.new [1,2,3,4], :attributes => %w[a b c d]
|
125
|
+
rec2 = rec1.dup
|
126
|
+
|
127
|
+
rec2.a = 5
|
128
|
+
rec2["b"] = 7
|
129
|
+
rec2[2] = 9
|
130
|
+
|
131
|
+
rec2.tag(:apple)
|
132
|
+
|
133
|
+
assert_equal [1,2,3,4], rec1.data
|
134
|
+
assert_equal [5,7,9,4], rec2.data
|
135
|
+
|
136
|
+
assert_equal [], rec1.tags
|
137
|
+
assert_equal [:apple], rec2.tags
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
data/test/tc_table.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "ruport"
|
3
|
+
|
4
|
+
class TestTable < Test::Unit::TestCase
|
5
|
+
def test_constructors
|
6
|
+
table = Ruport::Data::Table.new
|
7
|
+
table2 = Ruport::Data::Table.new :column_names => %w[a b c]
|
8
|
+
table3 = Ruport::Data::Table.new :data => [[1,2,3]]
|
9
|
+
table4 = Ruport::Data::Table.new :column_names => %w[col1 col2 col3],
|
10
|
+
:data => [[1,2,3]]
|
11
|
+
tables = [table,table2,table3,table4]
|
12
|
+
tables.zip([nil,%w[a b c], nil, %w[col1 col2 col3]]).each do |t,n|
|
13
|
+
assert_equal n, t.column_names
|
14
|
+
end
|
15
|
+
|
16
|
+
a = Ruport::Data::Record.new [1,2,3]
|
17
|
+
b = a.dup
|
18
|
+
b.attributes = %w[col1 col2 col3]
|
19
|
+
tables.zip([[],[],[a],[b]]).each { |t,n| assert_equal n, t.data }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_csv_load
|
23
|
+
table = Ruport::Data::Table.load("test/samples/data.csv")
|
24
|
+
assert_equal %w[col1 col2 col3], table.column_names
|
25
|
+
rows = [%w[a b c],["d",nil,"e"]]
|
26
|
+
table.each { |r| assert_equal rows.shift, r.data
|
27
|
+
assert_equal %w[col1 col2 col3], r.attributes }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_reorder
|
31
|
+
table = Ruport::Data::Table.load("test/samples/data.csv")
|
32
|
+
table.reorder! *%w[col1 col3]
|
33
|
+
assert_equal %w[col1 col3], table.column_names
|
34
|
+
rows = [%w[a c], %w[d e]]
|
35
|
+
table.each { |r| assert_equal rows.shift, r.data
|
36
|
+
assert_equal %w[col1 col3], r.attributes }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/tc_taggable.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "ruport"
|
5
|
+
|
6
|
+
class TestTaggable < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Ruport::Data
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@obj = Object.new.extend(Taggable)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_tags_are_nil_initially
|
15
|
+
assert_equal nil, @obj.instance_variable_get(:@ruport_tags)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_tags
|
19
|
+
@obj.instance_variable_set(:@ruport_tags, [:blue, :red])
|
20
|
+
assert_equal [:blue, :red], @obj.tags
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_set_tags
|
24
|
+
@obj.tags = [:orange, :yellow]
|
25
|
+
assert_equal [:orange, :yellow], @obj.instance_variable_get(:@ruport_tags)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_tag
|
29
|
+
@obj.tag(:purple)
|
30
|
+
assert_equal [:purple], @obj.instance_variable_get(:@ruport_tags)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_has_tag
|
34
|
+
@obj.tag(:maroon)
|
35
|
+
assert @obj.has_tag?(:maroon)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_delete_tag
|
39
|
+
@obj.tag(:scarlet)
|
40
|
+
assert @obj.has_tag?(:scarlet)
|
41
|
+
@obj.delete_tag(:scarlet)
|
42
|
+
assert !@obj.has_tag?(:scarlet)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_avoid_duplication
|
46
|
+
@obj.tag(:smelly)
|
47
|
+
assert_equal 1, @obj.tags.select { |t| t.eql? :smelly }.length
|
48
|
+
@obj.tag(:smelly)
|
49
|
+
assert_equal 1, @obj.tags.select { |t| t.eql? :smelly }.length
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|