aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYasuo Honda <yasuo.honda@gmail.com>2017-12-06 13:09:51 +0000
committerRyuta Kamizono <kamipo@gmail.com>2017-12-07 04:01:21 +0900
commitb34838cbe29434212eb81ca1e31bb0ab0765e32a (patch)
tree19131675d0ab69d3160129354a288e99b6aceba9
parentd721344280346f67c7d2dbffa9eaf9341e73673d (diff)
downloadrails-b34838cbe29434212eb81ca1e31bb0ab0765e32a.tar.gz
rails-b34838cbe29434212eb81ca1e31bb0ab0765e32a.tar.bz2
rails-b34838cbe29434212eb81ca1e31bb0ab0765e32a.zip
Address `ActiveRecord::NotNullViolation: OCIError: ORA-01400` for Oracle database which requires primary key value mentioned in insert statement explicitly.
-rw-r--r--activerecord/test/cases/json_shared_test_cases.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/activerecord/test/cases/json_shared_test_cases.rb b/activerecord/test/cases/json_shared_test_cases.rb
index 012aaffde1..b0c0f2c283 100644
--- a/activerecord/test/cases/json_shared_test_cases.rb
+++ b/activerecord/test/cases/json_shared_test_cases.rb
@@ -66,26 +66,26 @@ module JSONSharedTestCases
end
def test_rewrite
- @connection.execute(%q|insert into json_data_type (payload) VALUES ('{"k":"v"}')|)
+ @connection.execute(insert_statement_per_database('{"k":"v"}'))
x = klass.first
x.payload = { '"a\'' => "b" }
assert x.save!
end
def test_select
- @connection.execute(%q|insert into json_data_type (payload) VALUES ('{"k":"v"}')|)
+ @connection.execute(insert_statement_per_database('{"k":"v"}'))
x = klass.first
assert_equal({ "k" => "v" }, x.payload)
end
def test_select_multikey
- @connection.execute(%q|insert into json_data_type (payload) VALUES ('{"k1":"v1", "k2":"v2", "k3":[1,2,3]}')|)
+ @connection.execute(insert_statement_per_database('{"k1":"v1", "k2":"v2", "k3":[1,2,3]}'))
x = klass.first
assert_equal({ "k1" => "v1", "k2" => "v2", "k3" => [1, 2, 3] }, x.payload)
end
def test_null_json
- @connection.execute("insert into json_data_type (payload) VALUES(null)")
+ @connection.execute(insert_statement_per_database("null"))
x = klass.first
assert_nil(x.payload)
end
@@ -107,13 +107,13 @@ module JSONSharedTestCases
end
def test_select_array_json_value
- @connection.execute(%q|insert into json_data_type (payload) VALUES ('["v0",{"k1":"v1"}]')|)
+ @connection.execute(insert_statement_per_database('["v0",{"k1":"v1"}]'))
x = klass.first
assert_equal(["v0", { "k1" => "v1" }], x.payload)
end
def test_rewrite_array_json_value
- @connection.execute(%q|insert into json_data_type (payload) VALUES ('["v0",{"k1":"v1"}]')|)
+ @connection.execute(insert_statement_per_database('["v0",{"k1":"v1"}]'))
x = klass.first
x.payload = ["v1", { "k2" => "v2" }, "v3"]
assert x.save!
@@ -258,4 +258,12 @@ module JSONSharedTestCases
native_type = ActiveRecord::Base.connection.native_database_types[type][:name]
assert_match %r(\A#{native_type}\b), sql_type
end
+
+ def insert_statement_per_database(values)
+ if current_adapter?(:OracleAdapter)
+ "insert into json_data_type (id, payload) VALUES (json_data_type_seq.nextval, '#{values}')"
+ else
+ "insert into json_data_type (payload) VALUES ('#{values}')"
+ end
+ end
end