aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYasuo Honda <yasuo.honda@gmail.com>2017-08-22 18:49:50 +0000
committerYasuo Honda <yasuo.honda@gmail.com>2017-08-22 19:32:45 +0000
commit43c6a683f2caad47b87c5d6a263865cd0db6174f (patch)
tree4b737992738b3cd0f59f4aaf22459db3b753be0b
parent665ac7cff212d010a3573f85cea895666fbaad15 (diff)
downloadrails-43c6a683f2caad47b87c5d6a263865cd0db6174f.tar.gz
rails-43c6a683f2caad47b87c5d6a263865cd0db6174f.tar.bz2
rails-43c6a683f2caad47b87c5d6a263865cd0db6174f.zip
Load both `:authors` and `:author_addresses` to keep data integrity
`:authors` has a foreign key to `:author_addresses`. If only `:authors` fixture loaded into the database which supports foreign key and checks the existing data when enabling foreien keys like Oracle, it raises the following error `ORA-02298: cannot validate (ARUNIT.FK_RAILS_94423A17A3) - parent keys not found` It is because there is no parent data exists in `author_addresses` table. Here are how other database with foreign key support works: - MySQL does not check the existing data when enabling foreign key by `foreign_key_checks=1` https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_foreign_key_checks > Setting foreign_key_checks to 1 does not trigger a scan of the existing table data. Therefore, rows added to the table while foreign_key_checks=0 will not be verified for consistency. - PostgreSQL database itself has a feature to check existing data when enabling foreign key and discussed at #27636, which is reverted.
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb2
-rw-r--r--activerecord/test/cases/associations/inverse_associations_test.rb2
-rw-r--r--activerecord/test/cases/enum_test.rb2
-rw-r--r--activerecord/test/cases/relation/or_test.rb2
4 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index fdb98d84e0..2a9ebd19ed 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -15,7 +15,7 @@ require "models/post"
class HasOneAssociationsTest < ActiveRecord::TestCase
self.use_transactional_tests = false unless supports_savepoints?
- fixtures :accounts, :companies, :developers, :projects, :developers_projects, :ships, :pirates, :authors
+ fixtures :accounts, :companies, :developers, :projects, :developers_projects, :ships, :pirates, :authors, :author_addresses
def setup
Account.destroyed_account_ids.clear
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb
index 86a034b429..e13cf93dcf 100644
--- a/activerecord/test/cases/associations/inverse_associations_test.rb
+++ b/activerecord/test/cases/associations/inverse_associations_test.rb
@@ -283,7 +283,7 @@ class InverseHasOneTests < ActiveRecord::TestCase
end
class InverseHasManyTests < ActiveRecord::TestCase
- fixtures :men, :interests, :posts, :authors
+ fixtures :men, :interests, :posts, :authors, :author_addresses
def test_parent_instance_should_be_shared_with_every_child_on_find
m = men(:gordon)
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index 68a1190d68..78cb89ccc5 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -5,7 +5,7 @@ require "models/author"
require "models/book"
class EnumTest < ActiveRecord::TestCase
- fixtures :books, :authors
+ fixtures :books, :authors, :author_addresses
setup do
@book = books(:awdr)
diff --git a/activerecord/test/cases/relation/or_test.rb b/activerecord/test/cases/relation/or_test.rb
index b01801b41f..955e9fc9ce 100644
--- a/activerecord/test/cases/relation/or_test.rb
+++ b/activerecord/test/cases/relation/or_test.rb
@@ -8,7 +8,7 @@ require "models/post"
module ActiveRecord
class OrTest < ActiveRecord::TestCase
fixtures :posts
- fixtures :authors
+ fixtures :authors, :author_addresses
def test_or_with_relation
expected = Post.where("id = 1 or id = 2").to_a