summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2015-10-13 18:30:07 +0200
committerHarald Eilertsen <haraldei@anduin.net>2015-10-13 18:30:07 +0200
commit35d3ed2b09b3eff694d285a57d3ff911ef3f0ec2 (patch)
tree4d8001fe55e70a5848520fe07f767639141e01e3
parent800f8b9ee333fa703b30e3761124428564456908 (diff)
downloadnorsk-urskog-registrations-35d3ed2b09b3eff694d285a57d3ff911ef3f0ec2.tar.gz
norsk-urskog-registrations-35d3ed2b09b3eff694d285a57d3ff911ef3f0ec2.tar.bz2
norsk-urskog-registrations-35d3ed2b09b3eff694d285a57d3ff911ef3f0ec2.zip
Preserve info when redisplaying form on errors.
-rw-r--r--spec/features/register_band_spec.rb78
-rw-r--r--views/index.erb21
2 files changed, 50 insertions, 49 deletions
diff --git a/spec/features/register_band_spec.rb b/spec/features/register_band_spec.rb
index fd8b08a..8970137 100644
--- a/spec/features/register_band_spec.rb
+++ b/spec/features/register_band_spec.rb
@@ -1,56 +1,54 @@
require 'spec_helper'
-feature "Registration form" do
+feature "Submit registration form" do
background do
visit '/'
@band_params = create_band_params
end
- 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']
- end
+ context "with all fields filled in" do
+ scenario "displays thank you page", js: true do
+ fill_in_form_with(@band_params)
- click_on 'Legg til medlem'
+ expect(page).to have_content "Takk for at du vil være med på Norsk Urskog"
- within '#form-members .member-info' do
- fill_in 'Navn:', with: @band_params['members']['1']['name']
+ 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
+ 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']
+ context "with no data" do
+ scenario "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_content "Påmeldingsskjema for Band"
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 "/"
+ context "with invalid data" do
+ scenario "retains submitted data in form", js: true do
+ @band_params['songs'] = nil
+ fill_in_form_with(@band_params)
+
+ expect(find_field('Bandnavn:').value).to eql(@band_params['name'])
+ expect(find_field('Hjemsted:').value).to eql(@band_params['city'])
+ expect(find_field('Webside:').value).to eql(@band_params['website'])
+ expect(find_field('Plateselskap:').value).to eql(@band_params['label'])
+ expect(find_field('Kort bio:').value).to eql(@band_params['shortbio'])
+
+ within ('#form-contact-info') do
+ expect(find_field('Navn:').value).to eql(@band_params['contact']['name'])
+ expect(find_field('Postadresse:').value).to eql(@band_params['contact']['addr'])
+ expect(find_field('Tlf:').value).to eql(@band_params['contact']['phone'])
+ expect(find_field('E-post:').value).to eql(@band_params['contact']['email'])
+ end
+
+ within '#form-members .member-info' do
+ expect(find_field('Navn:').value).to eql(params['members']['1']['name'])
+ end
+ end
end
end
diff --git a/views/index.erb b/views/index.erb
index 1a63651..8565a31 100644
--- a/views/index.erb
+++ b/views/index.erb
@@ -7,27 +7,27 @@
<div class="field text required">
<label for="band_name">Bandnavn:</label>
- <input type="text" id="band_name" name="band[name]">
+ <input type="text" id="band_name" name="band[name]" value="<%= @band.name %>">
</div>
<div class="field text optional">
<label for="band_city">Hjemsted:</label>
- <input type="text" id="band_city" name="band[city]">
+ <input type="text" id="band_city" name="band[city]" value="<%= @band.city %>">
</div>
<div class="field text optional">
<label for="band_website">Webside:</label>
- <input type="text" id="band_website" name="band[website]">
+ <input type="text" id="band_website" name="band[website]" value="<%= @band.website %>">
</div>
<div class="field text optional">
<label for="band_label">Plateselskap:</label>
- <input type="text" id="band_label" name="band[label]">
+ <input type="text" id="band_label" name="band[label]" value="<%= @band.label %>">
</div>
<div class="field text required">
<label for="band_shortbio">Kort bio:</label>
- <textarea cols="40" rows="5" id="band_shortbio" name="band[shortbio]"></textarea>
+ <textarea cols="40" rows="5" id="band_shortbio" name="band[shortbio]"><%= @band.short_bio %></textarea>
</div>
</div>
@@ -35,22 +35,22 @@
<h3>Kontaktperson</h3>
<div class="field text required">
<label for="band-contact-name">Navn:</label>
- <input type="text" id="band-contact-name" name="band[contact][name]">
+ <input type="text" id="band-contact-name" name="band[contact][name]" value="<%= @band.contact.name %>">
</div>
<div class="field textarea required">
<label for="band-contact-addr">Postadresse:</label>
- <textarea cols="40" rows="4" id="band-contact-addr" name="band[contact][addr]"></textarea>
+ <textarea cols="40" rows="4" id="band-contact-addr" name="band[contact][addr]"><%= @band.contact.addr %></textarea>
</div>
<div class="field text required">
<label for="band-contact-phone">Tlf:</label>
- <input type="text" id="band-contact-phone" name="band[contact][phone]">
+ <input type="text" id="band-contact-phone" name="band[contact][phone]" value="<%= @band.contact.phone %>">
</div>
<div class="field text required">
<label for="band-contact-email">E-post:</label>
- <input type="text" id="band-contact-email" name="band[contact][email]">
+ <input type="text" id="band-contact-email" name="band[contact][email]" value="<%= @band.contact.email %>">
</div>
</div>
@@ -59,6 +59,9 @@
<p>Klikk på knappen under for å legge til medlemmene som er med i bandet. Dette er kun til
informasjon for websider, promomateriale og lignende. Har bandmedlemene pseudonymer de
foretrekker å bruke, så kan du bruke dem her.</p>
+ <% @band.members.each do |member| %>
+ <%= erb :member, layout: false, locals: { member_number: 1 } %>
+ <% end %>
</div>
<input type="button" name="add_member" value="Legg til medlem" id="add-member-button">