diff --git a/Gemfile b/Gemfile index a55e139b..9469d2ab 100644 --- a/Gemfile +++ b/Gemfile @@ -276,6 +276,8 @@ group :test do gem 'rails-controller-testing' # For managing the environment gem 'climate_control' + # For PDFs + gem 'pdf-inspector', require: "pdf/inspector" end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 57852f03..481f3b17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,6 +12,7 @@ GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: + Ascii85 (1.0.3) actioncable (5.0.7.1) actionpack (= 5.0.7.1) nio4r (>= 1.2, < 3.0) @@ -62,6 +63,7 @@ GEM activerecord (>= 3.0) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) + afm (0.2.2) airbrake (7.4.0) airbrake-ruby (~> 2.12) airbrake-ruby (2.12.0) @@ -226,6 +228,7 @@ GEM rubocop (>= 0.50.0) sysexits (~> 1.1) hashdiff (0.3.7) + hashery (2.1.2) hashie (3.5.7) html2haml (2.2.0) erubis (~> 2.7.0) @@ -350,6 +353,14 @@ GEM parser (2.5.3.0) ast (~> 2.4.0) pdf-core (0.2.5) + pdf-inspector (1.3.0) + pdf-reader (>= 1.0, < 3.0.a) + pdf-reader (2.2.0) + Ascii85 (~> 1.0.0) + afm (~> 0.2.1) + hashery (~> 2.0) + ruby-rc4 + ttfunk pg (1.1.3) piwik_analytics (1.0.2) actionpack @@ -497,6 +508,7 @@ GEM ruby-oembed (0.12.0) ruby-openid (2.5.0) ruby-progressbar (1.10.0) + ruby-rc4 (0.1.5) ruby_dep (1.5.0) ruby_parser (3.11.0) sexp_processor (~> 4.9) @@ -664,6 +676,7 @@ DEPENDENCIES omniauth-google-oauth2 omniauth-openid paper_trail + pdf-inspector pg piwik_analytics (~> 1.0.1) prawn-qrcode (~> 0.2.2.1) diff --git a/spec/pdfs/ticket_pdf_spec.rb b/spec/pdfs/ticket_pdf_spec.rb new file mode 100644 index 00000000..fdbc195e --- /dev/null +++ b/spec/pdfs/ticket_pdf_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe TicketPdf do + let(:registration_ticket) { create(:registration_ticket, price_cents: 0) } + let(:conference) do + create( + :conference, + title: 'ExampleCon', + tickets: [registration_ticket], + registration_period: create(:registration_period, start_date: 3.days.ago) + ) + end + let(:participant) { create(:user) } + let(:ticket_purchase) do + create( + :ticket_purchase, + user: participant, + conference: conference, + ticket: registration_ticket, + quantity: 1 + ) + end + let(:physical_ticket) do + create(:physical_ticket, ticket_purchase: ticket_purchase) + end + let(:layout) { conference.ticket_layout.to_sym } + let(:file_name) { "ticket_for_#{conference.short_title}.pdf" } + + it 'generates a PDF for a physical ticket' do + pdf = described_class.new(conference, participant, physical_ticket, layout, file_name) + page_analysis = PDF::Inspector::Page.analyze(pdf.render) + expect(page_analysis.pages.length).to eq(1) + expect(page_analysis.pages.first[:strings]).to include(conference.title) + end +end