mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 23:54:44 +02:00
parent
7acd41595c
commit
c129598d2b
3 changed files with 12 additions and 15 deletions
|
@ -28,8 +28,9 @@ class Invoice < ActiveRecord::Base
|
|||
validates :billing_email, email_format: { message: :invalid }, allow_blank: true
|
||||
|
||||
validates :due_date, :currency, :seller_name,
|
||||
:seller_iban, :buyer_name, :invoice_items, :vat_rate, presence: true
|
||||
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 99 }, allow_nil: true
|
||||
:seller_iban, :buyer_name, :invoice_items, presence: true
|
||||
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 },
|
||||
allow_nil: true
|
||||
|
||||
before_create :set_invoice_number, :check_vat
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class Registrar < ActiveRecord::Base
|
|||
validates :vat_rate, presence: true, if: :vat_rate_required?
|
||||
validates :vat_rate, absence: true, if: :local_vat_payer?
|
||||
validates :vat_rate, absence: true, if: 'foreign_vat_payer? && vat_no?'
|
||||
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 99.9 },
|
||||
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 },
|
||||
allow_nil: true
|
||||
|
||||
validate :forbid_special_code
|
||||
|
|
|
@ -9,26 +9,22 @@ class InvoiceTest < ActiveSupport::TestCase
|
|||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_vat_rate
|
||||
def test_valid_without_vat_rate
|
||||
@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
|
||||
def test_vat_rate_validation
|
||||
@invoice.vat_rate = -1
|
||||
@invoice.validate
|
||||
assert @invoice.invalid?
|
||||
end
|
||||
|
||||
def test_rejects_vat_rate_greater_than_max
|
||||
@invoice.vat_rate = 1
|
||||
assert @invoice.valid?
|
||||
|
||||
@invoice.vat_rate = 99.9
|
||||
assert @invoice.valid?
|
||||
|
||||
@invoice.vat_rate = 100
|
||||
@invoice.validate
|
||||
assert @invoice.invalid?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue