Permalink
Browse files

Fix for #5, thanks Brian

git-svn-id: http://stonecode.svnrepository.com/svn/ruport-util/trunk@41 8bb0c7d9-1235-0410-a803-a4cf5c4fc5c0
  • Loading branch information...
1 parent 643a978 commit 285ca544948af8b6f17e28693dbd29cacbc8bbb3 sandal committed Feb 2, 2008
Showing with 26 additions and 6 deletions.
  1. +3 −2 example/invoice_report.rb
  2. +2 −2 lib/ruport/util/invoice.rb
  3. +12 −1 lib/ruport/util/query.rb
  4. +9 −1 test/test_query.rb
@@ -1,10 +1,11 @@
+require "rubygems"
require "ruport"
require "ruport/util"
class SampleReport < Ruport::Report
include Invoice
- def generate
+ def renderable_data(format)
render_invoice do |i|
i.data = Table("Item Number","Description","Price") { |t|
t << %w[101 Erlang\ The\ Movie $1000.00]
@@ -25,4 +26,4 @@ def generate
end
a = SampleReport.new
-File.open("invoice.pdf","wb") { |f| f << a.generate }
+a.save_as("invoice.pdf")
@@ -22,7 +22,7 @@ def build_company_header
end
def build_customer_header
- move_cursor -5
+ move_cursor(-5)
rounded_text_box(options.customer_info) { |o|
o.radius = 3
o.width = options.header_width || 200
@@ -99,7 +99,7 @@ def build_invoice_footer
horizontal_line left_boundary + 20, right_boundary - 25
- move_cursor -10
+ move_cursor(-10)
add_text(options.comments,:justification => :center,
:left => 0, :right => 0 )
@@ -66,13 +66,24 @@ class Query
# # explicitly use a file, even if it doesn't end in .sql
# Ruport::Query.new(:file => "foo")
#
+ # # query with parameter substitution
+ # Ruport::Query.new("select * from fo where bar=?", :params => [1234])
+ # Ruport::Query.new(:file => "foo", :params => [1234])
+ #
+ # # query with parameter substitution (ActiveRecord style)
+ # Ruport::Query.new(["select * from fo where bar=?", 1234])
+ #
def initialize(sql, options={})
if sql.kind_of?(Hash)
options = { :source => :default }.merge(sql)
sql = options[:file] || options[:string]
else
+ if sql.kind_of?(Array)
+ options[:params] = sql[1..-1]
+ sql = sql.first
+ end
options = { :source => :default, :string => sql }.merge(options)
- options[:file] = sql if sql =~ /.sql$/
+ options[:file] = sql if sql =~ /\.sql$/
end
origin = options[:file] ? :file : :string
View
@@ -29,6 +29,7 @@
:plain => Ruport::Query.new(@sql[0]),
:sourced => Ruport::Query.new(@sql[0], :source => :alternative),
:paramed => Ruport::Query.new(@sql[0], :params => [ 42 ]),
+ :paramed_ar => Ruport::Query.new([@sql[0], 69, 777]),
:raw => Ruport::Query.new(@sql[0], :row_type => :raw),
:resultless => Ruport::Query.new(@sql[1]),
:multi => Ruport::Query.new(@sql[2]),
@@ -52,13 +53,20 @@
query.execute.should == nil
end
- it "should allow excute to accept parameters" do
+ it "should allow execute to accept parameters" do
query = @query[:paramed]
setup_mock_dbi(1, :params => [ 42 ])
query.execute.should == nil
end
+ it "should allow execute to accept parameters (ActiveRecord style)" do
+ query = @query[:paramed_ar]
+ setup_mock_dbi(1, :params => [ 69, 777 ])
+
+ query.execute.should == nil
+ end
+
it "should return nil for empty results" do
query = @query[:resultless]
setup_mock_dbi(1, :resultless => true, :sql => @sql[1])

0 comments on commit 285ca54

Please sign in to comment.