Skip to content

Fix Currency.unregister before the currency table is loaded - #1238

Open
Shaisolaris wants to merge 2 commits into
RubyMoney:mainfrom
Shaisolaris:fix-unregister-before-table-load
Open

Shaisolaris wants to merge 2 commits into
RubyMoney:mainfrom
Shaisolaris:fix-unregister-before-table-load

Conversation

@Shaisolaris

Copy link
Copy Markdown

Money::Currency.unregister reads @table directly, so it raises when it is the first call that touches the currency table, for example in an initializer right after require "money":

require "money"
Money::Currency.unregister(:usd)
# NoMethodError: undefined method `delete' for nil

register and the lookup methods all go through table, which loads the currencies on first use. This change makes unregister use table as well. When a currency is actually removed, it now also drops the cached instance and clears the iso_numeric index, as register does, so later lookups do not see stale entries.

Tests:

  • New .unregister specs in spec/money/currency_spec.rb. The two that start with an unloaded table fail on main with NoMethodError and pass with the change. The iso_numeric one passes on both and is there as a regression guard.
  • rspec: 505 examples, 0 failures locally on Ruby 3.3.
  • I could not run RuboCop locally with the project's plugins.

A CHANGELOG entry is added under Unreleased.

sunny
sunny previously approved these changes Oct 12, 2026

@sunny sunny left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looks good! (Apart from a lint error.)

RSpec/RepeatedExampleGroupDescription flagged the second
describe ".unregister" block.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants