diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-20 11:54:17 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-26 22:03:49 +0200 |
commit | 8768305f20d12c40241396092a63e0d56269fefe (patch) | |
tree | d08715db2104792427e6e71de1294238cbead260 /activerecord/test/cases/migration | |
parent | 8550ba307d712ebede0d0695b5172bb3e9af16c9 (diff) | |
download | rails-8768305f20d12c40241396092a63e0d56269fefe.tar.gz rails-8768305f20d12c40241396092a63e0d56269fefe.tar.bz2 rails-8768305f20d12c40241396092a63e0d56269fefe.zip |
fk: use random digest names
The name of the foreign key is not relevant from a users perspective.
Using random names resolves the urge to rename the foreign key when the
respective table or column is renamed.
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r-- | activerecord/test/cases/migration/foreign_key_test.rb | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb index 6a24df076d..c985092b4c 100644 --- a/activerecord/test/cases/migration/foreign_key_test.rb +++ b/activerecord/test/cases/migration/foreign_key_test.rb @@ -42,7 +42,7 @@ module ActiveRecord 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 "id", fk.primary_key + assert_equal "pk_id", fk.primary_key assert_equal "fk_name", fk.name end @@ -57,7 +57,7 @@ module ActiveRecord assert_equal "rockets", fk.to_table assert_equal "rocket_id", fk.column assert_equal "id", fk.primary_key - assert_equal "astronauts_rocket_id_fk", fk.name + assert_match(/^fk_rails_.{10}$/, fk.name) end def test_add_foreign_key_with_column @@ -71,7 +71,7 @@ module ActiveRecord assert_equal "rockets", fk.to_table assert_equal "rocket_id", fk.column assert_equal "id", fk.primary_key - assert_equal "astronauts_rocket_id_fk", fk.name + assert_match(/^fk_rails_.{10}$/, fk.name) end def test_add_foreign_key_with_non_standard_primary_key @@ -146,15 +146,6 @@ module ActiveRecord assert_equal :nullify, fk.on_update end - def test_add_foreign_key_with_too_long_identifier - with_example_table @connection, "long_table_name_will_result_in_a_long_foreign_key_name", "rocket_id integer" do - e = assert_raises(ArgumentError) do - @connection.add_foreign_key "long_table_name_will_result_in_a_long_foreign_key_name", "rockets" - end - assert_match(/^Foreign key name 'long_table_name_will_result_in_a_long_foreign_key_name_rocket_id_fk' is too long;/, e.message) - end - end - def test_remove_foreign_key_inferes_column @connection.add_foreign_key :astronauts, :rockets @@ -179,9 +170,21 @@ module ActiveRecord assert_equal [], @connection.foreign_keys("astronauts") end + def test_remove_foreign_non_existing_foreign_key_raises + assert_raises ArgumentError do + @connection.remove_foreign_key :astronauts, :rockets + end + end + def test_schema_dumping + @connection.add_foreign_key :astronauts, :rockets + output = dump_table_schema "astronauts" + assert_match %r{\s+add_foreign_key "astronauts", "rockets"$}, output + end + + 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: "id", name: "fk_name"$}, output + 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 def test_schema_dumping_on_delete_and_on_update_options @@ -205,7 +208,7 @@ module ActiveRecord def test_add_foreign_key_is_reversible migration = CreateCitiesAndHousesMigration.new silence_stream($stdout) { migration.migrate(:up) } - assert_equal ["houses_city_id_fk"], @connection.foreign_keys("houses").map(&:name) + assert_equal 1, @connection.foreign_keys("houses").size ensure silence_stream($stdout) { migration.migrate(:down) } end |