Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow each contact address to have multiple phone numbers

  • Loading branch information...
commit a2a3b73b65bc70a95546dd0b272678c562a850df 1 parent b3d93b5
@tomafro tomafro authored
View
75 app/assets/javascripts/admin/organisation_contact_form.js
@@ -3,12 +3,12 @@
var self = $(this);
var emptyFieldSet = self.children(".empty_fields");
- var updateId = function(el, attr, id, newId) {
+ var updateId = function(el, name, attr, id, newId) {
switch(attr) {
case "name":
- $(el).attr(attr, $(el).attr(attr).replace("["+id+"]", "["+newId+"]"));
+ $(el).attr(attr, $(el).attr(attr).replace(name + "]["+id+"]", name + "]["+newId+"]"));
default:
- $(el).attr(attr, $(el).attr(attr).replace("_"+id+"_", "_"+newId+"_"));
+ $(el).attr(attr, $(el).attr(attr).replace(name + "_"+id+"_", name + "_"+newId+"_"));
}
};
@@ -18,21 +18,20 @@
var id = parseInt($(referenceInput).attr("id").match(/_(\d)_/)[1]);
var newId = id + 1;
fieldset.children("label").each(function(i, el) {
- updateId(el, "for", id, newId);
+ updateId(el, "contacts_attributes", "for", id, newId);
});
fieldset.children("input").each(function(i, el) {
- updateId(el, "id", id, newId);
- updateId(el, "name", id, newId);
+ updateId(el, "contacts_attributes", "id", id, newId);
+ updateId(el, "contacts_attributes", "name", id, newId);
});
fieldset.children("textarea").each(function(i, el) {
- updateId(el, "id", id, newId);
- updateId(el, "name", id, newId);
+ updateId(el, "contacts_attributes", "id", id, newId);
+ updateId(el, "contacts_attributes", "name", id, newId);
});
};
var addNewContact = function() {
var clone = emptyFieldSet.children("fieldset").clone();
- hideEmptyInputs(clone);
self.append(clone);
updateIdsOnEmptyFields();
};
@@ -45,42 +44,46 @@
self.after(link);
};
- var addRevealLink = function(label) {
- var revealLinks = $(label).parent().find(".reveal_links");
- if (revealLinks.length == 0) {
- revealLinks = $.ul($.li('Add:', '.add'), '.reveal_links');
- $(label).parent().append(revealLinks);
+ var handleRemoveNumber = function() {
+ if ($(this).parent().parent().find('.contact_number').filter(':visible').size() > 1) {
+ $(this).parent().hide();
}
- var link = $.a($.trim($(label).text()));
+ $(this).parent().find('input').val('');
+ }
+
+ var addLinkToAddNewNumber = function() {
+ legend = $(this)
+ var link = $.a('Add number', {'class': 'button add_new'});
link.click(function() {
- $(label).show();
- $("#" + $(label).attr("for")).show();
- link.hide();
- if (revealLinks.find('a:visible').length == 0) {
- revealLinks.hide();
- }
+ fieldset = $(this).parent().parent();
+ newId = fieldset.find('.contact_number').size();
+ var clone = fieldset.find('fieldset.contact_number').filter(':visible').first().clone();
+ $(clone).find('input').val('')
+ $(clone).children("label").each(function(i, el) {
+ updateId(el, "contact_numbers_attributes", "for", 0, newId);
+ });
+ $(clone).children("input").each(function(i, el) {
+ updateId(el, "contact_numbers_attributes", "id", 0, newId);
+ updateId(el, "contact_numbers_attributes", "name", 0, newId);
+ });
+ fieldset.append(clone);
+ $(clone).find('a').click(handleRemoveNumber);
return false;
})
- revealLinks.append($.li(link));
+ legend.append(link);
};
- var hideEmptyInputs = function(fieldset) {
- $.each(fieldset.find("label"), function(i, label) {
- if ($(label).text() == "Description") return;
- var input = fieldset.find("#" + $(label).attr("for"));
- if (input.val() == "") {
- input.hide();
- $(label).hide();
- addRevealLink(label);
- }
- });
- };
+ var addRemoveNumberLink = function() {
+ number = $(this);
+ var link = $.a('remove', {'class': 'button remove'});
+ number.append(link);
+ link.click(handleRemoveNumber);
+ }
addLinkToCloneEmptyFields();
+ $('.contact_numbers legend').each(addLinkToAddNewNumber);
+ $('.contact_numbers .contact_number').each(addRemoveNumberLink);
emptyFieldSet.hide();
- $.each(self.children(".contact:visible"), function(i, fieldset) {
- hideEmptyInputs($(fieldset));
- });
}
$.fn.extend({
View
32 app/assets/stylesheets/shared/forms.scss
@@ -26,6 +26,32 @@
padding-top: 0.5em;
}
+ fieldset.inline {
+ @include clearfix;
+ border-bottom: 1px solid #eee;
+ padding: 1em 0;
+ margin-bottom: 0.4em;
+
+ label, input {
+ float: left;
+ }
+
+ label {
+ margin-right: 0.75em;
+ margin-top: 0.25em;
+ }
+
+ input {
+ margin-right: 1.5em;
+ margin-bottom: 0;
+ }
+
+ a.button {
+ font-size: 0.8em;
+ margin: 0;
+ }
+ }
+
legend {
padding: 0;
@include type-14;
@@ -34,6 +60,12 @@
margin-bottom: 0.5em;
border-bottom: 1px solid #ddd;
color: #777;
+
+ a.button {
+ font-size: 0.9em;
+ margin-left: 1em;
+ margin-bottom: 0.1em;
+ }
}
input[type="text"],
View
6 app/assets/stylesheets/website/organisations.scss
@@ -63,9 +63,9 @@
p.email, p.tel {
@include type-12;
margin-bottom: 0.25em;
-
- span.type {
- display: none;
+ font-weight: bold;
+ .type {
+ font-weight: normal;
}
}
}
View
15 app/controllers/admin/organisations_controller.rb
@@ -2,6 +2,7 @@ class Admin::OrganisationsController < Admin::BaseController
before_filter :load_organisation, only: [:edit, :update]
before_filter :load_news_articles, only: [:edit, :update]
before_filter :default_arrays_of_ids_to_empty, only: [:update]
+ before_filter :destroy_blank_phone_numbers, only: [:create, :update]
def index
@organisations = Organisation.all
@@ -47,4 +48,18 @@ def default_arrays_of_ids_to_empty
params[:organisation][:policy_area_ids] ||= []
params[:organisation][:parent_organisation_ids] ||= []
end
+
+ def destroy_blank_phone_numbers
+ if params[:organisation][:contacts_attributes]
+ params[:organisation][:contacts_attributes].each do |index, contact|
+ if contact && contact[:contact_numbers_attributes]
+ contact[:contact_numbers_attributes].each do |key, number|
+ if number[:label].blank? && number[:number].blank?
+ number[:_destroy] = "1"
+ end
+ end
+ end
+ end
+ end
+ end
end
View
3  app/models/contact.rb
@@ -1,5 +1,8 @@
class Contact < ActiveRecord::Base
belongs_to :organisation
+ has_many :contact_numbers
+ validates :description, presence: true
+ accepts_nested_attributes_for :contact_numbers, allow_destroy: true, reject_if: :all_blank
def mappable?
(latitude.present? and longitude.present?) or postcode.present?
View
4 app/models/contact_number.rb
@@ -0,0 +1,4 @@
+class ContactNumber < ActiveRecord::Base
+ belongs_to :contact
+ validates :label, :number, presence: true
+end
View
20 app/models/organisation.rb
@@ -28,8 +28,7 @@ class Organisation < ActiveRecord::Base
has_many :policy_areas, through: :organisation_policy_areas
has_many :contacts
- accepts_nested_attributes_for :contacts, reject_if: :all_blank
-
+ accepts_nested_attributes_for :contacts, reject_if: :contact_and_contact_numbers_are_blank
validates :name, presence: true, uniqueness: true
validates :organisation_type_id, presence: true
@@ -71,4 +70,21 @@ def search_link
# is still marked as dirty during after_save callbacks.
organisation_path(slug)
end
+
+ private
+
+ def contact_and_contact_numbers_are_blank(attributes)
+ attributes.all? { |key, value|
+ key == '_destroy' ||
+ value.blank? || (
+ (key == "contact_numbers_attributes") &&
+ value.all? { |contact_number_attributes|
+ contact_number_attributes.all? { |contact_number_key, contact_number_value|
+ contact_number_key == '_destroy' ||
+ contact_number_value.blank?
+ }
+ }
+ )
+ }
+ end
end
View
12 app/views/admin/organisations/_contacts_form.html.erb
@@ -2,8 +2,14 @@
<%= contacts_form.text_field :description %>
<%= contacts_form.text_area :address, rows: 3, class: "address" %>
<%= contacts_form.text_field :postcode %>
- <%= contacts_form.text_field :latitude %>
- <%= contacts_form.text_field :longitude %>
<%= contacts_form.text_field :email %>
- <%= contacts_form.text_field :number %>
+ <fieldset class="contact_numbers">
+ <legend>Phone numbers</legend>
+ <%= contacts_form.fields_for :contact_numbers, contacts_form.object.contact_numbers + [ContactNumber.new] do |contact_number_form| %>
+ <fieldset class="contact_number inline">
+ <%= contact_number_form.text_field :label %>
+ <%= contact_number_form.text_field :number %>
+ </fieldset>
+ <% end %>
+ </fieldset>
</fieldset>
View
4 app/views/organisations/show.html.erb
@@ -32,8 +32,8 @@
<% if contact.email.present? %>
<p class="email"><span class="type">Email</span> <%= mail_to contact.email, contact.email, :class => "email" %></p>
<% end %>
- <% if contact.number.present? %>
- <p class="tel"><span class="type"><%= contact.description %></span><%= contact.number %></p>
+ <% contact.contact_numbers.each do |number| %>
+ <p class="tel"><%= number.number %><span class="type"> <%= number.label %> </span></p>
<% end %>
<% if contact.mappable? %>
<p><%= link_to_google_map(contact) %></p>
View
10 db/migrate/20120130155425_add_numbers_to_contacts.rb
@@ -0,0 +1,10 @@
+class AddNumbersToContacts < ActiveRecord::Migration
+ def change
+ create_table :contact_numbers, force: true do |t|
+ t.references :contact
+ t.string :label
+ t.string :number
+ t.timestamps
+ end
+ end
+end
View
12 db/migrate/20120201142659_move_numbers_from_contact_to_contact_numbers.rb
@@ -0,0 +1,12 @@
+class MoveNumbersFromContactToContactNumbers < ActiveRecord::Migration
+ def change
+ insert %{
+ INSERT INTO contact_numbers (contact_id, label, number)
+ SELECT id, description, number
+ FROM contacts
+ WHERE number is not null AND number != ''
+ }
+
+ remove_column :contacts, :number
+ end
+end
View
11 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120201121512) do
+ActiveRecord::Schema.define(:version => 20120201142659) do
create_table "attachments", :force => true do |t|
t.string "carrierwave_file"
@@ -23,9 +23,16 @@
t.string "title"
end
+ create_table "contact_numbers", :force => true do |t|
+ t.integer "contact_id"
+ t.string "label"
+ t.string "number"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "contacts", :force => true do |t|
t.integer "organisation_id"
- t.string "number"
t.string "description"
t.text "address"
t.string "postcode"
View
7 test/factories/contact_numbers.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :contact_number do
+ contact
+ label "fax"
+ number "123"
+ end
+end
View
1  test/factories/contacts.rb
@@ -1,4 +1,5 @@
FactoryGirl.define do
factory :contact do
+ description "Contact description"
end
end
View
76 test/functional/admin/organisations_controller_test.rb
@@ -22,6 +22,25 @@ class Admin::OrganisationsControllerTest < ActionController::TestCase
assert_select parent_organisations_list_selector
assert_select organisation_type_list_selector
assert_select organisation_policy_areas_list_selector
+ assert_select "input[type=text][name='organisation[contacts_attributes][0][description]']"
+ assert_select "textarea[name='organisation[contacts_attributes][0][address]']"
+ assert_select "input[type=text][name='organisation[contacts_attributes][0][postcode]']"
+ assert_select "input[type=text][name='organisation[contacts_attributes][0][contact_numbers_attributes][0][label]']"
+ assert_select "input[type=text][name='organisation[contacts_attributes][0][contact_numbers_attributes][0][number]']"
+ end
+
+ test "should allow creation of an organisation without any contact details" do
+ organisation_type = create(:organisation_type)
+
+ post :create, organisation: {
+ name: "Anything",
+ organisation_type_id: organisation_type.id,
+ contacts_attributes: [{description: "", contact_numbers_attributes: [{label: "", number: ""}]}]
+ }
+
+ organisation = Organisation.last
+ assert_kind_of Organisation, organisation
+ assert_equal "Anything", organisation.name
end
test "creating should create a new Organisation" do
@@ -36,7 +55,7 @@ class Admin::OrganisationsControllerTest < ActionController::TestCase
post :create, organisation: attributes.merge(
organisation_type_id: organisation_type.id,
policy_area_ids: [policy_area.id],
- contacts_attributes: [{description: "Fax", number: "020712435678"}]
+ contacts_attributes: [{description: "Enquiries", contact_numbers_attributes: [{label: "Fax", number: "020712435678"}]}]
)
assert organisation = Organisation.last
@@ -44,7 +63,10 @@ class Admin::OrganisationsControllerTest < ActionController::TestCase
assert_equal attributes[:description], organisation.description
assert_equal attributes[:about_us], organisation.about_us
assert_equal 1, organisation.contacts.count
- assert_equal "Fax", organisation.contacts.first.description
+ assert_equal "Enquiries", organisation.contacts[0].description
+ assert_equal 1, organisation.contacts[0].contact_numbers.count
+ assert_equal "Fax", organisation.contacts[0].contact_numbers[0].label
+ assert_equal "020712435678", organisation.contacts[0].contact_numbers[0].number
assert_equal policy_area, organisation.policy_areas.first
end
@@ -52,8 +74,7 @@ class Admin::OrganisationsControllerTest < ActionController::TestCase
organisation_type = create(:organisation_type)
attributes = attributes_for(:organisation)
post :create, organisation: attributes.merge(
- organisation_type_id: organisation_type.id,
- contacts_attributes: [{description: "Fax", number: "020712435678"}]
+ organisation_type_id: organisation_type.id
)
assert_redirected_to admin_organisations_path
@@ -61,10 +82,7 @@ class Admin::OrganisationsControllerTest < ActionController::TestCase
test "creating without a name should reshow the edit form" do
attributes = attributes_for(:organisation)
- post :create, organisation: attributes.merge(
- name: '',
- contacts_attributes: [{description: "Fax", number: "020712435678"}]
- )
+ post :create, organisation: attributes.merge(name: '')
assert_template "organisations/new"
end
@@ -92,6 +110,32 @@ class Admin::OrganisationsControllerTest < ActionController::TestCase
assert_equal organisation_type, created_organisation.organisation_type
end
+ test "creating with blank numbers ignores blank numbers" do
+ attributes = attributes_for(:organisation,
+ description: "organisation-description",
+ about_us: "organisation-about-us"
+ )
+
+ organisation_type = create(:organisation_type)
+ policy_area = create(:policy_area)
+
+ post :create, organisation: attributes.merge(
+ organisation_type_id: organisation_type.id,
+ policy_area_ids: [policy_area.id],
+ contacts_attributes: {"0" => {
+ description: "Enquiries",
+ contact_numbers_attributes: {
+ "0" => { label: " ", number: " " },
+ "1" => { label: " ", number: " " }
+ }
+ }}
+ )
+
+ created_organisation = Organisation.last
+ assert_not_nil created_organisation
+ assert_equal 0, created_organisation.contacts.first.contact_numbers.size
+ end
+
test "editing should load the requested organisation" do
organisation = create(:organisation)
get :edit, id: organisation
@@ -169,4 +213,20 @@ class Admin::OrganisationsControllerTest < ActionController::TestCase
organisation.reload
assert_equal [], organisation.parent_organisations
end
+
+ test "updating with blank numbers destroys those blank numbers" do
+ organisation = create(:organisation)
+ contact = create(:contact, organisation: organisation)
+ contact_number = create(:contact_number, contact: contact)
+
+ put :update, id: organisation, organisation: { contacts_attributes: { 0 => {
+ id: contact,
+ contact_numbers_attributes: {
+ 0 => { label: " ", number: " ", id: contact_number }
+ }
+ }}}
+
+ contact.reload
+ assert_equal 0, contact.contact_numbers.count
+ end
end
View
21 test/functional/organisations_controller_test.rb
@@ -16,12 +16,15 @@ class OrganisationsControllerTest < ActionController::TestCase
test "presents the contact details of the organisation using hcard" do
ministerial_department = create(:organisation_type, name: "Ministerial Department")
organisation = create(:organisation, organisation_type: ministerial_department,
- name: "Ministry of Pomp", contacts_attributes: [
- {email: "pomp@gov.uk",
- address: "1 Smashing Place, London", postcode: "LO1 8DN"},
- {description: "Helpline", number: "02079460000"},
- {description: "Fax", number: "02079460001"}
- ]
+ name: "Ministry of Pomp", contacts_attributes: [{
+ description: "Main",
+ email: "pomp@gov.uk",
+ address: "1 Smashing Place, London", postcode: "LO1 8DN",
+ contact_numbers_attributes: [
+ { label: "Helpline", number: "02079460000" },
+ { label: "Fax", number: "02079460001" }
+ ]
+ }]
)
get :show, id: organisation
@@ -32,7 +35,7 @@ class OrganisationsControllerTest < ActionController::TestCase
assert_select ".street-address", "1 Smashing Place, London"
assert_select ".postal-code", "LO1 8DN"
end
- assert_select ".tel", /02079460000$/ do
+ assert_select ".tel", /02079460000/ do
assert_select ".type", "Helpline"
end
assert_select ".email", /pomp@gov\.uk/ do
@@ -42,7 +45,7 @@ class OrganisationsControllerTest < ActionController::TestCase
end
test "should use html line breaks when displaying the address" do
- organisation = create(:organisation, contacts_attributes: [{address: "Line 1\nLine 2"}])
+ organisation = create(:organisation, contacts_attributes: [{description: "Main", address: "Line 1\nLine 2"}])
get :show, id: organisation
assert_select ".street-address", /Line 1/
assert_select ".street-address", /Line 2/
@@ -193,7 +196,7 @@ class OrganisationsControllerTest < ActionController::TestCase
end
test "should link to a google map" do
- organisation = create(:organisation, contacts_attributes: [{latitude: 51.498772, longitude: -0.130974}])
+ organisation = create(:organisation, contacts_attributes: [{description: "Main", latitude: 51.498772, longitude: -0.130974}])
get :show, id: organisation
assert_select "a[href='http://maps.google.co.uk/maps?q=51.498772,-0.130974']"
end
View
58 test/javascripts/organisation_contact_form_test.js
@@ -1,6 +1,6 @@
module("Enhancing the organisation contact form", {
setup: function() {
- this. form = $('<form class="organisation_edit"></form>');
+ this.form = $('<form class="organisation_edit"></form>');
this.fieldset = $('<fieldset class="contacts"></fieldset>');
this.form.append(this.fieldset);
@@ -35,7 +35,6 @@ test("should display a new contact form when add link is clicked", function() {
equal(this.fieldset.children(".contact:visible").length, 2);
});
-
test("should continue adding new inputs as new files are selected", function() {
addContact(this.form);
addContact(this.form);
@@ -67,14 +66,51 @@ test("should increment the ID and name of the text input for each set of new inp
equal(latest_input.name, "organisation[contacts_attributes][2][postcode]");
});
-test("should hide empty inputs by default", function() {
- var visibleContact = $(this.fieldset.children("fieldset.contact")[0]);
- equal(visibleContact.find("input:visible").length, 1)
- notEqual(visibleContact.find("input:visible")[0].name, "organisation[contacts_attributes][0][postcode]")
+module("Add and removing contact phone numbers", {
+ setup: function() {
+ this.form = $('<form class="organisation_edit"></form>');
+ this.fieldset = $('<fieldset class="contacts"></fieldset>');
+ this.form.append(this.fieldset);
+
+ this.contactFieldset = $('<fieldset class="contact"></fieldset>');
+ this.contactNumbersFieldset = $('<fieldset class="contact_numbers"></fieldset>')
+ var fieldsetContents = function(id) {
+ id_prefix = 'organisation_contacts_attributes_0_contact_numbers_attributes_' + id
+ name_prefix = 'organisation[contacts_attributes][0][contact_numbers_attributes][' + id + ']'
+
+ return '<fieldset class="contact_number">' +
+ '<label for="' + id_prefix + '_label">Label</label>' +
+ '<input id="' + id_prefix + '_label" name="' + name_prefix + '[label]" size="30" type="text" value="Enquiries" />' +
+ '<label for="' + id_prefix + '_number">Address </label>' +
+ '<input id="' + id_prefix + '_number" name="' + name_prefix + '[number]" size="30" type="text" value="12345678" />' +
+ '</fieldset>';
+ }
+
+ this.contactNumbersFieldset.append(fieldsetContents(0));
+ this.contactNumbersFieldset.append(fieldsetContents(1));
+ this.contactFieldset.append(this.contactNumbersFieldset);
+ this.fieldset.append(this.contactFieldset);
+
+ $('#qunit-fixture').append(this.form);
+ this.fieldset.setupContactsForm();
+ }
});
-test("should provide links to show inputs", function() {
- var visibleContact = $(this.fieldset.children("fieldset.contact")[0]);
- $(visibleContact.find(".reveal_links a")[0]).click()
- equal(visibleContact.find("input:visible").length, 2)
-});
+test("adds remove links to contact", function() {
+ equal(this.contactNumbersFieldset.find('a.remove').length, 2)
+})
+
+test("remove hides and blanks number when other numbers are visible", function() {
+ target = $('.contact_number').first()
+ target.find('a.remove').click();
+ equal(target.is(':visible'), false)
+ equal(target.find('input[value!=""]').length, 0)
+})
+
+test("remove only blanks number when it's the last visible", function() {
+ $('.contact_number').first().find('a.remove').click();
+ target = $('.contact_number').last()
+ target.find('a.remove').click();
+ equal(target.is(':visible'), true)
+ equal(target.find('input[value!=""]').length, 0)
+})
View
18 test/unit/contact_number_test.rb
@@ -0,0 +1,18 @@
+require 'test_helper'
+
+class ContactNumberTest < ActiveSupport::TestCase
+ test "should be valid when built from the factory" do
+ contact_number = build(:contact_number)
+ assert contact_number.valid?
+ end
+
+ test "should be invalid without a label" do
+ contact_number = build(:contact_number, label: nil)
+ refute contact_number.valid?
+ end
+
+ test "should be invalid without a number" do
+ contact_number = build(:contact_number, number: nil)
+ refute contact_number.valid?
+ end
+end
View
25 test/unit/contact_test.rb
@@ -0,0 +1,25 @@
+require "test_helper"
+
+class ContactTest < ActiveSupport::TestCase
+ test "should be valid when built from the factory" do
+ contact = build(:contact)
+ assert contact.valid?
+ end
+
+ test "should be invalid without a description" do
+ contact = build(:contact, description: nil)
+ refute contact.valid?
+ end
+
+ test "should allow creation of nested contact numbers" do
+ contact = create(:contact, contact_numbers_attributes: [{label: "Telephone", number: "123"}])
+ assert_equal 1, contact.contact_numbers.count
+ assert_equal "Telephone", contact.contact_numbers[0].label
+ assert_equal "123", contact.contact_numbers[0].number
+ end
+
+ test "should not create nested contact numbers if their attributes are blank" do
+ contact = create(:contact, contact_numbers_attributes: [{label: "", number: ""}])
+ assert_equal 0, contact.contact_numbers.count
+ end
+end
View
23 test/unit/organisation_test.rb
@@ -76,22 +76,33 @@ class OrganisationTest < ActiveSupport::TestCase
{description: "Office address",
email: "someone@gov.uk", address: "Aviation House, London",
postcode: "WC2A 1BE", latitude: -0.112311, longitude: 51.215125},
- {description: "Helpline", number: "020712345678"},
- {description: "Fax", number: "020712345679"}
+ {description: "Helpline", contact_numbers_attributes: [
+ {label: "Telephone", number: "020712345678"},
+ {label: "Fax", number: "020712345679"}
+ ]}
]
}
organisation = create(:organisation, params)
- assert_equal 3, organisation.contacts.count
+ assert_equal 2, organisation.contacts.count
assert_equal "someone@gov.uk", organisation.contacts[0].email
assert_equal "Aviation House, London", organisation.contacts[0].address
assert_equal "WC2A 1BE", organisation.contacts[0].postcode
assert_equal -0.112311, organisation.contacts[0].latitude
assert_equal 51.215125, organisation.contacts[0].longitude
assert_equal "Helpline", organisation.contacts[1].description
- assert_equal "020712345678", organisation.contacts[1].number
- assert_equal "Fax", organisation.contacts[2].description
- assert_equal "020712345679", organisation.contacts[2].number
+ assert_equal 2, organisation.contacts[1].contact_numbers.count
+ assert_equal "Telephone", organisation.contacts[1].contact_numbers[0].label
+ assert_equal "020712345678", organisation.contacts[1].contact_numbers[0].number
+ assert_equal "Fax", organisation.contacts[1].contact_numbers[1].label
+ assert_equal "020712345679", organisation.contacts[1].contact_numbers[1].number
+ end
+
+ test "should be creatable when both contacts and contact numbers are blank" do
+ organisation = build(:organisation, contacts_attributes: [
+ {description: "", contact_numbers_attributes: [{label: "", number: ""}]}
+ ])
+ assert organisation.valid?
end
test "should set a slug from the organisation name" do
Please sign in to comment.
Something went wrong with that request. Please try again.