Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a test case for save(validate:false) with invalid foreign key.

It is supposed to raise ActiveRecord::InvalidForeignKey when the
database has a fk constraint.
  • Loading branch information...
commit ff8f9f09f487cf1965921da74c4b2bffa15a2bb6 1 parent 8a081db
@laurocaetano laurocaetano authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 activerecord/test/cases/adapter_test.rb
View
16 activerecord/test/cases/adapter_test.rb
@@ -146,7 +146,7 @@ def test_uniqueness_violations_are_translated_to_specific_exception
end
def test_foreign_key_violations_are_translated_to_specific_exception
- unless @connection.adapter_name == 'SQLite'
+ unless current_adapter?(:SQLite3Adapter)
assert_raises(ActiveRecord::InvalidForeignKey) do
# Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
if @connection.prefetch_primary_key?
@@ -159,6 +159,20 @@ def test_foreign_key_violations_are_translated_to_specific_exception
end
end
+ def test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false
+ unless current_adapter?(:SQLite3Adapter)
+ klass_has_fk = Class.new(ActiveRecord::Base) do
+ self.table_name = 'fk_test_has_fk'
+ end
+
+ assert_raises(ActiveRecord::InvalidForeignKey) do
+ has_fk = klass_has_fk.new
+ has_fk.fk_id = 1231231231
+ has_fk.save(validate: false)
+ end
+ end
+ end
+
def test_disable_referential_integrity
assert_nothing_raised do
@connection.disable_referential_integrity do
Please sign in to comment.
Something went wrong with that request. Please try again.