From 1c48f48073e33875650b687ced05a51e0fd7f7d3 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 3 Oct 2015 17:41:27 +0200 Subject: Add route to handle submitted form. --- lib/band.rb | 26 ++++++++++++++ lib/contact.rb | 10 ++++++ lib/member.rb | 9 +++++ lib/song.rb | 11 ++++++ public/regform.js | 14 ++++---- registration.rb | 10 ++++++ spec/registration_spec.rb | 92 ++++++++++++++++++++++++++++++++++++++++++++++- views/index.erb | 2 +- views/submitted.erb | 40 +++++++++++++++++++++ 9 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 lib/band.rb create mode 100644 lib/contact.rb create mode 100644 lib/member.rb create mode 100644 lib/song.rb create mode 100644 views/submitted.erb 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() { '

Låt nr '+num_songs+'

' + '
' + ' ' + - ' ' + + ' ' + '
' + '
' + ' ' + - ' '+ + ' '+ '
' + '
' + ' ' + - ' '+ + ' '+ '
' + '
' + ' '+ - ' ' + + ' ' + '
' + '
' + ' '+ - ' ' + + ' ' + '
' + '
' + ' '+ - ' ' + + ' ' + '
' + '' ) }); -}); \ 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 @@

Norsk Urskog 2015

Påmeldingsskjema for Band

Felter merket med er obligatoriske og må fylles ut.

-
+

Generell info:

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 @@ +

Takk for at du vil være med på Norsk Urskog 2016!

+ +

Du har registrert følgende opplysninger:

+ +

Band/Artist:

+
    +
  • Bandnavn: <%= @band.name %>
  • +
  • Hjemsted: <%= @band.city %>
  • +
  • Webside: <%= @band.website %>
  • +
  • Plateselskap: <%= @band.label %>
  • +
  • Kort bio: <%= @band.short_bio %>
  • +
+ +

Kontakt:

+
    +
  • Kontaktperson: <%= @band.contact.name %>
  • +
  • Kontaktadresse: <%= @band.contact.addr %>
  • +
  • Telefon: <%= @band.contact.phone %>
  • +
  • Epost: <%= @band.contact.email %>
  • +
+ +

Medlemmer:

+
    + <% @band.members.each do |m| %> +
  • <%= [m.name, m.instrument, m.age].join(', ') %>
  • + <% end %> +
+ +

Låter:

+
    + <% @band.songs.each do |s| %> +
  • + <%= s.title %>
    + Spilletid: <%= s.time %>
    + Utøvere: <%= s.performers.split("\n").join(', ') %>
    + Låtskrivere: <%= s.composers.split("\n").join(', ') %>
    + Merknad: <%= s.notes %> +
  • + <% end %> +
-- cgit v1.2.3