diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 8cf46ff56..d3efa9dff 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -15,8 +15,7 @@ class Registrar < ActiveRecord::Base validates :name, :reg_no, :email, :code, presence: true validates :name, :code, uniqueness: true - validates :address_street, :address_zip, :address_city, :address_state, :address_country_code, - presence: true + validates :address_street, :address_city, :address_country_code, presence: true validates :accounting_customer_code, presence: true validates :language, presence: true validates :reference_no, format: Billing::ReferenceNo::REGEXP diff --git a/app/views/admin/registrars/form/_address.html.erb b/app/views/admin/registrars/form/_address.html.erb index d0adfa858..ccac2b03e 100644 --- a/app/views/admin/registrars/form/_address.html.erb +++ b/app/views/admin/registrars/form/_address.html.erb @@ -30,7 +30,7 @@ <%= f.label :state, for: :registrar_address_state %>
- <%= f.text_field :address_state, required: true, class: 'form-control' %> + <%= f.text_field :address_state, class: 'form-control' %>
@@ -39,7 +39,7 @@ <%= f.label :zip, for: :registrar_address_zip %>
- <%= f.text_field :address_zip, required: true, class: 'form-control' %> + <%= f.text_field :address_zip, class: 'form-control' %>
diff --git a/db/migrate/20190520093231_change_registrars_address_state_and_zip_to_null.rb b/db/migrate/20190520093231_change_registrars_address_state_and_zip_to_null.rb new file mode 100644 index 000000000..c6c9a189c --- /dev/null +++ b/db/migrate/20190520093231_change_registrars_address_state_and_zip_to_null.rb @@ -0,0 +1,6 @@ +class ChangeRegistrarsAddressStateAndZipToNull < ActiveRecord::Migration + def change + change_column_null :registrars, :address_state, true + change_column_null :registrars, :address_zip, true + end +end diff --git a/db/structure.sql b/db/structure.sql index 0e71153c8..bec0a6f55 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2189,10 +2189,10 @@ CREATE TABLE public.registrars ( email character varying NOT NULL, billing_email character varying, address_country_code character varying NOT NULL, - address_state character varying NOT NULL, + address_state character varying, address_city character varying NOT NULL, address_street character varying NOT NULL, - address_zip character varying NOT NULL, + address_zip character varying, code character varying NOT NULL, website character varying, accounting_customer_code character varying NOT NULL, @@ -4966,3 +4966,5 @@ INSERT INTO schema_migrations (version) VALUES ('20190510090240'); INSERT INTO schema_migrations (version) VALUES ('20190510102549'); +INSERT INTO schema_migrations (version) VALUES ('20190520093231'); + diff --git a/spec/factories/registrar.rb b/spec/factories/registrar.rb index 07642e3a8..2bc945900 100644 --- a/spec/factories/registrar.rb +++ b/spec/factories/registrar.rb @@ -5,9 +5,7 @@ FactoryBot.define do sequence(:reg_no) { |n| "test#{n}" } email 'test@test.com' address_street 'test' - address_zip 'test' address_city 'test' - address_state 'test' address_country_code 'US' accounting_customer_code 'test' language 'en' diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index 0040ebfef..2f5ed74cf 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -4,9 +4,7 @@ bestnames: code: bestnames email: info@bestnames.test address_street: Main Street 1 - address_zip: 1234 address_city: NY - address_state: NY State address_country_code: US accounting_customer_code: bestnames language: en @@ -20,9 +18,7 @@ goodnames: code: goodnames email: info@goodnames.test address_street: Main Street 1 - address_zip: 1234 address_city: NY - address_state: NY State address_country_code: US vat_no: DE123456789 accounting_customer_code: goodnames @@ -35,9 +31,7 @@ not_in_use: code: any email: any@example.com address_street: Main Street 1 - address_zip: 1234 address_city: NY - address_state: NY State address_country_code: US vat_no: any accounting_customer_code: any @@ -50,9 +44,7 @@ invalid: code: another email: any address_street: Main Street 1 - address_zip: 1234 address_city: NY - address_state: NY State address_country_code: US vat_no: any accounting_customer_code: any diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index 9d1aa4b5a..ad5779475 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -93,16 +93,22 @@ class RegistrarTest < ActiveSupport::TestCase Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active_setting end - def test_invalid_without_address + def test_invalid_without_address_street registrar = valid_registrar - address_parts = %i[street zip city state country_code] + registrar.address_street = '' + assert registrar.invalid? + end - address_parts.each do |address_part| - attribute_name = "address_#{address_part}" - registrar.public_send("#{attribute_name}=", '') - assert registrar.invalid?, "#{attribute_name} should be required" - registrar.public_send("#{attribute_name}=", 'some') - end + def test_invalid_without_address_city + registrar = valid_registrar + registrar.address_city = '' + assert registrar.invalid? + end + + def test_invalid_without_address_country_code + registrar = valid_registrar + registrar.address_country_code = '' + assert registrar.invalid? end def test_full_address