diff options
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 6 | ||||
-rw-r--r-- | lib/registration.rb | 5 | ||||
-rw-r--r-- | registration.rb | 1 | ||||
-rw-r--r-- | spec/registration_spec.rb | 12 |
5 files changed, 24 insertions, 1 deletions
@@ -2,6 +2,7 @@ source "https://rubygems.org" gem "sinatra" gem "mail" +gem "prawn" group :development, :test do gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index 4a18b9f..a057e87 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,10 @@ GEM mail (2.6.3) mime-types (>= 1.16, < 3) mime-types (2.6.2) + pdf-core (0.6.0) + prawn (2.0.2) + pdf-core (~> 0.6.0) + ttfunk (~> 1.4.0) rack (1.6.4) rack-protection (1.5.3) rack @@ -29,6 +33,7 @@ GEM rack-protection (~> 1.4) tilt (>= 1.3, < 3) tilt (2.0.1) + ttfunk (1.4.0) PLATFORMS ruby @@ -36,6 +41,7 @@ PLATFORMS DEPENDENCIES byebug mail + prawn rack-test rspec sinatra diff --git a/lib/registration.rb b/lib/registration.rb index 5a31ca0..51c7663 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -11,3 +11,8 @@ def send_registration_emails_for(band) mail.deliver! end + +def generate_pdf_for(band) + Prawn::Document.generate("#{band.name}.pdf") do + end +end diff --git a/registration.rb b/registration.rb index f599bfd..e5be8f0 100644 --- a/registration.rb +++ b/registration.rb @@ -11,6 +11,7 @@ class RegistrationApp < Sinatra::Base if request.form_data? #p request['band'] @band = Band.new(request['band']) + generate_pdf_for @band send_registration_emails_for @band erb :submitted end diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb index ed95fae..c8858cc 100644 --- a/spec/registration_spec.rb +++ b/spec/registration_spec.rb @@ -1,3 +1,5 @@ +require "prawn" + describe RegistrationApp do include Rack::Test::Methods @@ -76,6 +78,10 @@ describe RegistrationApp do } } } + + class_spy("Prawn::Document") + allow(Prawn::Document).to receive('generate') + post '/submit', 'band' => params end @@ -106,7 +112,11 @@ describe RegistrationApp do expect(last_response).to match /Merknad: Rævrukkje rum kjurr!/ end - it 'sends and email to Norsk Urskog' do + it "generates a PDF file" do + expect(Prawn::Document).to have_received('generate').with("Imbalance.pdf") + end + + it 'sends an email to Norsk Urskog' do message = Mail::TestMailer.deliveries.first expect(Mail::TestMailer.deliveries).not_to be_empty expect(message.to).to include('haraldei@anduin.net') |