Skip to content

Commit

Permalink
Merge pull request #14494 from laurocaetano/test_case_for_fk_with_val…
Browse files Browse the repository at this point in the history
…idate_false

Add a test case for save(validate: false) with invalid foreign key.
  • Loading branch information
rafaelfranca committed Mar 27, 2014
2 parents 8a081db + ff8f9f0 commit 73b3afe
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion activerecord/test/cases/adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand Down

0 comments on commit 73b3afe

Please sign in to comment.