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

Can't validate money/currency presence in model #260

Open
rporrasluc opened this issue Feb 16, 2023 · 1 comment
Open

Can't validate money/currency presence in model #260

rporrasluc opened this issue Feb 16, 2023 · 1 comment
Labels

Comments

@rporrasluc
Copy link

Unless legacy_default_currency! is used, models can't be validated if currency is missing. Calling valid? on the method will read all attributes and so it will end up calling Helpers.value_to_currency(currency) with nil currency which will raise in absence of defaults.

Only if both value and currency are null (and coerce_null is false), the validation can be performed as read_money_attribute will return early if value is nil.

@csalvato
Copy link
Contributor

csalvato commented Feb 16, 2023

Note, this means that, by default, an invalid record where currency is nil, calling record.validate will result in a Money::Currency::UnknownCurrency error instead of ActiveRecord::RecordInvalid error, which is a break in convention.

@elfassy elfassy added the bug label Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants