Refactor registrars

#765
This commit is contained in:
Artur Beljajev 2017-11-20 08:10:59 +02:00
parent cee51e1ac5
commit 0f6a47d73d
47 changed files with 644 additions and 640 deletions

View file

@ -0,0 +1,29 @@
require 'test_helper'
class RegistrarCodeTest < ActiveSupport::TestCase
def setup
@registrar = registrars(:bestnames).dup
end
def test_registrar_is_invalid_without_code
@registrar.code = ''
assert @registrar.invalid?
end
def test_special_code_validation
@registrar.code = 'CID'
assert @registrar.invalid?
assert_includes @registrar.errors.full_messages, 'Code is forbidden'
end
def test_cannot_be_changed_once_registrar_is_created
registrar = registrars(:bestnames)
registrar.update!(code: 'new-code')
refute_equal 'new-code', registrar.code
end
def test_normalization
@registrar.code = 'with spaces:and:colon.'
assert_equal 'WITHSPACESANDCOLON.', @registrar.code
end
end

View file

@ -0,0 +1,37 @@
require 'test_helper'
class DeleteRegistrarTest < ActiveSupport::TestCase
def setup
@registrar = registrars(:not_in_use)
end
def test_can_be_deleted_if_not_in_use
assert_difference 'Registrar.count', -1 do
@registrar.destroy
end
end
def test_cannot_be_deleted_if_has_at_least_one_user
users(:api_bestnames).update!(registrar: @registrar)
assert_no_difference 'Registrar.count' do
@registrar.destroy
end
end
def test_cannot_be_deleted_if_has_at_least_one_contact
contacts(:john).update!(registrar: @registrar)
assert_no_difference 'Registrar.count' do
@registrar.destroy
end
end
def test_cannot_be_deleted_if_has_at_least_one_domain
domains(:shop).update!(registrar: @registrar)
assert_no_difference 'Registrar.count' do
@registrar.destroy
end
end
end

View file

@ -9,21 +9,33 @@ class RegistrarTest < ActiveSupport::TestCase
assert @registrar.valid?
end
def test_rejects_absent_accounting_customer_code
@registrar.accounting_customer_code = nil
@registrar.validate
def test_invalid_without_name
@registrar.name = ''
assert @registrar.invalid?
end
def test_invalid_without_reg_no
@registrar.reg_no = ''
assert @registrar.invalid?
end
def test_invalid_without_email
@registrar.email = ''
assert @registrar.invalid?
end
def test_invalid_without_accounting_customer_code
@registrar.accounting_customer_code = ''
assert @registrar.invalid?
end
def test_requires_country_code
@registrar.country_code = nil
@registrar.validate
@registrar.country_code = ''
assert @registrar.invalid?
end
def test_requires_language
@registrar.language = nil
@registrar.validate
def test_invalid_without_language
@registrar.language = ''
assert @registrar.invalid?
end
@ -38,4 +50,13 @@ class RegistrarTest < ActiveSupport::TestCase
registrar = Registrar.new(language: 'de')
assert_equal 'de', registrar.language
end
def test_full_address
assert_equal 'Main Street, New York, New York, 12345', @registrar.address
end
def test_reference_number_generation
@registrar.validate
refute_empty @registrar.reference_no
end
end