mirror of https://github.com/rails/rails
ActiveRecord::Coders::YAMLColumn#dump should raise an error
closes #2737 Conflicts: activerecord/lib/active_record/coders/yaml_column.rb
This commit is contained in:
parent
2e8129e87a
commit
9637de6b47
|
@ -15,7 +15,13 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def dump(obj)
|
||||
YAML.dump(obj) unless obj.nil?
|
||||
return if obj.nil?
|
||||
|
||||
unless obj.is_a?(object_class)
|
||||
raise SerializationTypeMismatch,
|
||||
"Attribute was supposed to be a #{object_class}, but was a #{obj.class}. -- #{obj.inspect}"
|
||||
end
|
||||
YAML.dump obj
|
||||
end
|
||||
|
||||
def load(yaml)
|
||||
|
|
|
@ -9,6 +9,13 @@ module ActiveRecord
|
|||
assert_equal Object, coder.object_class
|
||||
end
|
||||
|
||||
def test_type_mismatch_on_different_classes_on_dump
|
||||
coder = YAMLColumn.new(Array)
|
||||
assert_raises(SerializationTypeMismatch) do
|
||||
coder.dump("a")
|
||||
end
|
||||
end
|
||||
|
||||
def test_type_mismatch_on_different_classes
|
||||
coder = YAMLColumn.new(Array)
|
||||
assert_raises(SerializationTypeMismatch) do
|
||||
|
|
Loading…
Reference in New Issue