diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2015-10-10 18:36:09 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2015-10-10 18:36:09 +0200 |
commit | 800f8b9ee333fa703b30e3761124428564456908 (patch) | |
tree | a4b56b38c22a7c1cc7ffe0007390e540e7913bbc | |
parent | d9696a5eb4aa8638b757ca95b4cc2a4d5b8ae4f6 (diff) | |
download | norsk-urskog-registrations-800f8b9ee333fa703b30e3761124428564456908.tar.gz norsk-urskog-registrations-800f8b9ee333fa703b30e3761124428564456908.tar.bz2 norsk-urskog-registrations-800f8b9ee333fa703b30e3761124428564456908.zip |
Validate presence of contact info when submitting form.
-rw-r--r-- | lib/band.rb | 2 | ||||
-rw-r--r-- | lib/contact.rb | 21 | ||||
-rw-r--r-- | spec/registration_spec.rb | 26 | ||||
-rw-r--r-- | spec/support/band_factory.rb | 14 |
4 files changed, 53 insertions, 10 deletions
diff --git a/lib/band.rb b/lib/band.rb index 59e7541..8cd3535 100644 --- a/lib/band.rb +++ b/lib/band.rb @@ -45,6 +45,8 @@ class Band errors << "Bandnavn mangler" end + errors.concat(@contact.validate!) + if @songs.length <= 0 errors << "Du må ha med minst én låt!" end diff --git a/lib/contact.rb b/lib/contact.rb index 0d87012..5e6c475 100644 --- a/lib/contact.rb +++ b/lib/contact.rb @@ -9,4 +9,25 @@ class Contact @email = params['email'] end end + + def validate! + errors = [] + if @name.nil? || @name.strip.empty? + errors << "Du må oppgi en kontaktperson" + end + + if @addr.nil? || @addr.strip.empty? + errors << "Du må oppgi en kontaktadresse" + end + + if @phone.nil? || @phone.strip.empty? + errors << "Du må oppgi et telefonnummer" + end + + if @email.nil? || @email.strip.empty? + errors << "Du må oppgi en epostadresse" + end + + errors + end end diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb index e4d5ff4..89e2fa5 100644 --- a/spec/registration_spec.rb +++ b/spec/registration_spec.rb @@ -58,10 +58,10 @@ describe RegistrationApp do 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(/Kontaktperson: #{band_params['contact']['name']}/) + expect(last_response).to match(/Kontaktadresse: #{band_params['contact']['addr']}/) + expect(last_response).to match(/Telefon: #{band_params['contact']['phone']}/) + expect(last_response).to match(/Epost: #{band_params['contact']['email']}/) expect(last_response).to match(/Harald Eilertsen, Bass\/Vocals/) expect(last_response).to match(/Welle, Drums/) @@ -88,7 +88,7 @@ describe RegistrationApp do end shared_examples_for('form with errors') do |args| - let (:band_params) { create_band_params(args) } + let(:band_params) { create_band_params(args) } describe "form with errors" do before :each do @@ -116,5 +116,21 @@ describe RegistrationApp do context 'with a band name with only spaces' do it_behaves_like('form with errors', {:name => ' '}) end + + context 'with no contact' do + it_behaves_like('form with errors', {:contact_name => ''}) + end + + context 'with no contact address' do + it_behaves_like('form with errors', {:contact_addr => ''}) + end + + context 'with no contact phone' do + it_behaves_like('form with errors', {:contact_phone => ''}) + end + + context 'with no contact email' do + it_behaves_like('form with errors', {:contact_phone => ''}) + end end end diff --git a/spec/support/band_factory.rb b/spec/support/band_factory.rb index 4bf9a15..498f532 100644 --- a/spec/support/band_factory.rb +++ b/spec/support/band_factory.rb @@ -2,7 +2,11 @@ module BandFactory def create_band_params(options = {}) opts = { :songs => 1, - :name => 'Band name' + :name => 'Band name', + :contact_name => 'Contact Name', + :contact_addr => "Streetname 666\n1234Someplace Nice", + :contact_phone => '98765432', + :contact_email => 'band@example.com' }.merge(options) num_songs = opts.delete(:songs) @@ -14,10 +18,10 @@ module BandFactory 'label' => 'Calculated Imperfection', 'shortbio' => 'Thrash metal from Norway', 'contact' => { - 'name' => 'Harald Eilertsen', - 'addr' => "Gamleveien 13\n1289 Snufstad", - 'phone' => '98765432', - 'email' => 'mail@imbalance.no' + 'name' => opts[:contact_name], + 'addr' => opts[:contact_addr], + 'phone' => opts[:contact_phone], + 'email' => opts[:contact_email] }, 'members' => { '1' => { |