test/validator_test.rb in polish_invoicer-0.0.17 vs test/validator_test.rb in polish_invoicer-0.0.18
- old
+ new
@@ -6,24 +6,10 @@
def setup
@invoice = OpenStruct.new
end
- def check_error(field, value = nil)
- @invoice.send("#{field}=", value)
- v = Validator.new(@invoice)
- v.valid?
- assert v.errors[field]
- end
-
- def check_ok(field, value = nil)
- @invoice.send("#{field}=", value)
- v = Validator.new(@invoice)
- v.valid?
- assert_nil v.errors[field]
- end
-
def test_number_validation
check_error(:number)
check_ok(:number, '1/2014')
end
@@ -108,11 +94,11 @@
check_error(:proforma, 'test')
check_ok(:proforma, true)
check_ok(:proforma, false)
end
- def test_proforma_could_not_be_paid
+ def test_proforma_not_paid
@invoice.paid = true
@invoice.proforma = true
v = Validator.new(@invoice)
v.valid?
assert v.errors[:paid]
@@ -120,25 +106,17 @@
v = Validator.new(@invoice)
v.valid?
assert_nil v.errors[:paid]
end
- def test_seller_and_buyer_nip_presence
+ def test_nip_presence
check_error(:seller_nip)
check_ok(:buyer_nip)
check_ok(:seller_nip, '123')
check_ok(:buyer_nip, '123')
end
- def check_dates_ok(create_date, trade_date, msg = nil)
- @invoice.create_date = Date.parse(create_date)
- @invoice.trade_date = Date.parse(trade_date)
- v = Validator.new(@invoice)
- v.valid?
- assert_nil v.errors[:create_date], msg
- end
-
def test_no_vat_reason_presence
@invoice.vat = 23
v = Validator.new(@invoice)
v.valid?
assert_nil v.errors[:no_vat_reason]
@@ -148,8 +126,36 @@
assert v.errors[:no_vat_reason]
@invoice.no_vat_reason = 'reason'
v = Validator.new(@invoice)
v.valid?
assert_nil v.errors[:no_vat_reason]
+ end
+
+ def test_create_and_payment_date
+ @invoice.create_date = Date.parse('2018-04-10')
+ @invoice.payment_date = Date.parse('2018-04-01')
+ v = Validator.new(@invoice)
+ v.valid?
+ assert v.errors[:payment_date]
+ @invoice.payment_date = Date.parse('2018-04-17')
+ v = Validator.new(@invoice)
+ v.valid?
+ assert_nil v.errors[:payment_date]
+ end
+
+ private
+
+ def check_error(field, value = nil)
+ @invoice.send("#{field}=", value)
+ v = Validator.new(@invoice)
+ v.valid?
+ assert v.errors[field]
+ end
+
+ def check_ok(field, value = nil)
+ @invoice.send("#{field}=", value)
+ v = Validator.new(@invoice)
+ v.valid?
+ assert_nil v.errors[field]
end
end
end