From 9d3cee906330cbbe2dbd1bd4dcb88aa7c160baca Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 16 Aug 2016 21:54:30 +0200 Subject: Determine if registrations are open or not from config. --- registration.rb | 14 +++++++++++++- spec/registration_spec.rb | 48 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/registration.rb b/registration.rb index 3638ed7..8501a37 100644 --- a/registration.rb +++ b/registration.rb @@ -13,8 +13,20 @@ class RegistrationApp < Sinatra::Base config_file File.join(settings.root, 'config.yml') + + helpers do + def accept_registrations + start_date = Date.parse(settings.accept_registrations[:start]) + end_date = Date.parse(settings.accept_registrations[:stop]) + start_date <= Date.today && end_date > Date.today + end + end + get '/' do - #erb :registration_closed + if !accept_registrations + return erb :registration_closed + end + @band = Band.new 3.times { @band.songs << Song.new } erb :index diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb index 8d04d89..387a445 100644 --- a/spec/registration_spec.rb +++ b/spec/registration_spec.rb @@ -9,22 +9,46 @@ describe RegistrationApp do end describe 'GET index' do - before :each do - get '/' - end + context 'when registration is open' do + before :each do + app.set :accept_registrations, { + start: Date.today.iso8601, + stop: (Date.today + 1).iso8601 + } + get '/' + end - it 'should succeed' do - expect(last_response).to be_ok - end + it 'should succeed' do + expect(last_response).to be_ok + end + + it 'displays the registration form' do + expect(last_response.body).to match(/form id="registration-form"/) + end - it 'displays the registration form' do - expect(last_response.body).to match(/form id="registration-form"/) + it 'allows three songs' do + expect(last_response.body).to match(/Låt nr. 1/) + expect(last_response.body).to match(/Låt nr. 2/) + expect(last_response.body).to match(/Låt nr. 3/) + end end - it 'allows three songs' do - expect(last_response.body).to match(/Låt nr. 1/) - expect(last_response.body).to match(/Låt nr. 2/) - expect(last_response.body).to match(/Låt nr. 3/) + context 'when registration is closed' do + before :each do + app.set :accept_registrations, { + start: (Date.today + 1).iso8601, + stop: (Date.today + 30).iso8601 + } + get '/' + end + + it 'should succeed' do + expect(last_response).to be_ok + end + + it 'displays message that registration is closed' do + expect(last_response.body).to match(/Registreringen er stengt/) + end end end -- cgit v1.2.3