From 21675fdc441e5d67dd6bc007979523db164a5b2d Mon Sep 17 00:00:00 2001 From: Trung Duc Tran Date: Sun, 3 Jul 2016 21:27:37 +0200 Subject: Serialize JSON attribute value nil as SQL NULL, not JSON 'null' Test: JSON attribute value nil can be used in where(attr: nil) Add changelog entry --- activerecord/test/cases/adapters/postgresql/json_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activerecord/test/cases/adapters/postgresql/json_test.rb') diff --git a/activerecord/test/cases/adapters/postgresql/json_test.rb b/activerecord/test/cases/adapters/postgresql/json_test.rb index c74f70f251..273b2c1c7b 100644 --- a/activerecord/test/cases/adapters/postgresql/json_test.rb +++ b/activerecord/test/cases/adapters/postgresql/json_test.rb @@ -113,6 +113,22 @@ module PostgresqlJSONSharedTestCases assert_equal(nil, x.payload) end + def test_select_nil_json_after_create + json = JsonDataType.create(payload: nil) + x = JsonDataType.where(payload:nil).first + assert_equal(json, x) + end + + def test_select_nil_json_after_update + json = JsonDataType.create(payload: "foo") + x = JsonDataType.where(payload:nil).first + assert_equal(nil, x) + + json.update_attributes payload: nil + x = JsonDataType.where(payload:nil).first + assert_equal(json.reload, x) + end + def test_select_array_json_value @connection.execute %q|insert into json_data_type (payload) VALUES ('["v0",{"k1":"v1"}]')| x = JsonDataType.first -- cgit v1.2.3