test PDF generation by Prawn in a controller spec

159 views
Skip to first unread message

Javix

unread,
Nov 22, 2012, 5:31:50 AM11/22/12
to rs...@googlegroups.com
According the Prawn wiki at https://github.com/prawnpdf/prawn/wiki/Using-Prawn-in-Rails-3, what is the way to test a PDF generation method in the controller spec:

class HelloController < ApplicationController
   def index
    output = HelloReport.new.to_pdf

    respond_to do |format|
      format.pdf do
        send_data output, :filename => "hello.pdf", 
                          :type => "application/pdf"
      end
    end
  end
end

Thanks

Irish

unread,
Nov 23, 2012, 9:04:57 PM11/23/12
to rs...@googlegroups.com
This is how I do it for CSVs file downloads, you can basically do the same thing for PDFs.  Obviously the content disposition would be different though.

Javix

unread,
Nov 26, 2012, 3:22:40 AM11/26/12
to rs...@googlegroups.com
Thanks a lot, Irish, it works for me.
Reply all
Reply to author
Forward
0 new messages