Added the ability to change the default migrations path (introduced in Rails 5.0.3)

This commit is contained in:
Alexey Degtyarev
2017-12-21 17:12:19 +02:00
parent 1b02534bef
commit 12298ef968
3 changed files with 38 additions and 3 deletions

View File

@@ -13,6 +13,20 @@ if DEVISE_ORM == :active_record
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
end
test "all files are properly created with changed db/migrate path in application configuration" do
old_paths = Rails.application.config.paths["db/migrate"]
Rails.application.config.paths.add "db/migrate", with: "db2/migrate"
run_generator %w(monster)
if Rails.version >= '5.0.3'
assert_migration "db2/migrate/devise_create_monsters.rb", /def change/
else
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
end
Rails.application.config.paths["db/migrate"] = old_paths
end
test "all files for namespaced model are properly created" do
run_generator %w(admin/monster)
assert_migration "db/migrate/devise_create_admin_monsters.rb", /def change/
@@ -25,6 +39,23 @@ if DEVISE_ORM == :active_record
assert_migration "db/migrate/add_devise_to_monsters.rb"
end
test "update model migration when model exists with changed db/migrate path in application configuration" do
old_paths = Rails.application.config.paths["db/migrate"]
Rails.application.config.paths.add "db/migrate", with: "db2/migrate"
run_generator %w(monster)
assert_file "app/models/monster.rb"
run_generator %w(monster)
if Rails.version >= '5.0.3'
assert_migration "db2/migrate/add_devise_to_monsters.rb"
else
assert_migration "db/migrate/add_devise_to_monsters.rb"
end
Rails.application.config.paths["db/migrate"] = old_paths
end
test "all files are properly deleted" do
run_generator %w(monster)
run_generator %w(monster)