test/validator_test.rb in polish_invoicer-0.0.5 vs test/validator_test.rb in polish_invoicer-0.0.6
- old
+ new
@@ -1,23 +1,23 @@
require 'test_helper'
module PolishInvoicer
- class ValidatorTest < MiniTest::Unit::TestCase
+ class ValidatorTest < Minitest::Test
require 'ostruct'
def setup
@invoice = OpenStruct.new
end
- def check_error(field, value=nil)
+ 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)
+ def check_ok(field, value = nil)
@invoice.send("#{field}=", value)
v = Validator.new(@invoice)
v.valid?
assert_nil v.errors[field]
end
@@ -127,50 +127,29 @@
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)
+ 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?
+ v = Validator.new(@invoice)
+ v.valid?
assert_nil v.errors[:create_date], msg
end
- def check_dates_error(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 v.errors[:create_date], msg
- end
-
- # data wystawienia max 30 dni przed wykonaniem usługi
- def test_create_and_trade_date_correlation_before_trade
- check_dates_ok('2014-01-01', '2014-01-01', 'B1')
- check_dates_ok('2014-01-01', '2014-01-31', 'B2')
- check_dates_error('2014-01-01', '2014-02-01', 'B3')
- check_dates_ok('2014-01-02', '2014-02-01', 'B4')
- end
-
- # data wystawienie max 15 dnia następnego miesiąca po wykonaniu usługi
- def test_create_and_trade_date_correlation_after_trade
- check_dates_ok('2014-02-15', '2014-01-01', 'A1')
- check_dates_error('2014-02-16', '2014-01-01', 'A2')
- check_dates_error('2014-02-16', '2014-01-02', 'A3')
- check_dates_error('2014-02-16', '2014-01-31', 'A4')
- check_dates_ok('2014-02-15', '2014-01-31', 'A5')
- check_dates_ok('2014-03-15', '2014-02-15', 'A6')
- end
-
def test_no_vat_reason_presence
@invoice.vat = 23
- v = Validator.new(@invoice); v.valid?
+ v = Validator.new(@invoice)
+ v.valid?
assert_nil v.errors[:no_vat_reason]
@invoice.vat = -1
- v = Validator.new(@invoice); v.valid?
+ v = Validator.new(@invoice)
+ v.valid?
assert v.errors[:no_vat_reason]
@invoice.no_vat_reason = 'reason'
- v = Validator.new(@invoice); v.valid?
+ v = Validator.new(@invoice)
+ v.valid?
assert_nil v.errors[:no_vat_reason]
end
end
end