diff --git a/app/models/registrar.rb b/app/models/registrar.rb
index 8c3de65b9..1d2f2b4bd 100644
--- a/app/models/registrar.rb
+++ b/app/models/registrar.rb
@@ -13,8 +13,10 @@ class Registrar < ActiveRecord::Base
delegate :balance, to: :cash_account, allow_nil: true
- validates :name, :reg_no, :address_country_code, :email, :code, presence: true
+ 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 :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 2fe1217a0..5956e1c8c 100644
--- a/app/views/admin/registrars/form/_address.html.erb
+++ b/app/views/admin/registrars/form/_address.html.erb
@@ -9,46 +9,48 @@
diff --git a/db/migrate/20190510102549_change_registrars_address_parts_to_not_null.rb b/db/migrate/20190510102549_change_registrars_address_parts_to_not_null.rb
new file mode 100644
index 000000000..de3f5dbca
--- /dev/null
+++ b/db/migrate/20190510102549_change_registrars_address_parts_to_not_null.rb
@@ -0,0 +1,8 @@
+class ChangeRegistrarsAddressPartsToNotNull < ActiveRecord::Migration
+ def change
+ change_column_null :registrars, :address_street, false
+ change_column_null :registrars, :address_zip, false
+ change_column_null :registrars, :address_city, false
+ change_column_null :registrars, :address_state, false
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 1e746e1a7..fdd8b19ce 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,
- address_city character varying,
- address_street character varying,
- address_zip character varying,
+ address_state character varying NOT NULL,
+ address_city character varying NOT NULL,
+ address_street character varying NOT NULL,
+ address_zip character varying NOT NULL,
code character varying NOT NULL,
website character varying,
accounting_customer_code character varying NOT NULL,
@@ -4947,3 +4947,5 @@ INSERT INTO schema_migrations (version) VALUES ('20190415120246');
INSERT INTO schema_migrations (version) VALUES ('20190510090240');
+INSERT INTO schema_migrations (version) VALUES ('20190510102549');
+
diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml
index b20adb197..0040ebfef 100644
--- a/test/fixtures/registrars.yml
+++ b/test/fixtures/registrars.yml
@@ -19,6 +19,10 @@ goodnames:
reg_no: 12345
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
@@ -30,6 +34,10 @@ not_in_use:
reg_no: any
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
@@ -41,6 +49,10 @@ invalid:
reg_no: any
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 69be5efb8..7e31f1649 100644
--- a/test/models/registrar_test.rb
+++ b/test/models/registrar_test.rb
@@ -55,12 +55,6 @@ class RegistrarTest < ActiveSupport::TestCase
assert_equal 'de', registrar.language
end
- def test_full_address
- registrar = Registrar.new(address_street: 'Main Street 1', address_zip: '1234',
- address_city: 'NY', address_state: 'NY State')
- assert_equal 'Main Street 1, NY, NY State, 1234', registrar.address
- end
-
def test_validates_reference_number_format
@registrar.reference_no = '1'
assert @registrar.invalid?
@@ -99,6 +93,24 @@ class RegistrarTest < ActiveSupport::TestCase
Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active_setting
end
+ def test_invalid_without_address
+ registrar = valid_registrar
+ address_parts = %i[street zip city state country_code]
+
+ 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
+ end
+
+ def test_full_address
+ registrar = Registrar.new(address_street: 'Main Street 1', address_zip: '1234',
+ address_city: 'NY', address_state: 'NY State')
+ assert_equal 'Main Street 1, NY, NY State, 1234', registrar.address
+ end
+
private
def valid_registrar
diff --git a/test/system/admin_area/registrars_test.rb b/test/system/admin_area/registrars_test.rb
index dfea9ed18..3d3e1c4f0 100644
--- a/test/system/admin_area/registrars_test.rb
+++ b/test/system/admin_area/registrars_test.rb
@@ -9,21 +9,25 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
end
def test_creates_new_registrar
- assert_nil Registrar.find_by(name: 'New name')
+ assert_nil Registrar.find_by(name: 'Acme Ltd')
visit admin_registrars_path
click_on 'New registrar'
- fill_in 'Name', with: 'New name'
- fill_in 'Reg no', with: '55555555'
- fill_in 'Contact e-mail', with: 'any@registrar.test'
+ fill_in 'Name', with: 'Acme Ltd'
+ fill_in 'Reg no', with: '1234'
+ fill_in 'Contact e-mail', with: 'any@acme.test'
+ fill_in 'Street', with: 'any'
+ fill_in 'City', with: 'any'
+ fill_in 'State / Province', with: 'any'
+ fill_in 'Zip', with: 'any'
select 'United States', from: 'Country'
fill_in 'Accounting customer code', with: 'test'
fill_in 'Code', with: 'test'
click_on 'Create registrar'
assert_text 'Registrar has been successfully created'
- assert_text 'New name'
+ assert_text 'Acme Ltd'
end
def test_updates_registrar