Namespace
- CLASS ActiveRecord::Migration::ForeignKeyTest::Astronaut
- CLASS ActiveRecord::Migration::ForeignKeyTest::CreateCitiesAndHousesMigration
- CLASS ActiveRecord::Migration::ForeignKeyTest::CreateSchoolsAndClassesMigration
- CLASS ActiveRecord::Migration::ForeignKeyTest::Rocket
Methods
- T
-
- test_add_foreign_key_inferes_column,
- test_add_foreign_key_is_reversible,
- test_add_foreign_key_with_column,
- test_add_foreign_key_with_non_standard_primary_key,
- test_add_foreign_key_with_on_update,
- test_add_foreign_key_with_prefix,
- test_add_foreign_key_with_suffix,
- test_add_on_delete_cascade_foreign_key,
- test_add_on_delete_nullify_foreign_key,
- test_add_on_delete_restrict_foreign_key,
- test_foreign_keys,
- test_on_update_and_on_delete_raises_with_invalid_values,
- test_remove_foreign_key_by_column,
- test_remove_foreign_key_by_name,
- test_remove_foreign_key_by_symbol_column,
- test_remove_foreign_key_inferes_column,
- test_remove_foreign_non_existing_foreign_key_raises,
- test_schema_dumping,
- test_schema_dumping_on_delete_and_on_update_options,
- test_schema_dumping_with_options
Included Modules
Instance Public methods
test_add_foreign_key_inferes_column()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 49 def test_add_foreign_key_inferes_column @connection.add_foreign_key :astronauts, :rockets foreign_keys = @connection.foreign_keys("astronauts") assert_equal 1, foreign_keys.size fk = foreign_keys.first assert_equal "astronauts", fk.from_table assert_equal "rockets", fk.to_table assert_equal "rocket_id", fk.column assert_equal "id", fk.primary_key assert_equal("fk_rails_78146ddd2e", fk.name) end
test_add_foreign_key_is_reversible()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 216 def test_add_foreign_key_is_reversible migration = CreateCitiesAndHousesMigration.new silence_stream($stdout) { migration.migrate(:up) } assert_equal 1, @connection.foreign_keys("houses").size ensure silence_stream($stdout) { migration.migrate(:down) } end
test_add_foreign_key_with_column()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 63 def test_add_foreign_key_with_column @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id" foreign_keys = @connection.foreign_keys("astronauts") assert_equal 1, foreign_keys.size fk = foreign_keys.first assert_equal "astronauts", fk.from_table assert_equal "rockets", fk.to_table assert_equal "rocket_id", fk.column assert_equal "id", fk.primary_key assert_equal("fk_rails_78146ddd2e", fk.name) end
test_add_foreign_key_with_non_standard_primary_key()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 77 def test_add_foreign_key_with_non_standard_primary_key with_example_table @connection, "space_shuttles", "pk integer PRIMARY KEY" do @connection.add_foreign_key(:astronauts, :space_shuttles, column: "rocket_id", primary_key: "pk", name: "custom_pk") foreign_keys = @connection.foreign_keys("astronauts") assert_equal 1, foreign_keys.size fk = foreign_keys.first assert_equal "astronauts", fk.from_table assert_equal "space_shuttles", fk.to_table assert_equal "pk", fk.primary_key @connection.remove_foreign_key :astronauts, name: "custom_pk" end end
test_add_foreign_key_with_on_update()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 139 def test_add_foreign_key_with_on_update @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", on_update: :nullify foreign_keys = @connection.foreign_keys("astronauts") assert_equal 1, foreign_keys.size fk = foreign_keys.first assert_equal :nullify, fk.on_update end
test_add_foreign_key_with_prefix()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 235 def test_add_foreign_key_with_prefix ActiveRecord::Base.table_name_prefix = 'p_' migration = CreateSchoolsAndClassesMigration.new silence_stream($stdout) { migration.migrate(:up) } assert_equal 1, @connection.foreign_keys("p_classes").size ensure silence_stream($stdout) { migration.migrate(:down) } ActiveRecord::Base.table_name_prefix = nil end
test_add_foreign_key_with_suffix()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 245 def test_add_foreign_key_with_suffix ActiveRecord::Base.table_name_suffix = '_s' migration = CreateSchoolsAndClassesMigration.new silence_stream($stdout) { migration.migrate(:up) } assert_equal 1, @connection.foreign_keys("classes_s").size ensure silence_stream($stdout) { migration.migrate(:down) } ActiveRecord::Base.table_name_suffix = nil end
test_add_on_delete_cascade_foreign_key()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 109 def test_add_on_delete_cascade_foreign_key @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", on_delete: :cascade foreign_keys = @connection.foreign_keys("astronauts") assert_equal 1, foreign_keys.size fk = foreign_keys.first assert_equal :cascade, fk.on_delete end
test_add_on_delete_nullify_foreign_key()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 119 def test_add_on_delete_nullify_foreign_key @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", on_delete: :nullify foreign_keys = @connection.foreign_keys("astronauts") assert_equal 1, foreign_keys.size fk = foreign_keys.first assert_equal :nullify, fk.on_delete end
test_add_on_delete_restrict_foreign_key()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 94 def test_add_on_delete_restrict_foreign_key @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", on_delete: :restrict foreign_keys = @connection.foreign_keys("astronauts") assert_equal 1, foreign_keys.size fk = foreign_keys.first if current_adapter?(:MysqlAdapter, :Mysql2Adapter) # ON DELETE RESTRICT is the default on MySQL assert_equal nil, fk.on_delete else assert_equal :restrict, fk.on_delete end end
test_foreign_keys()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 37 def test_foreign_keys foreign_keys = @connection.foreign_keys("fk_test_has_fk") assert_equal 1, foreign_keys.size fk = foreign_keys.first assert_equal "fk_test_has_fk", fk.from_table assert_equal "fk_test_has_pk", fk.to_table assert_equal "fk_id", fk.column assert_equal "pk_id", fk.primary_key assert_equal "fk_name", fk.name end
test_on_update_and_on_delete_raises_with_invalid_values()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 129 def test_on_update_and_on_delete_raises_with_invalid_values assert_raises ArgumentError do @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", on_delete: :invalid end assert_raises ArgumentError do @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", on_update: :invalid end end
test_remove_foreign_key_by_column()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 157 def test_remove_foreign_key_by_column @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id" assert_equal 1, @connection.foreign_keys("astronauts").size @connection.remove_foreign_key :astronauts, column: "rocket_id" assert_equal [], @connection.foreign_keys("astronauts") end
test_remove_foreign_key_by_name()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 173 def test_remove_foreign_key_by_name @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", name: "fancy_named_fk" assert_equal 1, @connection.foreign_keys("astronauts").size @connection.remove_foreign_key :astronauts, name: "fancy_named_fk" assert_equal [], @connection.foreign_keys("astronauts") end
test_remove_foreign_key_by_symbol_column()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 165 def test_remove_foreign_key_by_symbol_column @connection.add_foreign_key :astronauts, :rockets, column: :rocket_id assert_equal 1, @connection.foreign_keys("astronauts").size @connection.remove_foreign_key :astronauts, column: :rocket_id assert_equal [], @connection.foreign_keys("astronauts") end
test_remove_foreign_key_inferes_column()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 149 def test_remove_foreign_key_inferes_column @connection.add_foreign_key :astronauts, :rockets assert_equal 1, @connection.foreign_keys("astronauts").size @connection.remove_foreign_key :astronauts, :rockets assert_equal [], @connection.foreign_keys("astronauts") end
test_remove_foreign_non_existing_foreign_key_raises()
Link
test_schema_dumping()
Link
test_schema_dumping_on_delete_and_on_update_options()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 198 def test_schema_dumping_on_delete_and_on_update_options @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", on_delete: :nullify, on_update: :cascade output = dump_table_schema "astronauts" assert_match %r{\s+add_foreign_key "astronauts",.+on_update: :cascade,.+on_delete: :nullify$}, output end
test_schema_dumping_with_options()
Link
# File activerecord/test/cases/migration/foreign_key_test.rb, line 193 def test_schema_dumping_with_options output = dump_table_schema "fk_test_has_fk" assert_match %r{\s+add_foreign_key "fk_test_has_fk", "fk_test_has_pk", column: "fk_id", primary_key: "pk_id", name: "fk_name"$}, output end