Last active
October 25, 2022 08:40
-
-
Save joemasilotti/6045144 to your computer and use it in GitHub Desktop.
Revisions
-
joemasilotti revised this gist
Jul 20, 2013 . 2 changed files with 12 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ group :test do gem 'rspec-rails' gem 'capybara' gem 'pdf-reader' end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,16 @@ feature 'Viewing a PDF' do scenario 'User requests the PDF page' do visit "/pdfs.pdf" convert_pdf_to_page page.should have_content("Hi, PDF!") # Passes end end def convert_pdf_to_page temp_pdf = Tempfile.new('pdf') temp_pdf << page.source.force_encoding('UTF-8') reader = PDF::Reader.new(temp_pdf) pdf_text = reader.pages.map(&:text) temp_pdf.close page.driver.response.instance_variable_set('@body', pdf_text) end -
joemasilotti created this gist
Jul 20, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ group :test do gem 'rspec-rails' gem 'capybara' end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ require 'spec_helper' feature 'Viewing a PDF' do scenario 'User requests the PDF page' do visit "/pdfs.pdf" page.should have_content("Hi, PDF!") # Fails: invalid byte sequence in UTF-8 end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ class PdfsController < ApplicationController def index respond_to do |format| format.pdf do render :pdf => 'filename.pdf', :show_as_html => params[:debug] end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ PdfValidation::Application.routes.draw do resources :pdfs, only: [:index] root to: "pdfs#index" end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ %h1 Hi, PDF!