1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fixed test_foreign_key_violations_are_translated_to_specific_exception to work with Oracle

This commit is contained in:
Raimonds Simanovskis 2009-07-23 20:02:04 +03:00
parent 44a7ef85eb
commit 53be10c5e6

View file

@ -132,7 +132,13 @@ class AdapterTest < ActiveRecord::TestCase
def test_foreign_key_violations_are_translated_to_specific_exception
unless @connection.adapter_name == 'SQLite'
assert_raises(ActiveRecord::InvalidForeignKey) do
@connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
# Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
if @connection.prefetch_primary_key?
id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
@connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
else
@connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
end
end
end
end