Skip to content

Commit

Permalink
Fix for #387
Browse files Browse the repository at this point in the history
git-svn-id: http://stonecode.svnrepository.com/svn/ruport/ruport/trunk@1291 bb2e8eb0-7117-0410-aac4-c024b40ed5f7
  • Loading branch information
sandal committed Mar 24, 2008
1 parent 380e1b5 commit 96fdb86
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/ruport/controller.rb
Expand Up @@ -479,6 +479,7 @@ def _run_
end

finalize self.class.final_stage if self.class.final_stage
maybe :finalize
end

def execute_stages
Expand Down
4 changes: 4 additions & 0 deletions lib/ruport/formatter/pdf.rb
Expand Up @@ -382,6 +382,10 @@ def draw_text!(text,text_opts)
text_opts[:font_size],
text_opts[:angle] || 0)
move_cursor_to(ypos)
end

def finalize
render_pdf
end
end

Expand Down
27 changes: 26 additions & 1 deletion test/pdf_formatter_test.rb
Expand Up @@ -199,7 +199,7 @@ def test_draw_table_should_not_destroy_nested_rendering_options
f.draw_table Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
assert_equal({ :justification => :center },
f.options[:table_format][:column_options][:heading])
end
end

end

Expand Down Expand Up @@ -326,4 +326,29 @@ def test_draw_text_retains_cursor
a.draw_text "foo", :left => a.left_boundary + 50, :y => 500
assert_equal 100, a.cursor
end
end

class SimpleController < Ruport::Controller
stage :foo

class PDF < Ruport::Formatter::PDF
renders :pdf, :for => SimpleController

build :foo do
add_text "Blah"
end
end
end

class TestPDFFinalize < Test::Unit::TestCase

context "When rendering a PDF" do
def specify_finalize_should_be_called
SimpleController.render_pdf do |r|
r.formatter.expects(:render_pdf)
end
end
end

end

18 changes: 16 additions & 2 deletions test/renderer_test.rb
Expand Up @@ -84,8 +84,15 @@ def finalize_document; end
class VanillaBinary < Ruport::Formatter
renders :bin, :for => VanillaController
save_as_binary_file
end
end

class SpecialFinalize < Ruport::Formatter
renders :with_finalize, :for => VanillaController

def finalize
output << "I has been finalized"
end
end

class TestController < Test::Unit::TestCase

Expand All @@ -96,7 +103,14 @@ def teardown
def test_trivial
actual = OldSchoolController.render(:text)
assert_equal "header\nbody\nfooter\n", actual
end
end

context "when running a formatter with custom a finalize method" do
def specify_finalize_method_should_be_called
assert_equal "I has been finalized",
VanillaController.render_with_finalize
end
end

context "when using templates" do
def specify_apply_template_should_be_called
Expand Down

0 comments on commit 96fdb86

Please sign in to comment.