diff options
-rw-r--r-- | lib/band.rb | 6 | ||||
-rw-r--r-- | spec/features/register_band_spec.rb | 56 |
2 files changed, 39 insertions, 23 deletions
diff --git a/lib/band.rb b/lib/band.rb index 49180d8..ac0a9db 100644 --- a/lib/band.rb +++ b/lib/band.rb @@ -17,8 +17,10 @@ class Band @contact = Contact.new(params['contact']) @members = [] - params['members'].each do |k, m| - @members << Member.new(m) + if params['members'] + params['members'].each do |k, m| + @members << Member.new(m) + end end @songs = [] diff --git a/spec/features/register_band_spec.rb b/spec/features/register_band_spec.rb index 65eede4..fd8b08a 100644 --- a/spec/features/register_band_spec.rb +++ b/spec/features/register_band_spec.rb @@ -1,42 +1,56 @@ require 'spec_helper' -feature "Register a band" do - - scenario "with valid input", js: true do - band_params = create_band_params - +feature "Registration form" do + background do visit '/' + @band_params = create_band_params + end - fill_in 'Bandnavn:', with: band_params['name'] - fill_in 'Hjemsted:', with: band_params['city'] - fill_in 'Webside:', with: band_params['website'] - fill_in 'Plateselskap:', with: band_params['label'] - fill_in 'Kort bio:', with: band_params['shortbio'] + scenario "displays thank you page when registration is successful", js: true do + fill_in 'Bandnavn:', with: @band_params['name'] + fill_in 'Hjemsted:', with: @band_params['city'] + fill_in 'Webside:', with: @band_params['website'] + fill_in 'Plateselskap:', with: @band_params['label'] + fill_in 'Kort bio:', with: @band_params['shortbio'] within '#form-contact-info' do - fill_in 'Navn:', with: band_params['contact']['name'] - fill_in 'Postadresse:', with: band_params['contact']['addr'] - fill_in 'Tlf:', with: band_params['contact']['phone'] - fill_in 'E-post:', with: band_params['contact']['email'] + fill_in 'Navn:', with: @band_params['contact']['name'] + fill_in 'Postadresse:', with: @band_params['contact']['addr'] + fill_in 'Tlf:', with: @band_params['contact']['phone'] + fill_in 'E-post:', with: @band_params['contact']['email'] end click_on 'Legg til medlem' within '#form-members .member-info' do - fill_in 'Navn:', with: band_params['members']['1']['name'] + fill_in 'Navn:', with: @band_params['members']['1']['name'] end click_on 'Legg til låt' within '#form-songs #song-1-info' do - fill_in 'Tittel:', with: band_params['songs']['1']['title'] - fill_in 'Lengde:', with: band_params['songs']['1']['time'] - fill_in 'ISRC-kode:', with: band_params['songs']['1']['isrc'] - fill_in 'Utøvere:', with: band_params['songs']['1']['performers'] - fill_in 'Opphavsmenn:', with: band_params['songs']['1']['composers'] - fill_in 'Andre merknader:', with: band_params['songs']['1']['notes'] + fill_in 'Tittel:', with: @band_params['songs']['1']['title'] + fill_in 'Lengde:', with: @band_params['songs']['1']['time'] + fill_in 'ISRC-kode:', with: @band_params['songs']['1']['isrc'] + fill_in 'Utøvere:', with: @band_params['songs']['1']['performers'] + fill_in 'Opphavsmenn:', with: @band_params['songs']['1']['composers'] + fill_in 'Andre merknader:', with: @band_params['songs']['1']['notes'] end click_on 'Send skjema' + + expect(page).to have_content "Takk for at du vil være med på Norsk Urskog" + + expect(page).to have_content "Bandnavn: #{@band_params['name']}" + expect(page).to have_content "Hjemsted: #{@band_params['city']}" + expect(page).to have_content "Webside: #{@band_params['website']}" + expect(page).to have_content "Plateselskap: #{@band_params['label']}" + expect(page).to have_content "Kort bio: #{@band_params['shortbio']}" + end + + scenario "submitting form with no data gives error message, and redisplays form" do + click_on 'Send skjema' + expect(page).to have_content "Det er feil i skjemaet" + expect(page).to have_current_path "/" end end |