Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ This project adheres to [Semantic Versioning].
Changes:
- Drop support for Rails < 7.0.

Fix:
- Make `RateStore` marshalable so a bank using it can be marshaled.

## v1.4.1

Fix:
Expand Down
10 changes: 10 additions & 0 deletions lib/active_currency/rate_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@
module ActiveCurrency
class RateStore < DatabaseStore
include CacheableStore

# Money::Bank::VariableExchange#marshal_load rebuilds the store with
# `store_info.shift.new(*store_info)`, so a store's #marshal_dump must
# return `[StoreClass, *constructor_args]`. RateStore takes no arguments,
# so returning `[self.class]` lets a bank backed by this store be
# marshaled -- for example when the configured default bank is cached
# under a Marshal-based cache/serializer.
def marshal_dump
[self.class]
end
end
end
14 changes: 14 additions & 0 deletions spec/lib/active_currency/rate_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,18 @@
end
end
end

describe "#marshal_dump" do
it "dumps the class so the store can be rebuilt on load" do
expect(store.marshal_dump).to eq([described_class])
end

it "lets a bank backed by the store round-trip through Marshal" do
bank = Money::Bank::VariableExchange.new(store)

loaded = Marshal.load(Marshal.dump(bank))

expect(loaded.store).to be_a(described_class)
end
end
end