Skip to content
Browse files

fk: raise for invalid :on_update / :on_delete values

  • Loading branch information...
1 parent 31e4c19 commit 8550ba307d712ebede0d0695b5172bb3e9af16c9 @senny senny committed Jun 20, 2014
View
11 activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb
@@ -104,9 +104,14 @@ def options_include_default?(options)
def action_sql(action, dependency)
case dependency
- when :nullify then "ON #{action} SET NULL"
- when :cascade then "ON #{action} CASCADE"
- when :restrict then "ON #{action} RESTRICT"
+ when :nullify then "ON #{action} SET NULL"
+ when :cascade then "ON #{action} CASCADE"
+ when :restrict then "ON #{action} RESTRICT"
+ else
+ raise ArgumentError, <<-MSG
+'#{dependency}' is not supported for :on_update or :on_delete.
+Supported values are: :nullify, :cascade, :restrict
+ MSG
end
end
end
View
10 activerecord/test/cases/migration/foreign_key_test.rb
@@ -126,6 +126,16 @@ def test_add_on_delete_nullify_foreign_key
assert_equal :nullify, fk.on_delete
end
+ 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
+
def test_add_foreign_key_with_on_update
@connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", on_update: :nullify

0 comments on commit 8550ba3

Please sign in to comment.
Something went wrong with that request. Please try again.