summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/deploy.rb2
-rw-r--r--lib/pdf_form.rb4
-rw-r--r--lib/registration.rb8
-rw-r--r--registration.rb2
-rw-r--r--spec/registration_spec.rb2
-rw-r--r--test_pdf.rb2
6 files changed, 12 insertions, 8 deletions
diff --git a/config/deploy.rb b/config/deploy.rb
index b695413..2a835d6 100644
--- a/config/deploy.rb
+++ b/config/deploy.rb
@@ -9,7 +9,7 @@ set :deploy_to, '/usr/local/www/norsk-urskog/registration'
set :linked_files, fetch(:linked_files, []).push('config.yml')
# Default value for linked_dirs is []
-# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
+set :linked_dirs, fetch(:linked_dirs, []).push('public/uploads')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
diff --git a/lib/pdf_form.rb b/lib/pdf_form.rb
index 19756a7..0695c47 100644
--- a/lib/pdf_form.rb
+++ b/lib/pdf_form.rb
@@ -7,7 +7,7 @@ class PDFForm
@document = Prawn::Document.new(:page_size => "A4")
end
- def render
+ def render(filename)
heading
next_line
@@ -45,7 +45,7 @@ class PDFForm
end_text
@document.number_pages "Side <page>", :align => :center, :at => [0, 0]
- @document.render_file "#{@band.name}.pdf"
+ @document.render_file filename
end
private
diff --git a/lib/registration.rb b/lib/registration.rb
index 9826f91..5ace438 100644
--- a/lib/registration.rb
+++ b/lib/registration.rb
@@ -13,7 +13,11 @@ def send_registration_emails_for(band)
mail.deliver!
end
-def generate_pdf_for(band)
+def generate_pdf_for(band, filename)
pdf = PDFForm.new(band)
- pdf.render
+ pdf.render(filename)
+end
+
+def create_pdf_file_name(band)
+ filename = "#{Date.today.iso8601}-#{band.name}-#{band.city}.pdf"
end
diff --git a/registration.rb b/registration.rb
index 1ba2aee..ac1a362 100644
--- a/registration.rb
+++ b/registration.rb
@@ -21,7 +21,7 @@ class RegistrationApp < Sinatra::Base
if request.form_data?
@band = Band.new(request['band'])
if @band.valid?
- generate_pdf_for @band
+ generate_pdf_for(@band, File.join(settings.public_folder, "uploads", create_pdf_file_name(@band)))
send_registration_emails_for @band
erb :submitted
else
diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb
index 96ae18f..9bbf477 100644
--- a/spec/registration_spec.rb
+++ b/spec/registration_spec.rb
@@ -68,7 +68,7 @@ describe RegistrationApp do
it "generates a PDF file" do
expect(Prawn::Document).to have_received('new').with({ :page_size => "A4" })
- expect(@doc_spy).to have_received('render_file').with("#{band_params['name']}.pdf")
+ expect(@doc_spy).to have_received('render_file').with(/uploads\/[0-9]{4}-[0-9]{2}-[0-9]{2}-#{band_params['name']}-#{band_params['city']}\.pdf/)
end
it 'sends an email to Norsk Urskog' do
diff --git a/test_pdf.rb b/test_pdf.rb
index 12dd3b8..8328ee6 100644
--- a/test_pdf.rb
+++ b/test_pdf.rb
@@ -34,4 +34,4 @@ params = {
}
}
-generate_pdf_for Band.new(params)
+generate_pdf_for(Band.new(params), "output.pdf")