summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2016-08-16 22:19:39 +0200
committerHarald Eilertsen <haraldei@anduin.net>2016-08-16 22:21:49 +0200
commit9594f5be7daa673b88654e0f47db07d1c1454765 (patch)
tree29785fb57273a5c98c75e592e0078c751a376382
parent62326cb57470475fd10e83e28d56a92e6cbc07bf (diff)
downloadnorsk-urskog-registrations-9594f5be7daa673b88654e0f47db07d1c1454765.tar.gz
norsk-urskog-registrations-9594f5be7daa673b88654e0f47db07d1c1454765.tar.bz2
norsk-urskog-registrations-9594f5be7daa673b88654e0f47db07d1c1454765.zip
Move registration open check to before filter.
-rw-r--r--registration.rb6
-rw-r--r--spec/email_spec.rb5
-rw-r--r--spec/registration_spec.rb165
3 files changed, 105 insertions, 71 deletions
diff --git a/registration.rb b/registration.rb
index e85fc47..f7a31b0 100644
--- a/registration.rb
+++ b/registration.rb
@@ -13,11 +13,13 @@ class RegistrationApp < Sinatra::Base
config_file File.join(settings.root, 'config.yml')
- get '/' do
+ before do
if !accept_registrations(settings)
- return erb :registration_closed
+ halt erb :registration_closed
end
+ end
+ get '/' do
@band = Band.new
3.times { @band.songs << Song.new }
erb :index
diff --git a/spec/email_spec.rb b/spec/email_spec.rb
index 5c4d310..e68d77f 100644
--- a/spec/email_spec.rb
+++ b/spec/email_spec.rb
@@ -12,6 +12,11 @@ RSpec.describe "sending email" do
let(:band_params) { create_band_params }
before :each do
+ app.set :accept_registrations, {
+ start: Date.today.iso8601,
+ stop: (Date.today + 30).iso8601
+ }
+
@mail_spy = spy("Mail")
allow(Mail).to receive('new') { @mail_spy }
allow(@mail_spy).to receive(:deliver!).and_raise(Net::SMTPFatalError.new("Some error message"))
diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb
index 387a445..4dd57d5 100644
--- a/spec/registration_spec.rb
+++ b/spec/registration_spec.rb
@@ -59,105 +59,132 @@ describe RegistrationApp do
Mail::TestMailer.deliveries.clear
end
- context 'with a valid registration' do
- let(:band_params) { create_band_params }
+ context 'when registration is open' do
before :each do
- post '/submit', 'band' => band_params
+ app.set :accept_registrations, {
+ start: Date.today.iso8601,
+ stop: (Date.today + 1).iso8601
+ }
end
- it 'should succeed' do
- expect(last_response).to be_ok
- end
+ context 'with a valid registration' do
+ let(:band_params) { create_band_params }
+ before :each do
+ post '/submit', 'band' => band_params
+ end
- it 'should not display any errors' do
- expect(last_response.body).not_to include("Det er feil i skjemaet")
- end
+ it 'should succeed' do
+ expect(last_response).to be_ok
+ end
+
+ it 'should not display any errors' do
+ expect(last_response.body).not_to include("Det er feil i skjemaet")
+ end
- it 'displays submitted data to user' do
- expect(last_response).to match(/Bandnavn\: #{band_params['name']}/)
- expect(last_response).to match(/Hjemsted\: #{band_params['city']}/)
- expect(last_response).to match(/Webside\: #{band_params['website']}/)
- expect(last_response).to match(/Plateselskap\: #{band_params['label']}/)
- expect(last_response).to match(/Kort bio\: #{band_params['shortbio']}/)
+ it 'displays submitted data to user' do
+ expect(last_response).to match(/Bandnavn\: #{band_params['name']}/)
+ expect(last_response).to match(/Hjemsted\: #{band_params['city']}/)
+ expect(last_response).to match(/Webside\: #{band_params['website']}/)
+ expect(last_response).to match(/Plateselskap\: #{band_params['label']}/)
+ expect(last_response).to match(/Kort bio\: #{band_params['shortbio']}/)
+
+ expect(last_response).to match(/Kontaktperson: #{band_params['contact']['name']}/)
+ expect(last_response).to match(/Kontaktadresse: #{band_params['contact']['addr']}/)
+ expect(last_response).to match(/Telefon: #{band_params['contact']['phone']}/)
+ expect(last_response).to match(/Epost: #{band_params['contact']['email']}/)
+
+ expect(last_response).to match(/#{band_params['members']['1']['name']}, #{band_params['members']['1']['instrument']}/)
+ expect(last_response).to match(/#{band_params['members']['2']['name']}, #{band_params['members']['2']['instrument']}/)
+ expect(last_response).to match(/#{band_params['members']['3']['name']}, #{band_params['members']['3']['instrument']}/)
+
+ expect(last_response).to match(/#{band_params['songs']['1']['title']}/)
+ expect(last_response).to match(/Spilletid: #{band_params['songs']['1']['time']}/)
+ expect(last_response).to match(/Utøvere: #{band_params['songs']['1']['performers'].split("\n").join(", ")}/)
+ expect(last_response).to match(/Låtskrivere: #{band_params['songs']['1']['composers'].split("\n").join(", ")}/)
+ expect(last_response).to match(/Merknad: #{band_params['songs']['1']['notes']}/)
+ end
- expect(last_response).to match(/Kontaktperson: #{band_params['contact']['name']}/)
- expect(last_response).to match(/Kontaktadresse: #{band_params['contact']['addr']}/)
- expect(last_response).to match(/Telefon: #{band_params['contact']['phone']}/)
- expect(last_response).to match(/Epost: #{band_params['contact']['email']}/)
+ 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(/uploads\/[0-9]{4}-[0-9]{2}-[0-9]{2}-#{sanitize(band_params['name'])}-#{sanitize(band_params['city'])}\.pdf/)
+ end
- expect(last_response).to match(/#{band_params['members']['1']['name']}, #{band_params['members']['1']['instrument']}/)
- expect(last_response).to match(/#{band_params['members']['2']['name']}, #{band_params['members']['2']['instrument']}/)
- expect(last_response).to match(/#{band_params['members']['3']['name']}, #{band_params['members']['3']['instrument']}/)
+ describe 'sends an email to Norsk Urskog' do
+ let(:message) { Mail::TestMailer.deliveries.first }
- expect(last_response).to match(/#{band_params['songs']['1']['title']}/)
- expect(last_response).to match(/Spilletid: #{band_params['songs']['1']['time']}/)
- expect(last_response).to match(/Utøvere: #{band_params['songs']['1']['performers'].split("\n").join(", ")}/)
- expect(last_response).to match(/Låtskrivere: #{band_params['songs']['1']['composers'].split("\n").join(", ")}/)
- expect(last_response).to match(/Merknad: #{band_params['songs']['1']['notes']}/)
- end
+ it 'is not empty' do
+ expect(Mail::TestMailer.deliveries).not_to be_empty
+ end
- 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(/uploads\/[0-9]{4}-[0-9]{2}-[0-9]{2}-#{sanitize(band_params['name'])}-#{sanitize(band_params['city'])}\.pdf/)
+ it 'contains the band info' do
+ expect(message.subject).to match(/Registrering av band #{band_params['name']} til Norsk Urskog/)
+ end
+
+ it 'contains the url to the pdf file' do
+ expect(message.body).to match(/example.org\/uploads\/[0-9]{4}-[0-9]{2}-[0-9]{2}-#{sanitize(band_params['name'])}-#{sanitize(band_params['city'])}\.pdf/)
+ end
+ end
end
- describe 'sends an email to Norsk Urskog' do
- let(:message) { Mail::TestMailer.deliveries.first }
+ shared_examples_for('form with errors') do |args|
+ let(:band_params) { create_band_params(args) }
- it 'sends an email to Norsk Urskog' do
- expect(Mail::TestMailer.deliveries).not_to be_empty
- expect(message.to).to include('haraldei@anduin.net')
- expect(message.subject).to match(/Registrering av band #{band_params['name']} til Norsk Urskog/)
+ before :each do
+ post '/submit', 'band' => band_params
end
- it 'contains the url to the pdf file' do
- expect(message.body).to match(/example.org\/uploads\/[0-9]{4}-[0-9]{2}-[0-9]{2}-#{sanitize(band_params['name'])}-#{sanitize(band_params['city'])}\.pdf/)
+ it 'should go back to the registration form' do
+ expect(last_response.body).to match(/form id="registration-form"/)
end
- end
- end
- shared_examples_for('form with errors') do |args|
- let(:band_params) { create_band_params(args) }
+ it 'should display an error message' do
+ expect(last_response.body).to include("Det er feil i skjemaet")
+ end
+ end
- before :each do
- post '/submit', 'band' => band_params
+ context 'with no songs' do
+ include_examples('form with errors', {:songs => 0})
end
- it 'should go back to the registration form' do
- expect(last_response.body).to match(/form id="registration-form"/)
+ context 'without a band name' do
+ include_examples('form with errors', {:name => ''})
end
- it 'should display an error message' do
- expect(last_response.body).to include("Det er feil i skjemaet")
+ context 'with a band name with only spaces' do
+ include_examples('form with errors', {:name => ' '})
end
- end
- context 'with no songs' do
- include_examples('form with errors', {:songs => 0})
- end
+ context 'with no contact' do
+ include_examples('form with errors', {:contact_name => ''})
+ end
- context 'without a band name' do
- include_examples('form with errors', {:name => ''})
- end
+ context 'with no contact address' do
+ include_examples('form with errors', {:contact_addr => ''})
+ end
- context 'with a band name with only spaces' do
- include_examples('form with errors', {:name => ' '})
- end
+ context 'with no contact phone' do
+ include_examples('form with errors', {:contact_phone => ''})
+ end
- context 'with no contact' do
- include_examples('form with errors', {:contact_name => ''})
+ context 'with no contact email' do
+ include_examples('form with errors', {:contact_email => ''})
+ end
end
- context 'with no contact address' do
- include_examples('form with errors', {:contact_addr => ''})
- end
+ context 'when registration is closed' do
+ let(:band_params) { create_band_params }
+ before :each do
+ app.set :accept_registrations, {
+ start: (Date.today + 1).iso8601,
+ stop: (Date.today + 30).iso8601
+ }
- context 'with no contact phone' do
- include_examples('form with errors', {:contact_phone => ''})
- end
+ post '/submit', 'band' => band_params
+ end
- context 'with no contact email' do
- include_examples('form with errors', {:contact_email => ''})
+ it 'redirects to registration closed message' do
+ expect(last_response.body).to match('Registreringen er stengt')
+ end
end
end
end