diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index a52bdbb4e..de8d099d2 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -77,7 +77,8 @@ module Admin :website, :billing_email, :code, - :test_registrar) + :test_registrar, + :accounting_customer_code) end end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index b906beee3..97ecfa32a 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -16,7 +16,9 @@ class Registrar < ActiveRecord::Base validates :name, :reg_no, :country_code, :email, :code, presence: true validates :name, :reg_no, :reference_no, :code, uniqueness: true + validates :accounting_customer_code, presence: true validate :forbidden_codes + def forbidden_codes return true unless ['CID'].include? code errors.add(:code, I18n.t(:forbidden_code)) diff --git a/app/views/admin/registrars/_form.haml b/app/views/admin/registrars/_form.haml index abf440921..2a80e7357 100644 --- a/app/views/admin/registrars/_form.haml +++ b/app/views/admin/registrars/_form.haml @@ -43,6 +43,12 @@ .col-md-7 = f.email_field :billing_email, class: 'form-control' + .form-group + .col-md-4.control-label + = f.label :accounting_customer_code + .col-md-7 + = f.text_field :accounting_customer_code, class: 'form-control', required: true + .row .col-md-8 .panel.panel-default diff --git a/db/migrate/20171025153841_change_registrar_accounting_customer_code_to_not_null.rb b/db/migrate/20171025153841_change_registrar_accounting_customer_code_to_not_null.rb new file mode 100644 index 000000000..f9d310305 --- /dev/null +++ b/db/migrate/20171025153841_change_registrar_accounting_customer_code_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeRegistrarAccountingCustomerCodeToNotNull < ActiveRecord::Migration + def change + change_column_null :registrars, :accounting_customer_code, false + end +end diff --git a/db/structure.sql b/db/structure.sql index 07b93417b..860a85530 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2473,7 +2473,7 @@ CREATE TABLE registrars ( zip character varying, code character varying, website character varying, - accounting_customer_code character varying, + accounting_customer_code character varying NOT NULL, vat boolean, legacy_id integer, reference_no character varying, @@ -5055,3 +5055,5 @@ INSERT INTO schema_migrations (version) VALUES ('20171025110933'); INSERT INTO schema_migrations (version) VALUES ('20171025113808'); +INSERT INTO schema_migrations (version) VALUES ('20171025153841'); + diff --git a/spec/factories/registrar.rb b/spec/factories/registrar.rb index 426561dda..443a41342 100644 --- a/spec/factories/registrar.rb +++ b/spec/factories/registrar.rb @@ -9,6 +9,7 @@ FactoryGirl.define do zip 'test' email 'test@test.com' country_code 'EE' + accounting_customer_code 'test' factory :registrar_with_unlimited_balance do after :create do |registrar| diff --git a/test/integration/admin/registrars/new_registrar_test.rb b/test/integration/admin/registrars/new_registrar_test.rb index 5c6395673..c0087e5e2 100644 --- a/test/integration/admin/registrars/new_registrar_test.rb +++ b/test/integration/admin/registrars/new_registrar_test.rb @@ -13,6 +13,7 @@ class NewRegistrarTest < ActionDispatch::IntegrationTest fill_in 'registrar[reg_no]', with: '1234567' fill_in 'registrar[email]', with: 'test@test.com' fill_in 'registrar[code]', with: 'test' + fill_in 'registrar[accounting_customer_code]', with: 'test' click_link_or_button 'Create registrar' assert_text 'Registrar has been successfully created' diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb new file mode 100644 index 000000000..f5012b099 --- /dev/null +++ b/test/models/registrar_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class RegistrarTest < ActiveSupport::TestCase + def test_rejects_absent_accounting_customer_code + registrar = Registrar.new(accounting_customer_code: nil) + registrar.validate + assert registrar.errors.added?(:accounting_customer_code, :blank) + end +end