Skip to content

Instantly share code, notes, and snippets.

@KelseyDH
Last active August 23, 2019 11:22
Show Gist options
  • Save KelseyDH/2214aa4da127f512e038be5fd3d70a33 to your computer and use it in GitHub Desktop.
Save KelseyDH/2214aa4da127f512e038be5fd3d70a33 to your computer and use it in GitHub Desktop.
# app/domain/null_account.rb
class NullAccount
def id
raise "You are calling id on an account that doesn't exist. Make sure the user you're working with has accounts first before trying to call them."
end
def available_balance
Money.new(available_balance_cents, available_balance_currency)
end
def available_balance_cents
0
end
def available_balance_currency
"CAD"
end
def valid?
false
end
def present?
false
end
def blank?
true
end
def account_key
raise "account_key is being called on a NullAccount!!"
end
def currency
"CAD"
end
def save
raise ActiveRecord::RecordInvalid
end
def update
raise ActiveRecord::RecordInvalid
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment