mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Changed the order of the devise_generator methods to create the model after the migration to properly use model_exists?, and I added tests to prove the generator works.
This commit is contained in:
parent
9629da863d
commit
179cb2c88a
2 changed files with 11 additions and 4 deletions
|
@ -9,10 +9,6 @@ module ActiveRecord
|
|||
include Devise::Generators::OrmHelpers
|
||||
source_root File.expand_path("../templates", __FILE__)
|
||||
|
||||
def generate_model
|
||||
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
||||
end
|
||||
|
||||
def copy_devise_migration
|
||||
unless model_exists?
|
||||
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
||||
|
@ -21,6 +17,10 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def generate_model
|
||||
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
||||
end
|
||||
|
||||
def inject_devise_content
|
||||
inject_into_class(model_path, class_name, model_contents + <<CONTENT) if model_exists?
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
|
|
|
@ -14,6 +14,13 @@ if DEVISE_ORM == :active_record
|
|||
assert_migration "db/migrate/devise_create_monsters.rb"
|
||||
end
|
||||
|
||||
test "update model migration when model exists" do
|
||||
run_generator %w(monster)
|
||||
assert_file "app/models/monster.rb"
|
||||
run_generator %w(monster)
|
||||
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
||||
end
|
||||
|
||||
test "all files are properly deleted" do
|
||||
run_generator %w(monster)
|
||||
run_generator %w(monster), :behavior => :revoke
|
||||
|
|
Loading…
Reference in a new issue