ruport-util 0.6.0 → 0.7.0
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.
- data/INSTALL +8 -7
- data/Rakefile +66 -11
- data/bin/csv2ods +53 -0
- data/example/data/blank.ods +0 -0
- data/example/graph_report.rb +6 -2
- data/example/invoice_report.rb +2 -1
- data/example/mailer.rb +7 -7
- data/example/managed_report.rb +5 -5
- data/example/ods.rb +12 -0
- data/lib/ruport/util/generator.rb +2 -11
- data/lib/ruport/util/graph.rb +8 -0
- data/lib/ruport/util/ods.rb +80 -0
- data/lib/ruport/util/report.rb +33 -299
- data/lib/ruport/util/report_manager.rb +2 -3
- data/lib/ruport/util.rb +9 -1
- data/test/helper/layout.rb +55 -0
- data/test/helper/wrap.rb +190 -0
- data/test/helper.rb +27 -0
- data/test/test_format_ods.rb +46 -0
- data/test/test_graph_renderer.rb +21 -31
- data/test/test_invoice.rb +30 -28
- data/test/test_mailer.rb +116 -159
- data/test/test_report.rb +80 -183
- data/test/test_report_manager.rb +32 -29
- metadata +30 -22
- data/example/foo.svg +0 -83
- data/example/form.pdf +0 -160
- data/example/out.pdf +0 -229
- data/test/init.rb +0 -7
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
testcase_requires 'hpricot'
|
4
|
+
|
5
|
+
describe 'OSD Formatter' do
|
6
|
+
before :all do
|
7
|
+
@csv = "first col,second col,third col\n" +
|
8
|
+
"first row,cell 1,cell 2\n" +
|
9
|
+
"second row,cell 3,cell 4\n" +
|
10
|
+
"third row,special >,special <\n" +
|
11
|
+
"fourth row,,after empty\n" +
|
12
|
+
"\n" +
|
13
|
+
"seventh row,nothing,more\n"
|
14
|
+
@table = Table(:string => @csv)
|
15
|
+
zipfile = @table.to_ods(:tempfile => true)
|
16
|
+
zip = Zip::ZipFile.open(zipfile.path)
|
17
|
+
@content = zip.read('content.xml')
|
18
|
+
zip.close
|
19
|
+
@doc = Hpricot(@content)
|
20
|
+
@rows = (@doc/'table:table-row')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have content' do
|
24
|
+
@content.should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should have all rows' do
|
28
|
+
@rows.should have(7).rows
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have the header' do
|
32
|
+
headers = (@rows.first/'text:p').map{|t| t.inner_html}
|
33
|
+
headers.should == @table.column_names
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have the two rows with data' do
|
37
|
+
@rows[1..2].zip(@table.data).each do |h_row, r_row|
|
38
|
+
(h_row/'text:p').map{ |t| t.inner_html }.should == r_row.to_a
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should escape HTML entities' do
|
43
|
+
(@rows[3]/'text:p').map{|e| e.inner_html}.
|
44
|
+
should == %w[third\ row special\ > special\ <]
|
45
|
+
end
|
46
|
+
end
|
data/test/test_graph_renderer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
quiet { testcase_requires 'scruffy' }
|
3
4
|
|
4
5
|
class MockGraphPlugin < Ruport::Formatter
|
5
6
|
renders :mock, :for => Ruport::Renderer::Graph
|
@@ -14,36 +15,27 @@ class MockGraphPlugin < Ruport::Formatter
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
describe 'Graph Renderer' do
|
19
|
+
before :all do
|
20
|
+
@graph = Ruport::Renderer::Graph
|
21
|
+
@data = Ruport::Graph(:data => [[1,2,3],[4,5,6]])
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
def test_basics
|
21
|
-
out = Ruport::Renderer::Graph.render_mock do |r|
|
24
|
+
it 'should render' do
|
25
|
+
out = @graph.render_mock do |r|
|
22
26
|
r.options do |l|
|
23
|
-
|
27
|
+
l.style.should == :line
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
|
-
|
31
|
+
out.should == 'preparebuildfinalize'
|
28
32
|
end
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
class TestSVGPlugin < Test::Unit::TestCase
|
34
|
-
|
35
|
-
def test_output
|
36
|
-
assert_not_nil Ruport::Renderer::Graph.render_svg { |r|
|
37
|
-
r.data = Ruport::Graph(:data => [[1,2,3],[4,5,6]])
|
38
|
-
}
|
34
|
+
it 'should render SVG' do
|
35
|
+
@graph.render_svg{|r| r.data = @data}.should_not be_nil
|
39
36
|
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
class TestXMLSWFPlugin < Test::Unit::TestCase
|
44
|
-
|
45
|
-
def test_output
|
46
|
-
|
38
|
+
it 'should render XMLSWF via block' do
|
47
39
|
expected = <<-EOS
|
48
40
|
<chart>
|
49
41
|
<chart_type>line</chart_type>
|
@@ -66,11 +58,11 @@ class TestXMLSWFPlugin < Test::Unit::TestCase
|
|
66
58
|
</chart_data>
|
67
59
|
</chart>
|
68
60
|
EOS
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
61
|
+
|
62
|
+
@graph.render_xml_swf{|r| r.data = @data}.should == expected
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should render XMLSWF via add_line' do
|
74
66
|
expected = <<-EOS
|
75
67
|
<chart>
|
76
68
|
<chart_type>line</chart_type>
|
@@ -98,8 +90,6 @@ EOS
|
|
98
90
|
graph.add_line [1,2,3], :name => "Alpha"
|
99
91
|
graph.add_line [4,5,6], :name => "Beta"
|
100
92
|
|
101
|
-
|
102
|
-
|
93
|
+
graph.to_xml_swf.should == expected
|
103
94
|
end
|
104
|
-
|
105
95
|
end
|
data/test/test_invoice.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
-
require
|
2
|
-
require "ruport/util"
|
1
|
+
require 'test/helper'
|
3
2
|
|
4
|
-
|
3
|
+
describe 'Invoice' do
|
4
|
+
before :all do
|
5
|
+
@invoice = Ruport::Renderer::Invoice
|
6
|
+
@data = Table(%w[a b c]) << [1,2,3]
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should raise if the required options are not set' do
|
10
|
+
lambda{ @invoice.render_pdf }.
|
11
|
+
should raise_error(Ruport::Renderer::RequiredOptionNotSet)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "shouldn't raise if options are given correct in hash form" do
|
15
|
+
lambda do
|
16
|
+
@invoice.render_pdf :data => @data,
|
17
|
+
:customer_info => 'blah', :company_info => 'also blah',
|
18
|
+
:order_info => 'Incredibly Blah', :comments => 'Super Blah'
|
19
|
+
end.should_not raise_error
|
20
|
+
end
|
5
21
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
#block form
|
19
|
-
assert_nothing_raised {
|
20
|
-
Ruport::Renderer::Invoice.render_pdf do |r|
|
21
|
-
r.data = Table(%w[a b c]) << [1,2,3]
|
22
|
-
r.customer_info = "blah"
|
23
|
-
r.company_info = "also blah"
|
24
|
-
r.order_info = "Incredibly Blah"
|
25
|
-
r.comments = "Super blah"
|
26
|
-
end
|
27
|
-
}
|
22
|
+
it "shouldn't raise if options are given correct in block form" do
|
23
|
+
lambda do
|
24
|
+
@invoice.render_pdf do |r|
|
25
|
+
r.customer_info = 'blah'
|
26
|
+
r.company_info = 'also blah'
|
27
|
+
r.order_info = 'Incredibly Blah'
|
28
|
+
r.comments = 'Super Blah'
|
29
|
+
r.data = @data
|
30
|
+
end
|
31
|
+
end.should_not raise_error
|
28
32
|
end
|
29
|
-
|
30
|
-
|
31
|
-
end
|
33
|
+
end
|
data/test/test_mailer.rb
CHANGED
@@ -1,206 +1,163 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require "ruport"
|
4
|
-
require "ruport/util/mailer"
|
5
|
-
begin
|
6
|
-
require 'mocha'
|
7
|
-
require 'stubba'
|
8
|
-
require 'net/smtp'
|
9
|
-
rescue LoadError
|
10
|
-
$stderr.puts "Warning: Mocha not found -- skipping some Mailer tests"
|
11
|
-
end
|
12
|
-
|
13
|
-
class TestMailer < Test::Unit::TestCase
|
1
|
+
require 'test/helper'
|
2
|
+
require 'net/smtp'
|
14
3
|
|
15
|
-
|
4
|
+
describe 'Mailer' do
|
5
|
+
before :all do
|
16
6
|
@default_opts = {
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
7
|
+
:user => "inky",
|
8
|
+
:host => "mail.example.com",
|
9
|
+
:address => "sue@example.com",
|
20
10
|
:password => "chunky"
|
21
11
|
}
|
22
12
|
|
23
13
|
@other_opts = {
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
14
|
+
:user => "blinky",
|
15
|
+
:host => "moremail.example.com",
|
16
|
+
:address => "clyde@example.com",
|
27
17
|
:password => "bacon"
|
28
18
|
}
|
29
19
|
|
30
|
-
Ruport::Mailer
|
31
|
-
Ruport::Mailer.add_mailer :other, @other_opts
|
20
|
+
@mailer = Ruport::Mailer
|
32
21
|
|
33
|
-
@
|
34
|
-
@
|
35
|
-
end
|
36
|
-
|
37
|
-
def assert_mailer_equal(expected, mailer)
|
38
|
-
assert_equal expected[:host], mailer.instance_variable_get(:@host)
|
39
|
-
assert_equal expected[:address], mailer.instance_variable_get(:@address)
|
40
|
-
assert_equal expected[:user], mailer.instance_variable_get(:@user)
|
41
|
-
assert_equal expected[:password], mailer.instance_variable_get(:@password)
|
42
|
-
end
|
22
|
+
@mailer.add_mailer :default, @default_opts
|
23
|
+
@mailer.add_mailer :other, @other_opts
|
43
24
|
|
44
|
-
|
45
|
-
|
46
|
-
setup_mock_report_mailer
|
47
|
-
@report = Ruport::Report.new
|
48
|
-
assert_equal "250 ok", @report.send_to("clyde@example.com") { |mail|
|
49
|
-
mail.subject = "Test Report"
|
50
|
-
mail.text = "Test"
|
51
|
-
}
|
52
|
-
end
|
25
|
+
@default_mailer = @mailer.new :default
|
26
|
+
@other_mailer = @mailer.new :other
|
53
27
|
|
54
|
-
|
55
|
-
|
56
|
-
|
28
|
+
@mail_fields = { :to => 'clyde@example.com',
|
29
|
+
:from => 'sue@example.com',
|
30
|
+
:subject => 'Hello',
|
31
|
+
:text => 'This is a test' }
|
57
32
|
end
|
58
33
|
|
34
|
+
def values_for(mailer, *keys)
|
35
|
+
keys = keys.flatten.map{|k| k.to_s}
|
36
|
+
keys.map{|k| mailer.instance_variable_get("@#{k}") }
|
37
|
+
end
|
59
38
|
|
60
|
-
|
61
|
-
|
62
|
-
|
39
|
+
def check(mailer, expected)
|
40
|
+
keys = [:host, :address, :user, :password]
|
41
|
+
values = values_for(mailer, *keys)
|
42
|
+
values.should == expected.values_at(*keys)
|
63
43
|
end
|
64
|
-
|
65
|
-
def
|
66
|
-
|
44
|
+
|
45
|
+
def mock_report_mailer
|
46
|
+
@smtp = mock('SMTP')
|
47
|
+
@smtp.stub!(:send_message).and_return('250 ok')
|
48
|
+
Net::SMTP.should_receive(:start).and_return("250 ok")
|
67
49
|
end
|
68
50
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
51
|
+
def mock_mailer(count, mailer = @default_mailer)
|
52
|
+
values = values_for(mailer, :host, :port, :host, :user, :password, :auth)
|
53
|
+
|
54
|
+
@smtp = mock('SMTP')
|
55
|
+
|
56
|
+
Net::SMTP.should_receive(:start).
|
57
|
+
with(*values).
|
58
|
+
exactly(count).times.
|
59
|
+
and_yield(@smtp)
|
60
|
+
@smtp.should_receive(:send_message).
|
61
|
+
with( an_instance_of(String),
|
62
|
+
an_instance_of(String),
|
63
|
+
an_instance_of(String) ).any_number_of_times.
|
64
|
+
and_return('250 ok')
|
65
|
+
@smtp.should_receive(:send_message).
|
66
|
+
with(an_instance_of(String),an_instance_of(String), nil).any_number_of_times.
|
67
|
+
and_raise(Net::SMTPSyntaxError)
|
72
68
|
end
|
73
|
-
|
74
|
-
def test_select_mailer
|
75
|
-
mailer = Ruport::Mailer.new :default
|
76
|
-
assert_mailer_equal @default_opts, mailer
|
77
69
|
|
78
|
-
|
79
|
-
|
70
|
+
it 'should have default mailer' do
|
71
|
+
@mailer.mailers[:default].should == @mailer.default_mailer
|
80
72
|
end
|
81
73
|
|
82
|
-
|
74
|
+
it 'should have equal options inside and outside of default mailer' do
|
75
|
+
check @default_mailer, @default_opts
|
76
|
+
end
|
83
77
|
|
84
|
-
|
85
|
-
|
86
|
-
}
|
87
|
-
assert_nothing_raised { Ruport::Mailer.add_mailer :bar, :host => "localhost" }
|
78
|
+
it 'should have equal options inside and outside of other mailer' do
|
79
|
+
check @other_mailer, @other_opts
|
88
80
|
end
|
89
81
|
|
82
|
+
it 'should raise if no default mailer is set' do
|
83
|
+
default = @mailer.mailers.delete :default
|
90
84
|
|
85
|
+
lambda{ @mailer.new }.
|
86
|
+
should raise_error(RuntimeError, 'you need to specify a mailer to use')
|
91
87
|
|
92
|
-
|
93
|
-
@default_mailer.instance_eval "@mail.to = ['foo@bar.com']"
|
94
|
-
assert_equal ['foo@bar.com'], @default_mailer.to
|
88
|
+
@mailer.mailers[:default] = default
|
95
89
|
end
|
96
90
|
|
97
|
-
|
98
|
-
@
|
99
|
-
|
100
|
-
end
|
91
|
+
it 'should raise if configuration is invalid' do
|
92
|
+
lambda{ @mailer.add_mailer :bar, :user => :foo, :address => 'foo@bar.com' }.
|
93
|
+
should raise_error(Ruport::Mailer::InvalidMailerConfigurationError)
|
101
94
|
|
102
|
-
|
103
|
-
|
104
|
-
assert_equal ['foo@bar.com'], @default_mailer.from
|
95
|
+
lambda{ @mailer.add_mailer :bar, :host => 'localhost' }.
|
96
|
+
should_not raise_error
|
105
97
|
end
|
106
98
|
|
107
|
-
|
108
|
-
|
109
|
-
|
99
|
+
it 'should send emails with default' do
|
100
|
+
mock_mailer 1
|
101
|
+
@default_mailer.deliver(@mail_fields).should == '250 ok'
|
110
102
|
end
|
111
103
|
|
112
|
-
|
113
|
-
|
114
|
-
|
104
|
+
it 'should send emails with other default' do
|
105
|
+
mock_mailer 1, @other_mailer
|
106
|
+
@other_mailer.deliver(@mail_fields).should == '250 ok'
|
115
107
|
end
|
116
108
|
|
117
|
-
|
118
|
-
|
119
|
-
|
109
|
+
it 'should send mail without to field' do
|
110
|
+
mock_mailer 1
|
111
|
+
hash = @mail_fields.dup
|
112
|
+
hash.delete :to
|
113
|
+
lambda{ @default_mailer.deliver(hash) }.
|
114
|
+
should raise_error(Net::SMTPSyntaxError)
|
120
115
|
end
|
121
116
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
:subject => "Hello",
|
129
|
-
:text => "This is a test.")
|
117
|
+
it 'should send mail with HTML' do
|
118
|
+
mock_mailer 1
|
119
|
+
hash = @mail_fields.dup
|
120
|
+
hash.delete(:text)
|
121
|
+
hash[:html] = '<p>This is a test.</p>'
|
122
|
+
@default_mailer.deliver(hash).should == '250 ok'
|
130
123
|
end
|
131
124
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
@other_mailer.deliver(:to => "sue@example.com",
|
137
|
-
:from => "clyde@example.com",
|
138
|
-
:subject => "Hello",
|
139
|
-
:text => "This is a test.")
|
125
|
+
it 'should send mail with attachment' do
|
126
|
+
mock_mailer 1
|
127
|
+
@default_mailer.attach 'test/samples/data.csv'
|
128
|
+
@default_mailer.deliver(@mail_fields).should == '250 ok'
|
140
129
|
end
|
141
130
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
131
|
+
it 'should have information about the mail' do
|
132
|
+
dfm = @default_mailer
|
133
|
+
|
134
|
+
{ :to => ['foo@bar.com'],
|
135
|
+
:from => ['foo@bar.com'],
|
136
|
+
:subject => ['RuportDay!']
|
137
|
+
}.each do |meth, value|
|
138
|
+
assign_meth = "#{meth}="
|
139
|
+
|
140
|
+
dfm.instance_eval{ @mail.send(assign_meth, value) }
|
141
|
+
dfm.send(meth).should == value
|
142
|
+
|
143
|
+
dfm.send(assign_meth, value)
|
144
|
+
dfm.send(meth).should == value
|
145
|
+
end
|
150
146
|
end
|
151
147
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
:from => "sue@example.com",
|
158
|
-
:subject => "Hello",
|
159
|
-
:html => "<p>This is a test.</p>")
|
148
|
+
it 'should be able to select a mailer' do
|
149
|
+
mailer = @mailer.new(:default)
|
150
|
+
check mailer, @default_opts
|
151
|
+
mailer.send(:select_mailer, :other)
|
152
|
+
check mailer, @other_opts
|
160
153
|
end
|
161
154
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
@
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
:text => "This is a test.")
|
171
|
-
end
|
172
|
-
|
173
|
-
private
|
174
|
-
|
175
|
-
def setup_mock_mailer(count, mailer=@default_mailer)
|
176
|
-
host = mailer.instance_variable_get(:@host)
|
177
|
-
port = mailer.instance_variable_get(:@port)
|
178
|
-
user = mailer.instance_variable_get(:@user)
|
179
|
-
password = mailer.instance_variable_get(:@password)
|
180
|
-
auth = mailer.instance_variable_get(:@auth)
|
181
|
-
|
182
|
-
@smtp = mock('smtp')
|
183
|
-
|
184
|
-
Net::SMTP.expects(:start).
|
185
|
-
with(host,port,host,user,password,auth).
|
186
|
-
yields(@smtp).
|
187
|
-
returns("250 ok").times(count)
|
188
|
-
@smtp.stubs(:send_message).
|
189
|
-
with {|*params| !params[2].nil? }.
|
190
|
-
returns("250 ok")
|
191
|
-
@smtp.stubs(:send_message).
|
192
|
-
with {|*params| params[2].nil? }.
|
193
|
-
raises(Net::SMTPSyntaxError)
|
194
|
-
end
|
195
|
-
|
196
|
-
def setup_mock_report_mailer
|
197
|
-
@smtp = mock('smtp')
|
198
|
-
|
199
|
-
Net::SMTP.expects(:start).
|
200
|
-
yields(@smtp).
|
201
|
-
returns("250 ok").at_least_once
|
202
|
-
@smtp.stubs(:send_message).
|
203
|
-
returns("250 ok")
|
204
|
-
end
|
155
|
+
it 'should send reports with default mailer' do
|
156
|
+
report = Ruport::Report.new
|
157
|
+
mock_report_mailer
|
158
|
+
report.send_to(@other_opts[:address]){|mail|
|
159
|
+
mail.subject = 'Test Report'
|
160
|
+
mail.text = 'Test'
|
161
|
+
}.should == '250 ok'
|
162
|
+
end
|
205
163
|
end
|
206
|
-
|