test/models/billing/account_test.rb in billing-0.0.3 vs test/models/billing/account_test.rb in billing-0.0.4a
- old
+ new
@@ -7,23 +7,23 @@
@account.save! # force summary calculation
end
test "charge" do
charge = @account.charge 3
- assert charge.persisted?
+ assert charge.try(:persisted?)
assert_equal '13 USD'.to_money, @account.total # (1 + 3) + 100% + $1
end
test "discount" do
- discount = @account.modify(-1.00)
- assert discount.persisted?
+ discount = @account.modify(-1.00, charge: billing_charges(:two))
+ assert discount.try(:persisted?)
assert_equal '6 USD'.to_money, @account.total
end
test "surcharge" do
- surcharge = @account.modify(1.00)
- assert surcharge.persisted?
+ surcharge = @account.modify(1.00, charge: billing_charges(:two))
+ assert surcharge.try(:persisted?)
assert_equal '8 USD'.to_money, @account.total
end
test "pay" do
payment = @account.pay billing_payment_types(:one)
@@ -32,12 +32,25 @@
end
test "validate positive total" do
assert @account.save
@account.modify(-500)
- assert @account.errors[:total]
+ assert @account.errors.messages[:total]
assert_raise ActiveRecord::RecordInvalid do
@account.save!
end
+ end
+
+ test "account with payments should have origin" do
+ assert @account.origin
+ assert @account.payments.any?
+ @account.origin = nil
+ assert_equal false, @account.save
+ assert @account.errors.messages[:origin]
+ end
+
+ test "autofin" do
+ assert @account.pay billing_payment_types(:one)
+ assert @account.finalized_at
end
end
end