Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set default_currency to nil #697

Open
sirwolfgang opened this issue Apr 24, 2024 · 1 comment
Open

Unable to set default_currency to nil #697

sirwolfgang opened this issue Apr 24, 2024 · 1 comment

Comments

@sirwolfgang
Copy link

sirwolfgang commented Apr 24, 2024

Noticed an issue where in our system an edge case would cause the default currency of USD to get applied. Generally we want to be strict, and not risk a default value. When I attempted to set the default_currency to nil this started to error.

Based on this message I found while debugging [WARNING] The default currency will change from 'USD' to 'nil' in the next major release., it doesn't sound like it's intended to prevent the removal of a default.

I've prepared two PRs that make the required adjustments to allow nil to be used as a default value, that triggers NoCurrency error.

This will allow strictly defined systems to operate without risk of unexpected currencies.

@mediafinger
Copy link

We would love to see this included as well. A default currency is a hard no for our use case. And just after installing the gem and setting up an object, I already stumbled about an issue which shows me why having a default could cause big problems.

class Account < ApplicationRecord
  normalizes :balance_currency, with: ->(currency) { currency.strip.upcase }

  validates :balance, presence: true

  # to provide a Money object for the balance attribute
  monetize :balance, as: :money
end

$> acc = Account.last

  Account Load ...
  {
             :balance => 50,
    :balance_currency => "HUF",
  }

$> acc.money

{
           :cents => 50,
    :currency_iso => "EUR"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants