Skip to content

Commit 227f736

Browse files
authored
Clear the cached currency keys in Currency.reset! (#1228)
1 parent 015ca05 commit 227f736

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- 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`
56
- 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`
67

78
## 7.1.1

‎lib/money/currency.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def each(&)
217217
def reset!
218218
@@instances = {}
219219
@table = Loader.load_currencies
220+
@stringified_keys = nil
220221
clear_iso_numeric_cache
221222
end
222223

‎spec/money/currency_spec.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,5 +533,16 @@ def to_s
533533
described_class.reset!
534534
expect(described_class.find(:cad).decimal_mark).not_to eq modified_mark
535535
end
536+
537+
it "drops a registered currency it no longer holds" do
538+
described_class.register(iso_code: "ZZZ", subunit_to_unit: 100, priority: 1)
539+
described_class.new("ZZZ")
540+
541+
described_class.reset!
542+
543+
expect(described_class.find(:zzz)).to be_nil
544+
expect { described_class.new("ZZZ") }
545+
.to raise_error(described_class::UnknownCurrency)
546+
end
536547
end
537548
end

0 commit comments

Comments
 (0)