internetee-registry/test/models/invoice/cancellable_test.rb
Artur Beljajev a97728c0f3 Refactor and improve invoices
- `runner 'Invoice.cancel_overdue_invoices'` in `schedule.rb` is
changed to `rake 'invoices:cancel_overdue'`.
- `invoices.payment_term` database column is removed and its value is
hardcoded in UI.
- `invoices.paid_at` is removed as unused
- `invoices.due_date` column's type is now `date`.
- `Invoice#invoice_items` renamed to `Invoice#items` and `Invoice`
interface to get a list of items is unified.
- Default date format in UI.
- Default translations are used.
- Tests improved.
- Specs converted to tests and removed along with factories.
- Database structure improved.
2019-03-14 15:39:24 +02:00

69 lines
No EOL
1.8 KiB
Ruby

require 'test_helper'
class CancellableInvoiceTest < ActiveSupport::TestCase
setup do
@invoice = invoices(:one)
end
def test_non_cancelled_scope_returns_non_cancelled_invoices
@invoice.update!(cancelled_at: nil)
assert Invoice.non_cancelled.include?(@invoice), 'Should return cancelled invoice'
end
def test_non_cancelled_scope_does_not_return_cancelled_invoices
@invoice.update!(cancelled_at: '2010-07-05')
assert_not Invoice.non_cancelled.include?(@invoice), 'Should not return cancelled invoice'
end
def test_cancellable_when_unpaid_and_not_yet_cancelled
@invoice.account_activity = nil
@invoice.cancelled_at = nil
assert @invoice.cancellable?
end
def test_not_cancellable_when_paid
assert @invoice.paid?
assert_not @invoice.cancellable?
end
def test_not_cancellable_when_already_cancelled
@invoice.cancelled_at = '2010-07-05'
assert_not @invoice.cancellable?
end
def test_cancels_an_invoice
travel_to Time.zone.parse('2010-07-05 08:00')
@invoice.account_activity = nil
assert @invoice.cancellable?
assert_nil @invoice.cancelled_at
@invoice.cancel
@invoice.reload
assert @invoice.cancelled?
assert_equal Time.zone.parse('2010-07-05 08:00'), @invoice.cancelled_at
end
def test_throws_an_exception_when_trying_to_cancel_already_cancelled_invoice
@invoice.cancelled_at = '2010-07-05'
e = assert_raise do
@invoice.cancel
end
assert_equal 'Invoice cannot be cancelled', e.message
end
def test_not_cancelled
@invoice.cancelled_at = nil
assert @invoice.not_cancelled?
assert_not @invoice.cancelled?
end
def test_cancelled
@invoice.cancelled_at = '2010-07-05'
assert @invoice.cancelled?
assert_not @invoice.not_cancelled?
end
end