diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2015-10-03 17:41:27 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2015-10-03 17:47:28 +0200 |
commit | 1c48f48073e33875650b687ced05a51e0fd7f7d3 (patch) | |
tree | 0426fff05d78335a81c7c2d369e00d29bfbc0028 | |
parent | ff7a2f930d58e0cb02ffee76e250a02e6b3c7ce3 (diff) | |
download | norsk-urskog-registrations-1c48f48073e33875650b687ced05a51e0fd7f7d3.tar.gz norsk-urskog-registrations-1c48f48073e33875650b687ced05a51e0fd7f7d3.tar.bz2 norsk-urskog-registrations-1c48f48073e33875650b687ced05a51e0fd7f7d3.zip |
Add route to handle submitted form.
-rw-r--r-- | lib/band.rb | 26 | ||||
-rw-r--r-- | lib/contact.rb | 10 | ||||
-rw-r--r-- | lib/member.rb | 9 | ||||
-rw-r--r-- | lib/song.rb | 11 | ||||
-rw-r--r-- | public/regform.js | 14 | ||||
-rw-r--r-- | registration.rb | 10 | ||||
-rw-r--r-- | spec/registration_spec.rb | 92 | ||||
-rw-r--r-- | views/index.erb | 2 | ||||
-rw-r--r-- | views/submitted.erb | 40 |
9 files changed, 205 insertions, 9 deletions
diff --git a/lib/band.rb b/lib/band.rb new file mode 100644 index 0000000..44d1e7c --- /dev/null +++ b/lib/band.rb @@ -0,0 +1,26 @@ +require_relative 'contact' +require_relative 'member' +require_relative 'song' + +class Band + attr_reader :name, :city, :website, :label, :short_bio, :contact, :members, :songs + + def initialize(params) + @name = params['name'] + @city = params['city'] + @website = params['website'] + @label = params['label'] + @short_bio = params['shortbio'] + @contact = Contact.new(params['contact']) + + @members = [] + params['members'].each do |k, m| + @members << Member.new(m) + end + + @songs = [] + params['songs'].each do |k, s| + @songs << Song.new(s) + end + end +end diff --git a/lib/contact.rb b/lib/contact.rb new file mode 100644 index 0000000..1e6ba4b --- /dev/null +++ b/lib/contact.rb @@ -0,0 +1,10 @@ +class Contact + attr_reader :name, :addr, :phone, :email + + def initialize(params) + @name = params['name'] + @addr = params['addr'] + @phone = params['phone'] + @email = params['email'] + end +end diff --git a/lib/member.rb b/lib/member.rb new file mode 100644 index 0000000..c67915a --- /dev/null +++ b/lib/member.rb @@ -0,0 +1,9 @@ +class Member + attr_reader :name, :instrument, :age + + def initialize(params) + @name = params['name'] + @instrument = params['instrument'] + @age = params['age'].to_i + end +end diff --git a/lib/song.rb b/lib/song.rb new file mode 100644 index 0000000..c045ed2 --- /dev/null +++ b/lib/song.rb @@ -0,0 +1,11 @@ +class Song + attr_reader :title, :time, :composers, :performers, :notes + + def initialize(params) + @title = params['title'] + @time = params['time'] + @composers = params['composers'] + @performers = params['performers'] + @notes = params['notes'] + end +end diff --git a/public/regform.js b/public/regform.js index 00e5486..7509f0b 100644 --- a/public/regform.js +++ b/public/regform.js @@ -30,30 +30,30 @@ $(function() { ' <h4>Låt nr '+num_songs+'<input type="button" id="delete-song-'+num_songs+'" class="delete-song" value="X"></h4>' + ' <div class="field text required">' + ' <label>Tittel:</label>' + - ' <input type="text" name="song['+num_songs+'][title]">' + + ' <input type="text" name="band[songs]['+num_songs+'][title]">' + ' </div>' + ' <div class="field text optional">' + ' <label>Lengde:</label>' + - ' <input type="text" pattern="[0-9]{2}:[0-9]{2}" title="Spilletid i min:sek (mm:ss)" name="song['+num_songs+'][time]" size="6">'+ + ' <input type="text" pattern="[0-9]{2}:[0-9]{2}" title="Spilletid i min:sek (mm:ss)" name="band[songs]['+num_songs+'][time]" size="6">'+ ' </div>' + ' <div class="field text optional">' + ' <label>ISRC-kode:</label>' + - ' <input type="text" title="Dersom låten har vært utgitt før har den en ISRC-kode. Om du vet den så oppgi den her." name="song['+num_songs+'][isrc]" size="11">'+ + ' <input type="text" title="Dersom låten har vært utgitt før har den en ISRC-kode. Om du vet den så oppgi den her." name="band[songs]['+num_songs+'][isrc]" size="11">'+ ' </div>' + ' <div class="field textarea required">' + ' <label>Utøvere:</label>'+ - ' <textarea cols="40" rows="5" name="song['+num_songs+'][performers]" title="Fullt navn (ingen pseudonymer) på alle som er med på denne innspillingen."></textarea>' + + ' <textarea cols="40" rows="5" name="band[songs]['+num_songs+'][performers]" title="Fullt navn (ingen pseudonymer) på alle som er med på denne innspillingen."></textarea>' + ' </div>' + ' <div class="field textarea required">' + ' <label>Opphavsmenn:</label>'+ - ' <textarea cols="40" rows="5" name="song['+num_songs+'][composers]" title="Fullt navn (ingen pseudonymer) på alle som har vært med på å skrive denne låten."></textarea>' + + ' <textarea cols="40" rows="5" name="band[songs]['+num_songs+'][composers]" title="Fullt navn (ingen pseudonymer) på alle som har vært med på å skrive denne låten."></textarea>' + ' </div>' + ' <div class="field textarea optional">' + ' <label>Andre merknader:</label>'+ - ' <textarea cols="40" rows="5" name="song['+num_songs+'][notes]" title="Evt andre ting vi burde vite."></textarea>' + + ' <textarea cols="40" rows="5" name="band[songs]['+num_songs+'][notes]" title="Evt andre ting vi burde vite."></textarea>' + ' </div>' + '</div>' ) }); -});
\ No newline at end of file +}); diff --git a/registration.rb b/registration.rb index de9ec75..9fae54f 100644 --- a/registration.rb +++ b/registration.rb @@ -1,4 +1,5 @@ require 'sinatra/base' +require_relative 'lib/band' class RegistrationApp < Sinatra::Base @@ -6,5 +7,14 @@ class RegistrationApp < Sinatra::Base erb :index end + post '/submit' do + if request.form_data? + #p request['band'] + @band = Band.new(request['band']) + + erb :submitted + end + end + run! if app_file == $0 end diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb index 1f89321..5f398c0 100644 --- a/spec/registration_spec.rb +++ b/spec/registration_spec.rb @@ -6,9 +6,99 @@ describe RegistrationApp do end describe 'GET index' do - it 'displays the registration form' do + before :each do get '/' + 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 add member button' do + expect(last_response.body).to match /id="add-member-button"/ + end + + it 'displays the add song button' do + expect(last_response.body).to match /id="add-song-button"/ + end + end + + describe 'POST submit' do + context 'with a valid registration' do + before :each do + params = { + 'name' => 'Imbalance', + 'city' => 'Oslo', + 'website' => 'http://imbalance.no', + 'label' => 'Calculated Imperfection', + 'shortbio' => 'Thrash metal from Norway', + 'contact' => { + 'name' => 'Harald Eilertsen', + 'addr' => "Gamleveien 13\n1289 Snufstad", + 'phone' => '98765432', + 'email' => 'mail@imbalance.no' + }, + 'members' => { + '1' => { + 'name' => 'Harald Eilertsen', + 'instrument' => 'Bass/Vocals', + 'age' => '' + }, + '2' => { + 'name' => 'Welle', + 'instrument' => 'Drums', + 'age' => '' + }, + '3' => { + 'name' => 'Thormodr', + 'instrument' => 'Guitar', + 'age' => '' + } + }, + 'songs' => { + '1' => { + 'title' => 'Bestial by Nature', + 'time' => '02:80', + 'isrc' => '', + 'performers' => "Harald Eilertsen\nThormod Steinert\nLars Welle", + 'composers' => "Harald Eilertsen\nThormod Steinert", + 'notes' => 'Rævrukkje rum kjurr!' + } + } + } + post '/submit', 'band' => params + end + + it 'should succeed' do + expect(last_response).to be_ok + end + + it 'displays submitted data to user' do + expect(last_response).to match /Bandnavn\: Imbalance/ + expect(last_response).to match /Hjemsted\: Oslo/ + expect(last_response).to match /Webside\: http\:\/\/imbalance.no/ + expect(last_response).to match /Plateselskap\: Calculated Imperfection/ + expect(last_response).to match /Kort bio\: Thrash metal from Norway/ + + expect(last_response).to match /Kontaktperson: Harald Eilertsen/ + expect(last_response).to match /Kontaktadresse: Gamleveien 13\n1289 Snufstad/ + expect(last_response).to match /Telefon: 98765432/ + expect(last_response).to match /Epost: mail@imbalance\.no/ + + expect(last_response).to match /Harald Eilertsen, Bass\/Vocals/ + expect(last_response).to match /Welle, Drums/ + expect(last_response).to match /Thormodr, Guitar/ + + expect(last_response).to match /Bestial by Nature/ + expect(last_response).to match /Spilletid: 02:80/ + expect(last_response).to match /Utøvere: Harald Eilertsen, Thormod Steinert, Lars Welle/ + expect(last_response).to match /Låtskrivere: Harald Eilertsen, Thormod Steinert/ + expect(last_response).to match /Merknad: Rævrukkje rum kjurr!/ + end + end end end diff --git a/views/index.erb b/views/index.erb index 64a7de3..51ec288 100644 --- a/views/index.erb +++ b/views/index.erb @@ -1,7 +1,7 @@ <h1>Norsk Urskog 2015</h1> <h2>Påmeldingsskjema for Band</h2> <p>Felter merket med <span class="required"></span> er obligatoriske og må fylles ut.</p> - <form id="registration-form" action="mailto:haraldei@anduin.net"> + <form id="registration-form" action="<%= url('submit') %>" method="POST" > <div id="form-general-info" class="fieldgroup"> <h3>Generell info:</h3> diff --git a/views/submitted.erb b/views/submitted.erb new file mode 100644 index 0000000..9b6837d --- /dev/null +++ b/views/submitted.erb @@ -0,0 +1,40 @@ +<h1>Takk for at du vil være med på Norsk Urskog 2016!</h1> + +<p>Du har registrert følgende opplysninger:</p> + +<p>Band/Artist:</p> +<ul> + <li>Bandnavn: <%= @band.name %></li> + <li>Hjemsted: <%= @band.city %></li> + <li>Webside: <%= @band.website %></li> + <li>Plateselskap: <%= @band.label %></li> + <li>Kort bio: <%= @band.short_bio %></li> +</ul> + +<p>Kontakt:</p> +<ul> + <li>Kontaktperson: <%= @band.contact.name %></li> + <li>Kontaktadresse: <%= @band.contact.addr %></li> + <li>Telefon: <%= @band.contact.phone %></li> + <li>Epost: <%= @band.contact.email %></li> +</ul> + +<p>Medlemmer:</p> +<ul> + <% @band.members.each do |m| %> + <li><%= [m.name, m.instrument, m.age].join(', ') %></li> + <% end %> +</ul> + +<p>Låter:</p> +<ul> + <% @band.songs.each do |s| %> + <li> + <%= s.title %><br> + Spilletid: <%= s.time %><br> + Utøvere: <%= s.performers.split("\n").join(', ') %><br> + Låtskrivere: <%= s.composers.split("\n").join(', ') %><br> + Merknad: <%= s.notes %> + </li> + <% end %> +</ul> |