diff --git a/CHANGELOG.md b/CHANGELOG.md index 074e591272..9f9cba998a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Fix `Money::Currency.reset!` keeping the cached key set, so a currency registered before the reset was still accepted by `Money::Currency.new` and raised `NoMethodError` instead of `UnknownCurrency` - Fix `Money::Bank::VariableExchange#import_rates` parsing `:json` with `JSON.load`, which instantiates any class named by a `json_class` key; it now uses `JSON.parse` ## 7.1.1 diff --git a/lib/money/currency.rb b/lib/money/currency.rb index 1b630fe37a..d4e96be88e 100644 --- a/lib/money/currency.rb +++ b/lib/money/currency.rb @@ -217,6 +217,7 @@ def each(&) def reset! @@instances = {} @table = Loader.load_currencies + @stringified_keys = nil clear_iso_numeric_cache end diff --git a/spec/money/currency_spec.rb b/spec/money/currency_spec.rb index 6252fc2b91..1b809d7f22 100644 --- a/spec/money/currency_spec.rb +++ b/spec/money/currency_spec.rb @@ -533,5 +533,16 @@ def to_s described_class.reset! expect(described_class.find(:cad).decimal_mark).not_to eq modified_mark end + + it "drops a registered currency it no longer holds" do + described_class.register(iso_code: "ZZZ", subunit_to_unit: 100, priority: 1) + described_class.new("ZZZ") + + described_class.reset! + + expect(described_class.find(:zzz)).to be_nil + expect { described_class.new("ZZZ") } + .to raise_error(described_class::UnknownCurrency) + end end end