spec/pdfkit_spec.rb in pdfkit-0.5.0 vs spec/pdfkit_spec.rb in pdfkit-0.5.1

- old
+ new

@@ -103,10 +103,40 @@ } pdfkit = PDFKit.new(body) pdfkit.command[pdfkit.command.index('"--page-size"') + 1].should == '"Legal"' pdfkit.command[pdfkit.command.index('"--orientation"') + 1].should == '"Landscape"' end + + it "should detect special pdfkit meta tags despite bad markup" do + body = %{ + <html> + <head> + <meta name="pdfkit-page_size" content="Legal"/> + <meta name="pdfkit-orientation" content="Landscape"/> + </head> + <br> + </html> + } + pdfkit = PDFKit.new(body) + pdfkit.command[pdfkit.command.index('"--page-size"') + 1].should == '"Legal"' + pdfkit.command[pdfkit.command.index('"--orientation"') + 1].should == '"Landscape"' + end + + it "should skip non-pdfkit meta tags" do + body = %{ + <html> + <head> + <meta name="test-page_size" content="Legal"/> + <meta name="pdfkit-orientation" content="Landscape"/> + </head> + <br> + </html> + } + pdfkit = PDFKit.new(body) + pdfkit.command[pdfkit.command.index('"--orientation"') + 1].should == '"Landscape"' + end + end context "#to_pdf" do it "should generate a PDF of the HTML" do pdfkit = PDFKit.new('html', :page_size => 'Letter') @@ -163,9 +193,18 @@ it "should create a file with the PDF as content" do pdfkit = PDFKit.new('html', :page_size => 'Letter') file = pdfkit.to_file(@file_path) file.should be_instance_of(File) File.read(file.path)[0...4].should == "%PDF" # PDF Signature at beginning of file + end + + it "should not truncate data (in Ruby 1.8.6)" do + file_path = File.join(SPEC_ROOT,'fixtures','example.html') + pdfkit = PDFKit.new(File.new(file_path)) + pdf_data = pdfkit.to_pdf + file = pdfkit.to_file(@file_path) + file_data = open(@file_path, 'rb') {|io| io.read } + pdf_data.size.should == file_data.size end end context "security" do before do