mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Added a helper to look for an modifying migration. If one is found during :revoke, the modifying migration is deleted. If the modifying migration is not found, the creating migration is deleted.
This commit is contained in:
parent
99d539b9a7
commit
8ad414b217
3 changed files with 26 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
require 'rails/generators/active_record'
|
||||
require 'generators/devise/orm_helpers'
|
||||
|
||||
|
||||
module ActiveRecord
|
||||
module Generators
|
||||
class DeviseGenerator < ActiveRecord::Generators::Base
|
||||
|
@ -11,12 +12,19 @@ module ActiveRecord
|
|||
|
||||
def copy_devise_migration
|
||||
exists = model_exists?
|
||||
exists = !exists if behavior == :revoke
|
||||
unless behavior == :revoke
|
||||
unless exists
|
||||
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
||||
else
|
||||
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}"
|
||||
end
|
||||
else
|
||||
if migration_exists?(table_name)
|
||||
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}"
|
||||
else
|
||||
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generate_model
|
||||
|
|
|
@ -15,6 +15,14 @@ CONTENT
|
|||
File.exists?(File.join(destination_root, model_path))
|
||||
end
|
||||
|
||||
def migration_exists?(table_name)
|
||||
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
||||
end
|
||||
|
||||
def migration_path
|
||||
@migration_path ||= File.join("db", "migrate")
|
||||
end
|
||||
|
||||
def model_path
|
||||
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
||||
end
|
||||
|
|
|
@ -23,6 +23,12 @@ if DEVISE_ORM == :active_record
|
|||
|
||||
test "all files are properly deleted" do
|
||||
run_generator %w(monster)
|
||||
run_generator %w(monster)
|
||||
assert_migration "db/migrate/devise_create_monsters.rb"
|
||||
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
||||
run_generator %w(monster), :behavior => :revoke
|
||||
assert_no_migration "db/migrate/add_devise_to_monsters.rb"
|
||||
assert_migration "db/migrate/devise_create_monsters.rb"
|
||||
run_generator %w(monster), :behavior => :revoke
|
||||
assert_no_file "app/models/monster.rb"
|
||||
assert_no_migration "db/migrate/devise_create_monsters.rb"
|
||||
|
|
Loading…
Reference in a new issue