mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
Merge branch 'registry-765' into registry-623
# Conflicts: # app/models/registrar.rb # config/locales/en.yml # spec/models/registrar_spec.rb # test/models/registrar_test.rb
This commit is contained in:
commit
4f51f6c736
35 changed files with 464 additions and 482 deletions
29
test/models/registrar/code_test.rb
Normal file
29
test/models/registrar/code_test.rb
Normal 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
|
37
test/models/registrar/delete_test.rb
Normal file
37
test/models/registrar/delete_test.rb
Normal 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
|
|
@ -9,9 +9,23 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
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_rejects_absent_accounting_customer_code
|
||||
@registrar.accounting_customer_code = nil
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
|
@ -20,9 +34,8 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
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,65 +51,12 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
assert_equal 'de', registrar.language
|
||||
end
|
||||
|
||||
def test_rejects_vat_no_when_local_vat_payer
|
||||
Registry.instance.stub(:legal_address_country, Country.new('US')) do
|
||||
@registrar.vat_no = 'US1'
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
def test_full_address
|
||||
assert_equal 'Main Street, New York, New York, 12345', @registrar.address
|
||||
end
|
||||
|
||||
def test_rejects_vat_rate_when_local_vat_payer
|
||||
Registry.instance.stub(:legal_address_country, Country.new('US')) do
|
||||
@registrar.vat_rate = 20
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_rejects_negative_vat_rate
|
||||
@registrar.vat_rate = -1
|
||||
def test_reference_number_generation
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_rejects_vat_rate_greater_than_max
|
||||
@registrar.vat_rate = 100
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_requires_vat_rate_when_foreign_vat_payer_without_number
|
||||
Registry.instance.stub(:legal_address_country, Country.new('GB')) do
|
||||
@registrar.vat_no = nil
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_rejects_vat_rate_when_foreign_vat_payer_with_number
|
||||
Registry.instance.stub(:legal_address_country, Country.new('GB')) do
|
||||
@registrar.vat_no = 'US1'
|
||||
@registrar.vat_rate = 1
|
||||
@registrar.validate
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_serializes_and_deserializes_vat_rate
|
||||
valid_attributes = registrars(:bestnames).attributes.except('id').merge({ name: 'uniq1',
|
||||
reg_no: 'uniq1',
|
||||
code: 'uniq1',
|
||||
country_code: 'GB' })
|
||||
registrar = Registrar.new(valid_attributes)
|
||||
registrar.vat_rate = 55
|
||||
registrar.save!
|
||||
registrar.reload
|
||||
assert_equal 55, registrar.vat_rate
|
||||
end
|
||||
|
||||
def test_treats_empty_vat_rate_as_absent
|
||||
@registrar.vat_rate = ''
|
||||
assert_nil @registrar.vat_rate
|
||||
refute_empty @registrar.reference_no
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue