1
0
Fork 0
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:
Sean Hill 2011-08-29 17:53:32 -05:00
parent 99d539b9a7
commit 8ad414b217
3 changed files with 26 additions and 4 deletions

View file

@ -1,6 +1,7 @@
require 'rails/generators/active_record'
require 'generators/devise/orm_helpers'
module ActiveRecord
module Generators
class DeviseGenerator < ActiveRecord::Generators::Base
@ -11,11 +12,18 @@ module ActiveRecord
def copy_devise_migration
exists = model_exists?
exists = !exists if behavior == :revoke
unless exists
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
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
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}"
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

View file

@ -14,6 +14,14 @@ CONTENT
def model_exists?
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")

View file

@ -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"