Changeset 1291

Show
Ignore:
Timestamp:
03/23/08 19:39:32 (8 months ago)
Author:
sandal
Message:

Fix for #387

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ruport/trunk/lib/ruport/controller.rb

    r1288 r1291  
    480480 
    481481    finalize self.class.final_stage if self.class.final_stage 
     482    maybe :finalize 
    482483  end   
    483484   
  • ruport/trunk/lib/ruport/formatter/pdf.rb

    r1287 r1291  
    383383          text_opts[:angle] || 0) 
    384384        move_cursor_to(ypos) 
     385      end    
     386       
     387      def finalize 
     388        render_pdf 
    385389      end 
    386390    end    
  • ruport/trunk/test/pdf_formatter_test.rb

    r1286 r1291  
    200200     assert_equal({ :justification => :center },  
    201201                  f.options[:table_format][:column_options][:heading])       
    202   end 
     202  end         
    203203     
    204204end     
     
    327327    assert_equal 100, a.cursor 
    328328  end 
     329end   
     330   
     331class SimpleController < Ruport::Controller 
     332  stage :foo 
     333   
     334  class PDF < Ruport::Formatter::PDF 
     335    renders :pdf, :for => SimpleController 
     336     
     337    build :foo do 
     338      add_text "Blah" 
     339    end 
     340  end 
     341end                                 
     342 
     343class TestPDFFinalize < Test::Unit::TestCase 
     344 
     345  context "When rendering a PDF" do     
     346    def specify_finalize_should_be_called 
     347      SimpleController.render_pdf do |r| 
     348        r.formatter.expects(:render_pdf) 
     349      end  
     350    end 
     351  end 
     352   
    329353end 
     354     
  • ruport/trunk/test/renderer_test.rb

    r1286 r1291  
    8585  renders :bin, :for => VanillaController 
    8686  save_as_binary_file 
    87 end 
    88  
     87end  
     88 
     89class SpecialFinalize < Ruport::Formatter 
     90  renders :with_finalize, :for => VanillaController 
     91   
     92  def finalize 
     93    output << "I has been finalized" 
     94  end 
     95end 
    8996 
    9097class TestController < Test::Unit::TestCase 
     
    97104    actual = OldSchoolController.render(:text) 
    98105    assert_equal "header\nbody\nfooter\n", actual 
    99   end     
     106  end           
     107   
     108  context "when running a formatter with custom a finalize method" do 
     109    def specify_finalize_method_should_be_called 
     110      assert_equal "I has been finalized",  
     111                   VanillaController.render_with_finalize 
     112    end                 
     113  end 
    100114   
    101115  context "when using templates" do