Permalink
Browse files

fk: `add/remove_foreign_key` are noop for adapters that don't support fk

  • Loading branch information...
1 parent 0938d53 commit 31e4c19331c9262574d354250675bba7dcf9dba2 @senny senny committed Jun 11, 2014
@@ -647,6 +647,8 @@ def foreign_keys(table_name)
end
def add_foreign_key(from_table, to_table, options = {})
+ return unless supports_foreign_keys?
+
options[:column] ||= foreign_key_column_for(to_table)
primary_key = options.fetch(:primary_key, "id")
@@ -664,6 +666,8 @@ def add_foreign_key(from_table, to_table, options = {})
end
def remove_foreign_key(from_table, options_or_to_table = {})
+ return unless supports_foreign_keys?
+
if options_or_to_table.is_a?(Hash)
options = options_or_to_table
else
@@ -202,4 +202,28 @@ def test_add_foreign_key_is_reversible
end
end
end
+else
+module ActiveRecord
+ class Migration
+ class NoForeignKeySupportTest < ActiveRecord::TestCase
+ setup do
+ @connection = ActiveRecord::Base.connection
+ end
+
+ def test_add_foreign_key_should_be_noop
+ @connection.add_foreign_key :clubs, :categories
+ end
+
+ def test_remove_foreign_key_should_be_noop
+ @connection.remove_foreign_key :clubs, :categories
+ end
+
+ def test_foreign_keys_should_raise_not_implemented
+ assert_raises NotImplementedError do
+ @connection.foreign_keys("clubs")
+ end
+ end
+ end
+ end
+end
end

0 comments on commit 31e4c19

Please sign in to comment.