aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/json_test.rb
diff options
context:
space:
mode:
authorTrung Duc Tran <trung@tdtran.org>2016-07-03 21:27:37 +0200
committerTrung Duc Tran <trung@tdtran.org>2016-09-23 11:38:38 -0700
commit21675fdc441e5d67dd6bc007979523db164a5b2d (patch)
tree8ea4c551d3bfa5252db0ab2081d813727cf08719 /activerecord/test/cases/adapters/postgresql/json_test.rb
parent0bc196518a7369d1279a11faad8aef2442539c82 (diff)
downloadrails-21675fdc441e5d67dd6bc007979523db164a5b2d.tar.gz
rails-21675fdc441e5d67dd6bc007979523db164a5b2d.tar.bz2
rails-21675fdc441e5d67dd6bc007979523db164a5b2d.zip
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
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql/json_test.rb')
-rw-r--r--activerecord/test/cases/adapters/postgresql/json_test.rb16
1 files changed, 16 insertions, 0 deletions
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