summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2016-08-16 21:54:30 +0200
committerHarald Eilertsen <haraldei@anduin.net>2016-08-16 21:54:30 +0200
commit9d3cee906330cbbe2dbd1bd4dcb88aa7c160baca (patch)
tree9c158a38f82c64aef3d16157f9a316d1ff9c5f6a
parent206b14869bc36696fc5a3d4aa37bc030d3844162 (diff)
downloadnorsk-urskog-registrations-9d3cee906330cbbe2dbd1bd4dcb88aa7c160baca.tar.gz
norsk-urskog-registrations-9d3cee906330cbbe2dbd1bd4dcb88aa7c160baca.tar.bz2
norsk-urskog-registrations-9d3cee906330cbbe2dbd1bd4dcb88aa7c160baca.zip
Determine if registrations are open or not from config.
-rw-r--r--registration.rb14
-rw-r--r--spec/registration_spec.rb48
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