Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ActiveRecord::Coders::YAMLColumn#dump should raise an error

closes #2737

Conflicts:

	activerecord/lib/active_record/coders/yaml_column.rb
  • Loading branch information...
commit 9637de6b472b05a09fe6d28d973b4729e3ea4615 1 parent 2e8129e
@gutenye gutenye authored committed
View
8 activerecord/lib/active_record/coders/yaml_column.rb
@@ -15,7 +15,13 @@ def initialize(object_class = Object)
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)
View
7 activerecord/test/cases/coders/yaml_column_test.rb
@@ -9,6 +9,13 @@ def test_initialize_takes_class
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

0 comments on commit 9637de6

Please sign in to comment.
Something went wrong with that request. Please try again.