DEFAULTS: &DEFAULTS
payment_trail: $LABEL
identifier: $LABEL_stripe_key
amount_cents: <%= AMOUNT_CENTS[:one_h] %>
paid: false
status: <%= Charge::STATUSES[0] %>
state: <%= Charge::STATES[0] %>
created_at: now # special `now` or can use <%= 1.week.from_now %>
currency: usd # refers to currencies(:usd)
invoice:
<<: *DEFAULTS
paid:
<<: *DEFAULTS
paid: true
require 'test_helper'
class ChargeTest < ActiveSupport::TestCase
should validate_presence_of(:identifier)
should validate_uniqueness_of(:identifier)
should validate_inclusion_of(:state).in_array(Charge::STATES)
should validate_inclusion_of(:status).in_array(Charge::STATUSES)
should validate_presence_of(:amount_cents)
validate_numericality_of(:amount_cents).only_integer.is_greater_than_or_equal_to(0)
test 'scopes' do
assert_includes Charge.paid, charges(:paid)
end
test 'validate #custom_validator_method' do
item = items(:item)
assert item.valid?
item.user = item.invitee
refute item.valid?
refute errors.keys.include?(:xyz)
assert.errors.keys.include?(:abc)
assert_equal item.errors.messages, base: ["Sorry, but you can't accept your own invite"]
end
end