提交 a57990ff 编写于 作者: J John Firebaugh

Call methods on the correct instance in AR::Schema.define

Now that migrations support instance methods, we should
use the same instance rather than relying on delegation
to a global instance. This allows subclassing AR::Schema.
上级 d6e4c06a
......@@ -34,6 +34,15 @@ def migrations_paths
ActiveRecord::Migrator.migrations_paths
end
def define(info, &block)
instance_eval(&block)
unless info[:version].blank?
initialize_schema_migrations_table
assume_migrated_upto_version(info[:version], migrations_paths)
end
end
# Eval the given block. All methods available to the current connection
# adapter are available within the block, so you can easily use the
# database definition DSL to build up your schema (+create_table+,
......@@ -46,13 +55,7 @@ def migrations_paths
# ...
# end
def self.define(info={}, &block)
schema = new
schema.instance_eval(&block)
unless info[:version].blank?
initialize_schema_migrations_table
assume_migrated_upto_version(info[:version], schema.migrations_paths)
end
new.define(info, &block)
end
end
end
......@@ -37,6 +37,13 @@ def test_schema_raises_an_error_for_invalid_column_type
end
end
end
def test_schema_subclass
Class.new(ActiveRecord::Schema).define(:version => 9) do
create_table :fruits
end
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册