mirror of
https://github.com/meineerde/rackstash.git
synced 2025-12-19 15:01:12 +00:00
Freeze the raw object along the wrapper for all fields
This commit is contained in:
parent
57f1197299
commit
fa174bba9d
@ -29,6 +29,16 @@ module Rackstash
|
||||
end
|
||||
alias eql? ==
|
||||
|
||||
# Prevents further modifications to `self`. A `RuntimeError` will be
|
||||
# raised if modification is attempted. There is no way to unfreeze a
|
||||
# frozen object.
|
||||
#
|
||||
# @return [self]
|
||||
def freeze
|
||||
raw.freeze
|
||||
super
|
||||
end
|
||||
|
||||
# Compute a hash-code for this collection.
|
||||
#
|
||||
# Two collections with the same raw content will have the same hash code
|
||||
|
||||
@ -92,6 +92,20 @@ describe Rackstash::Fields::AbstractCollection do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#freeze' do
|
||||
it 'freezes the collection and the raw data' do
|
||||
raw = [123, 'foo']
|
||||
collection.send(:raw=, raw)
|
||||
|
||||
expect(raw).not_to be_frozen
|
||||
|
||||
collection.freeze
|
||||
|
||||
expect(collection).to be_frozen
|
||||
expect(raw).to be_frozen
|
||||
end
|
||||
end
|
||||
|
||||
describe '#hash' do
|
||||
it 'returns the same hash for the same raw content' do
|
||||
collection.send(:raw=, [123, 'foo'])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user