Add a JsonSerializationError class instead of raising SecurityError

This commit is contained in:
Robert Speicher 2017-12-01 11:33:02 -06:00
parent 2f92238a6e
commit 8d0ad36bcf
2 changed files with 6 additions and 4 deletions

View file

@ -5,8 +5,10 @@
module BlocksJsonSerialization
extend ActiveSupport::Concern
def to_json(*args)
raise SecurityError,
JsonSerializationError = Class.new(StandardError)
def to_json(*)
raise JsonSerializationError,
"JSON serialization has been disabled on #{self.class.name}"
end

View file

@ -7,11 +7,11 @@ describe BlocksJsonSerialization do
it 'blocks as_json' do
expect { DummyModel.new.to_json }
.to raise_error(SecurityError, "JSON serialization has been disabled on DummyModel")
.to raise_error(described_class::JsonSerializationError, /DummyModel/)
end
it 'blocks to_json' do
expect { DummyModel.new.to_json }
.to raise_error(SecurityError, "JSON serialization has been disabled on DummyModel")
.to raise_error(described_class::JsonSerializationError, /DummyModel/)
end
end