diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-03-26 22:16:02 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-03-26 22:16:02 -0500 |
commit | 73b3afe58f3a25efa808a2bd1e5ca9f4bbe5c94a (patch) | |
tree | b6cbbcee010dcfea59452c8ebbf2a5ba74dcb9b7 /activerecord/test | |
parent | 8a081db3575431380592ce2b8f0045e627a4e664 (diff) | |
parent | ff8f9f09f487cf1965921da74c4b2bffa15a2bb6 (diff) | |
download | rails-73b3afe58f3a25efa808a2bd1e5ca9f4bbe5c94a.tar.gz rails-73b3afe58f3a25efa808a2bd1e5ca9f4bbe5c94a.tar.bz2 rails-73b3afe58f3a25efa808a2bd1e5ca9f4bbe5c94a.zip |
Merge pull request #14494 from laurocaetano/test_case_for_fk_with_validate_false
Add a test case for save(validate: false) with invalid foreign key.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapter_test.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 696b859b36..ed4d0d503d 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -146,7 +146,7 @@ module ActiveRecord 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 @@ module ActiveRecord 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 |