mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 23:42:04 +02:00
parent
c47ca77ca6
commit
6a01226138
8 changed files with 126 additions and 20 deletions
|
@ -1,9 +1,34 @@
|
|||
require 'test_helper'
|
||||
|
||||
class InvoiceTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@invoice = invoices(:valid)
|
||||
end
|
||||
|
||||
def test_valid
|
||||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_vat_rate
|
||||
invoice = Invoice.new(vat_rate: nil)
|
||||
invoice.validate
|
||||
assert invoice.errors.added?(:vat_rate, :blank)
|
||||
@invoice.vat_rate = nil
|
||||
assert @invoice.invalid?
|
||||
end
|
||||
|
||||
def test_allows_absent_vat_rate
|
||||
@invoice.vat_rate = nil
|
||||
@invoice.validate
|
||||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_rejects_negative_vat_rate
|
||||
@invoice.vat_rate = -1
|
||||
@invoice.validate
|
||||
assert @invoice.invalid?
|
||||
end
|
||||
|
||||
def test_rejects_vat_rate_greater_than_max
|
||||
@invoice.vat_rate = 100
|
||||
@invoice.validate
|
||||
assert @invoice.invalid?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
assert_equal 'de', registrar.language
|
||||
end
|
||||
|
||||
def test_rejects_vat_number_when_local_vat_payer
|
||||
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
|
||||
|
@ -67,11 +67,6 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_converts_integer_vat_rate_to_fractional
|
||||
@registrar = registrars(:foreign_vat_payer_with_rate)
|
||||
assert_equal 20, @registrar.vat_rate
|
||||
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
|
||||
|
@ -88,4 +83,21 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
assert @registrar.invalid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_serializes_and_deserializes_vat_rate
|
||||
valid_attributes = registrars(:valid).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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue