summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/contact.rb18
-rw-r--r--spec/features/register_band_spec.rb4
-rw-r--r--spec/registration_spec.rb4
-rw-r--r--spec/support/band_factory.rb8
-rw-r--r--spec/support/submit_form_helper.rb4
-rw-r--r--views/index.erb22
6 files changed, 47 insertions, 13 deletions
diff --git a/lib/contact.rb b/lib/contact.rb
index 5e6c475..ffa33bf 100644
--- a/lib/contact.rb
+++ b/lib/contact.rb
@@ -1,23 +1,33 @@
class Contact
- attr_reader :name, :addr, :phone, :email
+ attr_reader :name, :street, :postcode, :city, :phone, :email
def initialize(params = nil)
if params
@name = params['name']
- @addr = params['addr']
+ @street = params['street']
+ @postcode = params['postcode']
+ @city = params['city']
@phone = params['phone']
@email = params['email']
end
end
+ def addr
+ "#{@street}, #{@postcode} #{@city}"
+ 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"
+ if @postcode.nil? || @postcode.strip.empty?
+ errors << "Du må oppgi et gyldig postnr."
+ end
+
+ if @city.nil? || @city.strip.empty?
+ errors << "Du må oppgi poststed."
end
if @phone.nil? || @phone.strip.empty?
diff --git a/spec/features/register_band_spec.rb b/spec/features/register_band_spec.rb
index f75315d..5d812bc 100644
--- a/spec/features/register_band_spec.rb
+++ b/spec/features/register_band_spec.rb
@@ -47,7 +47,9 @@ feature "Submit registration form" do
within ('#form-contact-info') do
expect(find_field('Navn:').value).to eql(@band_params['contact']['name'])
- expect(find_field('Postadresse:').value.gsub("\r\n", "\n")).to eql(@band_params['contact']['addr'])
+ expect(find_field('Adresse:').value).to eql(@band_params['contact']['street'])
+ expect(find_field('Postnr:').value).to eql(@band_params['contact']['postcode'])
+ expect(find_field('Sted:').value).to eql(@band_params['contact']['city'])
expect(find_field('Tlf:').value).to eql(@band_params['contact']['phone'])
expect(find_field('E-post:').value).to eql(@band_params['contact']['email'])
end
diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb
index d1875d7..9dc7616 100644
--- a/spec/registration_spec.rb
+++ b/spec/registration_spec.rb
@@ -87,7 +87,7 @@ describe RegistrationApp do
expect(last_response).to match(/Kort bio\: #{band_params['shortbio']}/)
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(/Kontaktadresse: #{band_params['contact']['street']}, #{band_params['contact']['postcode']} #{band_params['contact']['city']}/)
expect(last_response).to match(/Telefon: #{band_params['contact']['phone']}/)
expect(last_response).to match(/Epost: #{band_params['contact']['email']}/)
@@ -157,7 +157,7 @@ describe RegistrationApp do
end
context 'with no contact address' do
- include_examples('form with errors', {:contact_addr => ''})
+ include_examples('form with errors', {:contact_city => '', :contact_postcode => '', :contact_street => ''})
end
context 'with no contact phone' do
diff --git a/spec/support/band_factory.rb b/spec/support/band_factory.rb
index 3ae2589..b092653 100644
--- a/spec/support/band_factory.rb
+++ b/spec/support/band_factory.rb
@@ -8,7 +8,9 @@ module BandFactory
:label => 'A Record Label',
:bio => 'A short bio about the band',
:contact_name => 'Contact Name',
- :contact_addr => "Streetname 666\n1234Someplace Nice",
+ :contact_street => "Streetname 666",
+ :contact_postcode => "1234",
+ :contact_city => "Someplace Nice",
:contact_phone => '98765432',
:contact_email => 'band@example.com',
:members => "Member 1 (Instrument 1, 24\nMember 2 (Instrument 2)\nMember 3",
@@ -24,7 +26,9 @@ module BandFactory
'shortbio' => opts[:bio],
'contact' => {
'name' => opts[:contact_name],
- 'addr' => opts[:contact_addr],
+ 'street' => opts[:contact_street],
+ 'postcode' => opts[:contact_postcode],
+ 'city' => opts[:contact_city],
'phone' => opts[:contact_phone],
'email' => opts[:contact_email]
},
diff --git a/spec/support/submit_form_helper.rb b/spec/support/submit_form_helper.rb
index 30816cf..b9a64aa 100644
--- a/spec/support/submit_form_helper.rb
+++ b/spec/support/submit_form_helper.rb
@@ -9,7 +9,9 @@ module SubmitFormHelper
within '#form-contact-info' do
fill_in 'Navn:', with: params['contact']['name']
- fill_in 'Postadresse:', with: params['contact']['addr']
+ fill_in 'Adresse:', with: params['contact']['street']
+ fill_in 'Postnr:', with: params['contact']['postcode']
+ fill_in 'Sted:', with: params['contact']['city']
fill_in 'Tlf:', with: params['contact']['phone']
fill_in 'E-post:', with: params['contact']['email']
end
diff --git a/views/index.erb b/views/index.erb
index d38d5a6..fceb73b 100644
--- a/views/index.erb
+++ b/views/index.erb
@@ -53,9 +53,25 @@
<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 id="band-contact-addr" name="band[contact][addr]"><%= @band.contact.addr %></textarea>
+ <div class="field text">
+ <label for="band-contact-street">Adresse:</label>
+ <input type="text" id="band-contact-street"
+ name="band[contact][street]"
+ value="<%= @band.contact.street %>">
+ </div>
+
+ <div class="field text required">
+ <label for="band-contact-postcode">Postnr:</label>
+ <input type="text" id="band-contact-postcode"
+ name="band[contact][postcode]"
+ value="<%= @band.contact.postcode %>">
+ </div>
+
+ <div class="field text required">
+ <label for="band-contact-city">Sted:</label>
+ <input type="text" id="band-contact-city"
+ name="band[contact][city]"
+ value="<%= @band.contact.city %>">
</div>
<div class="field text required">