提交 85741dd1 编写于 作者: C Carlos Antonio da Silva

Merge pull request #8500 from senny/8492_migrations_crash_on_specific_path

Recognize migrations, in folders containing numbers and 'rb'
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##
* Recognize migrations placed in directories containing numbers and 'rb'.
Fix #8492
*Yves Senn*
* Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control * Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
the format of the timestamp value in the cache key. the format of the timestamp value in the cache key.
This allows users to improve the precision of the cache key. This allows users to improve the precision of the cache key.
......
...@@ -665,7 +665,7 @@ def migrations(paths) ...@@ -665,7 +665,7 @@ def migrations(paths)
files = Dir[*paths.map { |p| "#{p}/**/[0-9]*_*.rb" }] files = Dir[*paths.map { |p| "#{p}/**/[0-9]*_*.rb" }]
migrations = files.map do |file| migrations = files.map do |file|
version, name, scope = file.scan(/([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?.rb/).first version, name, scope = file.scan(/([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?\.rb\z/).first
raise IllegalMigrationNameError.new(file) unless version raise IllegalMigrationNameError.new(file) unless version
version = version.to_i version = version.to_i
......
...@@ -84,6 +84,12 @@ def test_finds_migrations_from_two_directories ...@@ -84,6 +84,12 @@ def test_finds_migrations_from_two_directories
end end
end end
def test_finds_migrations_in_numbered_directory
migrations = ActiveRecord::Migrator.migrations [MIGRATIONS_ROOT + '/10_urban']
assert_equal 9, migrations[0].version
assert_equal 'AddExpressions', migrations[0].name
end
def test_deprecated_constructor def test_deprecated_constructor
assert_deprecated do assert_deprecated do
ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid") ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid")
......
class AddExpressions < ActiveRecord::Migration
def self.up
create_table("expressions") do |t|
t.column :expression, :string
end
end
def self.down
drop_table "expressions"
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册