Make registrar address required

Closes #1190
This commit is contained in:
Artur Beljajev 2019-05-10 13:30:56 +03:00
parent efb63399b2
commit 04575295ee
7 changed files with 68 additions and 26 deletions

View file

@ -13,8 +13,10 @@ class Registrar < ActiveRecord::Base
delegate :balance, to: :cash_account, allow_nil: true 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 :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 :accounting_customer_code, presence: true
validates :language, presence: true validates :language, presence: true
validates :reference_no, format: Billing::ReferenceNo::REGEXP validates :reference_no, format: Billing::ReferenceNo::REGEXP

View file

@ -9,46 +9,48 @@
<div class="panel-body"> <div class="panel-body">
<div class="form-group"> <div class="form-group">
<div class="col-md-4 control-label"> <div class="col-md-4 control-label">
<%= f.label :street %> <%= f.label :street, for: :registrar_address_street %>
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<%= f.text_field :address_street, class: 'form-control' %> <%= f.text_field :address_street, required: true, class: 'form-control' %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-4 control-label"> <div class="col-md-4 control-label">
<%= f.label :city %> <%= f.label :city, for: :registrar_address_city %>
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<%= f.text_field :address_city, class: 'form-control' %> <%= f.text_field :address_city, required: true, class: 'form-control' %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-4 control-label"> <div class="col-md-4 control-label">
<%= f.label :state %> <%= f.label :state, for: :registrar_address_state %>
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<%= f.text_field :address_state, class: 'form-control' %> <%= f.text_field :address_state, required: true, class: 'form-control' %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-4 control-label"> <div class="col-md-4 control-label">
<%= f.label :zip %> <%= f.label :zip, for: :registrar_address_zip %>
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<%= f.text_field :address_zip, class: 'form-control' %> <%= f.text_field :address_zip, required: true, class: 'form-control' %>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-4 control-label"> <div class="col-md-4 control-label">
<%= f.label :address_country_code, t(:country) %> <%= f.label :country, for: :registrar_address_country_code %>
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<%= f.select :address_country_code, SortedCountry.all_options(f.object.address_country_code), {}, class: 'form-control' %> <%= f.select :address_country_code,
SortedCountry.all_options(f.object.address_country_code), {},
required: true, class: 'form-control' %>
</div> </div>
</div> </div>

View file

@ -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

View file

@ -2189,10 +2189,10 @@ CREATE TABLE public.registrars (
email character varying NOT NULL, email character varying NOT NULL,
billing_email character varying, billing_email character varying,
address_country_code character varying NOT NULL, address_country_code character varying NOT NULL,
address_state character varying, address_state character varying NOT NULL,
address_city character varying, address_city character varying NOT NULL,
address_street character varying, address_street character varying NOT NULL,
address_zip character varying, address_zip character varying NOT NULL,
code character varying NOT NULL, code character varying NOT NULL,
website character varying, website character varying,
accounting_customer_code character varying NOT NULL, 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 ('20190510090240');
INSERT INTO schema_migrations (version) VALUES ('20190510102549');

View file

@ -19,6 +19,10 @@ goodnames:
reg_no: 12345 reg_no: 12345
code: goodnames code: goodnames
email: info@goodnames.test email: info@goodnames.test
address_street: Main Street 1
address_zip: 1234
address_city: NY
address_state: NY State
address_country_code: US address_country_code: US
vat_no: DE123456789 vat_no: DE123456789
accounting_customer_code: goodnames accounting_customer_code: goodnames
@ -30,6 +34,10 @@ not_in_use:
reg_no: any reg_no: any
code: any code: any
email: any@example.com email: any@example.com
address_street: Main Street 1
address_zip: 1234
address_city: NY
address_state: NY State
address_country_code: US address_country_code: US
vat_no: any vat_no: any
accounting_customer_code: any accounting_customer_code: any
@ -41,6 +49,10 @@ invalid:
reg_no: any reg_no: any
code: another code: another
email: any email: any
address_street: Main Street 1
address_zip: 1234
address_city: NY
address_state: NY State
address_country_code: US address_country_code: US
vat_no: any vat_no: any
accounting_customer_code: any accounting_customer_code: any

View file

@ -55,12 +55,6 @@ class RegistrarTest < ActiveSupport::TestCase
assert_equal 'de', registrar.language assert_equal 'de', registrar.language
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
def test_validates_reference_number_format def test_validates_reference_number_format
@registrar.reference_no = '1' @registrar.reference_no = '1'
assert @registrar.invalid? assert @registrar.invalid?
@ -99,6 +93,24 @@ class RegistrarTest < ActiveSupport::TestCase
Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active_setting Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active_setting
end 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 private
def valid_registrar def valid_registrar

View file

@ -9,21 +9,25 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
end end
def test_creates_new_registrar 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 visit admin_registrars_path
click_on 'New registrar' click_on 'New registrar'
fill_in 'Name', with: 'New name' fill_in 'Name', with: 'Acme Ltd'
fill_in 'Reg no', with: '55555555' fill_in 'Reg no', with: '1234'
fill_in 'Contact e-mail', with: 'any@registrar.test' 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' select 'United States', from: 'Country'
fill_in 'Accounting customer code', with: 'test' fill_in 'Accounting customer code', with: 'test'
fill_in 'Code', with: 'test' fill_in 'Code', with: 'test'
click_on 'Create registrar' click_on 'Create registrar'
assert_text 'Registrar has been successfully created' assert_text 'Registrar has been successfully created'
assert_text 'New name' assert_text 'Acme Ltd'
end end
def test_updates_registrar def test_updates_registrar