Permalink
Browse files

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.
  • Loading branch information...
1 parent 9629da8 commit 179cb2c88a2be958f942ddbe8100b5bd6bedc2c3 @seanski committed Aug 28, 2011
View
8 lib/generators/active_record/devise_generator.rb
@@ -9,10 +9,6 @@ class DeviseGenerator < ActiveRecord::Generators::Base
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 @@ def copy_devise_migration
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
View
7 test/generators/active_record_generator_test.rb
@@ -13,6 +13,13 @@ class ActiveRecordGeneratorTest < Rails::Generators::TestCase
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
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)

0 comments on commit 179cb2c

Please sign in to comment.