ruport 0.8.14 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/README +42 -107
  2. data/Rakefile +29 -32
  3. data/examples/centered_pdf_text_box.rb +13 -19
  4. data/examples/example.csv +3 -0
  5. data/examples/line_plotter.rb +15 -15
  6. data/examples/pdf_complex_report.rb +10 -23
  7. data/examples/pdf_table_with_title.rb +12 -12
  8. data/examples/rope_examples/itunes/Rakefile +22 -1
  9. data/examples/rope_examples/itunes/config/environment.rb +4 -0
  10. data/examples/rope_examples/itunes/lib/init.rb +32 -2
  11. data/examples/rope_examples/itunes/util/build +50 -16
  12. data/examples/rope_examples/sales_report/README +1 -1
  13. data/examples/rope_examples/sales_report/Rakefile +22 -1
  14. data/examples/rope_examples/sales_report/config/environment.rb +4 -0
  15. data/examples/rope_examples/sales_report/lib/init.rb +32 -2
  16. data/examples/rope_examples/sales_report/lib/reports/sales.rb +10 -16
  17. data/examples/rope_examples/sales_report/util/build +50 -16
  18. data/examples/row_renderer.rb +39 -0
  19. data/examples/ruport_list/png_embed.rb +61 -0
  20. data/examples/ruport_list/roadmap.png +0 -0
  21. data/examples/sample.rb +16 -0
  22. data/examples/simple_pdf_lines.rb +24 -0
  23. data/lib/ruport.rb +143 -57
  24. data/lib/ruport/acts_as_reportable.rb +246 -0
  25. data/lib/ruport/data.rb +1 -2
  26. data/lib/ruport/data/grouping.rb +311 -0
  27. data/lib/ruport/data/record.rb +113 -84
  28. data/lib/ruport/data/table.rb +275 -174
  29. data/lib/ruport/formatter.rb +149 -0
  30. data/lib/ruport/formatter/csv.rb +87 -0
  31. data/lib/ruport/formatter/html.rb +89 -0
  32. data/lib/ruport/formatter/pdf.rb +357 -0
  33. data/lib/ruport/formatter/text.rb +151 -0
  34. data/lib/ruport/generator.rb +127 -30
  35. data/lib/ruport/query.rb +46 -99
  36. data/lib/ruport/renderer.rb +238 -194
  37. data/lib/ruport/renderer/grouping.rb +67 -0
  38. data/lib/ruport/renderer/table.rb +25 -98
  39. data/lib/ruport/report.rb +45 -96
  40. data/test/acts_as_reportable_test.rb +229 -0
  41. data/test/csv_formatter_test.rb +97 -0
  42. data/test/{_test_database.rb → database_test_.rb} +0 -0
  43. data/test/grouping_test.rb +305 -0
  44. data/test/html_formatter_test.rb +104 -0
  45. data/test/pdf_formatter_test.rb +25 -0
  46. data/test/{test_query.rb → query_test.rb} +32 -121
  47. data/test/{test_record.rb → record_test.rb} +40 -23
  48. data/test/renderer_test.rb +344 -0
  49. data/test/{test_report.rb → report_test.rb} +74 -44
  50. data/test/samples/ticket_count.csv +124 -0
  51. data/test/{test_sql_split.rb → sql_split_test.rb} +0 -0
  52. data/test/{test_table.rb → table_test.rb} +255 -44
  53. data/test/text_formatter_test.rb +144 -0
  54. data/util/bench/data/record/bench_as_vs_to.rb +17 -0
  55. data/util/bench/data/record/bench_constructor.rb +46 -0
  56. data/util/bench/data/record/bench_indexing.rb +65 -0
  57. data/util/bench/data/record/bench_reorder.rb +35 -0
  58. data/util/bench/data/record/bench_to_a.rb +19 -0
  59. data/util/bench/data/table/bench_column_manip.rb +103 -0
  60. data/util/bench/data/table/bench_dup.rb +24 -0
  61. data/util/bench/data/table/bench_init.rb +67 -0
  62. data/util/bench/data/table/bench_manip.rb +125 -0
  63. data/util/bench/formatter/bench_csv.rb +14 -0
  64. data/util/bench/formatter/bench_html.rb +14 -0
  65. data/util/bench/formatter/bench_pdf.rb +14 -0
  66. data/util/bench/formatter/bench_text.rb +14 -0
  67. data/util/bench/samples/tattle.csv +1237 -0
  68. metadata +121 -143
  69. data/TODO +0 -21
  70. data/examples/invoice.rb +0 -142
  71. data/examples/invoice_report.rb +0 -29
  72. data/examples/line_graph.rb +0 -38
  73. data/examples/rope_examples/itunes/config/ruport_config.rb +0 -8
  74. data/examples/rope_examples/sales_report/config/ruport_config.rb +0 -8
  75. data/lib/ruport/attempt.rb +0 -63
  76. data/lib/ruport/config.rb +0 -204
  77. data/lib/ruport/data/groupable.rb +0 -93
  78. data/lib/ruport/data/taggable.rb +0 -80
  79. data/lib/ruport/format.rb +0 -1
  80. data/lib/ruport/format/csv.rb +0 -29
  81. data/lib/ruport/format/html.rb +0 -42
  82. data/lib/ruport/format/latex.rb +0 -47
  83. data/lib/ruport/format/pdf.rb +0 -233
  84. data/lib/ruport/format/plugin.rb +0 -31
  85. data/lib/ruport/format/svg.rb +0 -60
  86. data/lib/ruport/format/text.rb +0 -103
  87. data/lib/ruport/format/xml.rb +0 -32
  88. data/lib/ruport/layout.rb +0 -1
  89. data/lib/ruport/layout/component.rb +0 -7
  90. data/lib/ruport/mailer.rb +0 -99
  91. data/lib/ruport/renderer/graph.rb +0 -46
  92. data/lib/ruport/report/graph.rb +0 -14
  93. data/lib/ruport/system_extensions.rb +0 -71
  94. data/test/test_config.rb +0 -88
  95. data/test/test_format_text.rb +0 -63
  96. data/test/test_graph_renderer.rb +0 -97
  97. data/test/test_groupable.rb +0 -56
  98. data/test/test_mailer.rb +0 -170
  99. data/test/test_renderer.rb +0 -151
  100. data/test/test_ruport.rb +0 -58
  101. data/test/test_table_renderer.rb +0 -141
  102. data/test/test_taggable.rb +0 -52
data/test/test_config.rb DELETED
@@ -1,88 +0,0 @@
1
- require "test/unit"
2
- require "ruport"
3
-
4
- class TestConfiguration < Test::Unit::TestCase
5
-
6
- def setup
7
- Ruport::Config.log_file = "test/unit.log"
8
- end
9
-
10
- def test_dsn_defaults
11
- assert_equal(nil, Ruport::Config.default_source)
12
- end
13
-
14
- def test_mail_defaults
15
- assert_equal(nil, Ruport::Config.default_mailer)
16
- end
17
-
18
- def test_missing_dsn
19
- assert_raise(ArgumentError) {
20
- Ruport::Config.source :foo, :user => "root", :password => "fff"
21
- }
22
- assert_nothing_raised { Ruport::Config.source :bar, :dsn => "..." }
23
- end
24
-
25
- def test_mailer_errors
26
- assert_raise(ArgumentError) {
27
- Ruport::Config.mailer :bar, :user => :foo, :address => "foo@bar.com"
28
- }
29
- assert_nothing_raised { Ruport::Config.mailer :bar, :host => "localhost" }
30
- end
31
-
32
- def test_new_defaults
33
- Ruport::Config.source :default, :dsn => "dbi:mysql:test",
34
- :user => "root",
35
- :password => ""
36
- assert_equal("dbi:mysql:test", Ruport::Config.default_source.dsn)
37
- assert_equal("root", Ruport::Config.default_source.user)
38
- assert_equal("", Ruport::Config.default_source.password)
39
- end
40
-
41
- def test_multiple_sources
42
- Ruport::Config.source :foo, :dsn => "dbi:mysql:test"
43
- Ruport::Config.source :bar, :dsn => "dbi:mysql:test2"
44
- assert_equal("dbi:mysql:test", Ruport::Config.sources[:foo].dsn)
45
- assert_equal("dbi:mysql:test2", Ruport::Config.sources[:bar].dsn)
46
- end
47
-
48
- def test_simple_interface
49
- Ruport.configure do |c|
50
- c.source :foo, :dsn => "dbi:odbc:test"
51
- c.source :bar, :dsn => "dbi:odbc:test2"
52
- end
53
- assert_equal("dbi:odbc:test",Ruport::Config.sources[:foo].dsn)
54
- assert_equal("dbi:odbc:test2",Ruport::Config.sources[:bar].dsn)
55
- end
56
-
57
-
58
- def test_logger
59
- # We have a logger running now, dont we?
60
- assert(Ruport::Config.logger.kind_of?(Logger))
61
-
62
- # And then we change are mind again. Back logging?
63
- Ruport::Config.log_file = "test/unit.log"
64
- assert(Ruport::Config.logger.kind_of?(Logger))
65
-
66
- end
67
-
68
- def test_debug
69
- assert_equal(false, Ruport::Config.debug_mode?)
70
- Ruport::Config.debug_mode = true
71
- assert_equal(true, Ruport::Config.debug_mode?)
72
- Ruport::Config.debug_mode = false
73
- assert_equal(false, Ruport::Config.debug_mode?)
74
- end
75
-
76
- def test_adding_custom_accessors
77
- Ruport::Config.my_new_setting = 'blinky'
78
- assert_equal('blinky', Ruport::Config.my_new_setting)
79
- Ruport::Config.my_new_setting = 'clyde'
80
- assert_equal('clyde', Ruport::Config.my_new_setting)
81
-
82
- Ruport::Config.my_other_new_setting 'inky'
83
- assert_equal('inky', Ruport::Config.my_other_new_setting)
84
- Ruport::Config.my_other_new_setting 'sue'
85
- assert_equal('sue', Ruport::Config.my_other_new_setting)
86
- end
87
-
88
- end
@@ -1,63 +0,0 @@
1
- require "test/unit"
2
- require "ruport"
3
- class TestFormatText < Test::Unit::TestCase
4
-
5
- def test_basic
6
-
7
- tf = "+-------+\n"
8
-
9
- a = [[1,2],[3,4]].to_table.to_text
10
- assert_equal("#{tf}| 1 | 2 |\n| 3 | 4 |\n#{tf}",a)
11
-
12
- a = [[1,2],[3,4]].to_table(%w[a b]).to_text
13
- assert_equal("#{tf}| a | b |\n#{tf}| 1 | 2 |\n| 3 | 4 |\n#{tf}", a)
14
-
15
- end
16
-
17
-
18
- def test_centering
19
- tf = "+---------+\n"
20
-
21
- a = [[1,2],[300,4]].to_table
22
- assert_equal( "#{tf}| 1 | 2 |\n| 300 | 4 |\n#{tf}",
23
- a.as(:text) { |e| e.layout.alignment = :center })
24
-
25
- tf = "+------------+\n"
26
- a.column_names = %w[a bark]
27
- assert_equal("#{tf}| a | bark |\n#{tf}| 1 | 2 |\n"+
28
- "| 300 | 4 |\n#{tf}",
29
- a.as(:text) { |e| e.layout.alignment = :center })
30
-
31
- end
32
-
33
- def test_justified
34
- tf = "+----------+\n"
35
- a = [[1,'Z'],[300,'BB']].to_table
36
- assert_equal "#{tf}| 1 | Z |\n| 300 | BB |\n#{tf}", a.to_s
37
- end
38
-
39
- def test_wrapping
40
- a = [[1,2],[300,4]].to_table.as(:text) { |r|
41
- r.layout { |l| l.table_width = 10 }
42
- }
43
-
44
- assert_equal("+------->>\n| 1 | >>\n| 300 | >>\n+------->>\n",a)
45
- end
46
-
47
-
48
- def test_make_sure_this_damn_column_names_bug_dies_a_horrible_death!
49
- a = [[1,2,3]].to_table.to_text
50
- expected = "+-----------+\n"+
51
- "| 1 | 2 | 3 |\n"+
52
- "+-----------+\n"
53
- assert_equal(expected,a)
54
-
55
- end
56
-
57
- def test_raise_error_on_empty_table
58
- assert_raise(RuntimeError) { [].to_table.to_text }
59
- assert_raise(RuntimeError) { [].to_table(%w[a b c]).to_text }
60
- end
61
-
62
-
63
- end
@@ -1,97 +0,0 @@
1
- require "test/unit"
2
- require "ruport"
3
-
4
- begin
5
- require "rubygems"
6
- rescue LoadError
7
- nil
8
- end
9
-
10
- class MockGraphPlugin < Ruport::Format::Plugin
11
- def prepare_graph
12
- output << "prepare"
13
- end
14
- def build_graph
15
- output << "build"
16
- end
17
- def finalize_graph
18
- output << "finalize"
19
- end
20
- end
21
-
22
- Ruport::Renderer::Graph.add_format MockGraphPlugin, :mock
23
-
24
- class TestGraphRenderer < Test::Unit::TestCase
25
-
26
- def test_basics
27
- out = Ruport::Renderer::Graph.render_mock do |r|
28
- r.layout do |l|
29
- assert l.height.kind_of?(Numeric)
30
- assert l.width.kind_of?(Numeric)
31
- assert_equal :line, l.style
32
- end
33
- end
34
-
35
- assert_equal("preparebuildfinalize",out)
36
- end
37
-
38
- def test_report_shortcut
39
- a = Ruport::Report.new
40
- a.extend(Ruport::Report::Graph)
41
-
42
- p = lambda { |e| e.data = [[1,2,3]].to_table(%w[a b c]) }
43
-
44
- b = a.build_graph(&p)
45
- c = b.run
46
- assert_not_nil b.plugin.output
47
-
48
- assert_equal c, a.render_graph(&p)
49
-
50
- end
51
-
52
- end
53
-
54
-
55
- class TestSVGPlugin < Test::Unit::TestCase
56
-
57
- def test_output
58
- assert_not_nil Ruport::Renderer::Graph.render_svg { |r|
59
- r.data = [[1,2,3],[4,5,6]].to_table
60
- }
61
- end
62
-
63
- end
64
-
65
- class TestXMLSWFPlugin < Test::Unit::TestCase
66
-
67
- def test_output
68
-
69
- expected = <<-EOS
70
- <chart>
71
- <chart_type>line</chart_type>
72
- <chart_data>
73
- <row>
74
- <null/>
75
- </row>
76
- <row>
77
- <string>Region 0</string>
78
- <number>1</number>
79
- <number>2</number>
80
- <number>3</number>
81
- </row>
82
- <row>
83
- <string>Region 1</string>
84
- <number>4</number>
85
- <number>5</number>
86
- <number>6</number>
87
- </row>
88
- </chart_data>
89
- </chart>
90
- EOS
91
- assert_equal expected,
92
- Ruport::Renderer::Graph.render_xml { |r|
93
- r.data = [[1,2,3],[4,5,6]].to_table
94
- }
95
- end
96
-
97
- end
@@ -1,56 +0,0 @@
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("grp_foo"); a[1].tag("grp_bar");
13
- a[2].tag("grp_bar"); a[3].tag("grp_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 => %w[foo bar] )
19
- assert_equal expected, a.groups
20
-
21
- a[0].tag("grp_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.groups
27
- end
28
-
29
- def test_create_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_group("starts_odd") { |r| (r[0] % 2) != 0 }
35
- a.create_group(:starts_even) { |r| (r[0] % 2).zero? }
36
-
37
- assert_equal expected, a.groups
38
- assert_equal([[1,2,3],[7,8,9]].to_table(%w[a b c]), a.group("starts_odd"))
39
- assert_equal([[1,2,3],[7,8,9]].to_table(%w[a b c]), a.group(:starts_odd))
40
- assert_equal([[4,5,6]].to_table(%w[a b c]), a.group("starts_even"))
41
-
42
- end
43
-
44
- #--BUG TRAPS-------------------------------------------------------------
45
-
46
- #Ticket #155
47
- def test_ensure_grouping_works_with_nameless_tables
48
- a = [[1,2],[3,4],[5,6]].to_table
49
- a.create_group("foo") { true }
50
- a[1].tag("grp_bar")
51
- assert_nothing_raised { a.groups }
52
- assert_equal a, a.group("foo")
53
- assert_equal [a[1]].to_table, a.group("bar")
54
- end
55
-
56
- end
data/test/test_mailer.rb DELETED
@@ -1,170 +0,0 @@
1
- require "test/unit"
2
- require "ruport"
3
- begin; require "rubygems"; rescue LoadError; nil end
4
-
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
14
-
15
- def setup
16
- @default_opts = {
17
- :host => "mail.example.com",
18
- :address => "sue@example.com",
19
- :user => "inky",
20
- :password => "chunky"
21
- }
22
-
23
- @other_opts = {
24
- :host => "moremail.example.com",
25
- :address => "clyde@example.com",
26
- :user => "blinky",
27
- :password => "bacon"
28
- }
29
-
30
- Ruport::Config.mailer :default, @default_opts
31
- Ruport::Config.mailer :other, @other_opts
32
-
33
- @default_mailer = Ruport::Mailer.new
34
- @other_mailer = Ruport::Mailer.new :other
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
43
-
44
- def test_default_constructor
45
- assert_mailer_equal @default_opts, @default_mailer
46
- end
47
-
48
- def test_constructor_with_mailer_label
49
- assert_mailer_equal @other_opts, @other_mailer
50
- end
51
-
52
- def test_constructor_without_mailer
53
- Ruport::Config.mailers[:default] = nil
54
- assert_raise(RuntimeError) { Ruport::Mailer.new }
55
- end
56
-
57
- def test_select_mailer
58
- mailer = Ruport::Mailer.new :default
59
- assert_mailer_equal @default_opts, mailer
60
-
61
- mailer.send(:select_mailer, :other)
62
- assert_mailer_equal @other_opts, mailer
63
- end
64
-
65
- def test_to
66
- @default_mailer.instance_eval "@mail.to = ['foo@bar.com']"
67
- assert_equal ['foo@bar.com'], @default_mailer.to
68
- end
69
-
70
- def test_to_equals
71
- @default_mailer.to = ['foo@bar.com']
72
- assert_equal ['foo@bar.com'], @default_mailer.to
73
- end
74
-
75
- def test_from
76
- @default_mailer.instance_eval "@mail.from = ['foo@bar.com']"
77
- assert_equal ['foo@bar.com'], @default_mailer.from
78
- end
79
-
80
- def test_from_equals
81
- @default_mailer.from = ['foo@bar.com']
82
- assert_equal ['foo@bar.com'], @default_mailer.from
83
- end
84
-
85
- def test_subject
86
- @default_mailer.instance_eval "@mail.subject = ['RuportDay!']"
87
- assert_equal ['RuportDay!'], @default_mailer.subject
88
- end
89
-
90
- def test_subject_equals
91
- @default_mailer.subject = ['RuportDay!']
92
- assert_equal ['RuportDay!'], @default_mailer.subject
93
- end
94
-
95
- def test_send_mail_with_default
96
- return unless Object.const_defined? :Mocha
97
- setup_mock_mailer(1)
98
- assert_equal "250 ok",
99
- @default_mailer.deliver(:to => "clyde@example.com",
100
- :from => "sue@example.com",
101
- :subject => "Hello",
102
- :text => "This is a test.")
103
- end
104
-
105
- def test_send_mail_with_other
106
- return unless Object.const_defined? :Mocha
107
- setup_mock_mailer(1, @other_mailer)
108
- assert_equal "250 ok",
109
- @other_mailer.deliver(:to => "sue@example.com",
110
- :from => "clyde@example.com",
111
- :subject => "Hello",
112
- :text => "This is a test.")
113
- end
114
-
115
- def test_send_mail_without_to
116
- return unless Object.const_defined? :Mocha
117
- setup_mock_mailer(1)
118
- assert_raise(Net::SMTPSyntaxError) {
119
- @default_mailer.deliver(:from => "sue@example.com",
120
- :subject => "Hello",
121
- :text => "This is a test.")
122
- }
123
- end
124
-
125
- def test_send_html_mail
126
- return unless Object.const_defined? :Mocha
127
- setup_mock_mailer(1)
128
- assert_equal "250 ok",
129
- @default_mailer.deliver(:to => "clyde@example.com",
130
- :from => "sue@example.com",
131
- :subject => "Hello",
132
- :html => "<p>This is a test.</p>")
133
- end
134
-
135
- def test_send_mail_with_attachment
136
- return unless Object.const_defined? :Mocha
137
- setup_mock_mailer(1)
138
- @default_mailer.attach 'test/samples/data.csv'
139
- assert_equal "250 ok",
140
- @default_mailer.deliver(:to => "clyde@example.com",
141
- :from => "sue@example.com",
142
- :subject => "Hello",
143
- :text => "This is a test.")
144
- end
145
-
146
- private
147
-
148
- def setup_mock_mailer(count, mailer=@default_mailer)
149
- host = mailer.instance_variable_get(:@host)
150
- port = mailer.instance_variable_get(:@port)
151
- user = mailer.instance_variable_get(:@user)
152
- password = mailer.instance_variable_get(:@password)
153
- auth = mailer.instance_variable_get(:@auth)
154
-
155
- @smtp = mock('smtp')
156
-
157
- Net::SMTP.expects(:start).
158
- with(host,port,host,user,password,auth).
159
- yields(@smtp).
160
- returns("250 ok").times(count)
161
- @smtp.stubs(:send_message).
162
- with {|*params| !params[2].nil? }.
163
- returns("250 ok")
164
- @smtp.stubs(:send_message).
165
- with {|*params| params[2].nil? }.
166
- raises(Net::SMTPSyntaxError)
167
- end
168
-
169
- end
170
-