From e8460f8bbe73537897f2162d1cccda943d8c0f4a Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 21 Jan 2015 11:47:11 -0700 Subject: Don't error when invalid json is assigned to a JSON column Keeping with our behavior elsewhere in the system, invalid input is assumed to be `nil`. Fixes #18629. --- activerecord/test/cases/adapters/postgresql/json_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test/cases/adapters') diff --git a/activerecord/test/cases/adapters/postgresql/json_test.rb b/activerecord/test/cases/adapters/postgresql/json_test.rb index 5f6cda1986..f5ae872483 100644 --- a/activerecord/test/cases/adapters/postgresql/json_test.rb +++ b/activerecord/test/cases/adapters/postgresql/json_test.rb @@ -179,6 +179,14 @@ module PostgresqlJSONSharedTestCases assert_equal({ 'one' => 'two', 'three' => 'four' }, json.payload) assert_not json.changed? end + + def test_assigning_invalid_json + json = JsonDataType.new + + json.payload = 'foo' + + assert_nil json.payload + end end class PostgresqlJSONTest < ActiveRecord::TestCase -- cgit v1.2.3