diff --git a/lib/generators/active_record/devise_generator.rb b/lib/generators/active_record/devise_generator.rb index ba55d7ec..35541d91 100644 --- a/lib/generators/active_record/devise_generator.rb +++ b/lib/generators/active_record/devise_generator.rb @@ -27,7 +27,11 @@ module ActiveRecord attr_accessible :email, :password, :password_confirmation, :remember_me CONTENT - class_path = class_name.to_s.split("::") + class_path = if namespaced? + class_name.to_s.split("::") + else + [class_name] + end indent_depth = class_path.size - 1 content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n" diff --git a/test/generators/active_record_generator_test.rb b/test/generators/active_record_generator_test.rb index 7bf11db8..f4160034 100644 --- a/test/generators/active_record_generator_test.rb +++ b/test/generators/active_record_generator_test.rb @@ -14,6 +14,12 @@ if DEVISE_ORM == :active_record assert_migration "db/migrate/devise_create_monsters.rb", /def change/ end + test "all files for namespaced model are properly created" do + run_generator %w(admin/monster) + assert_file "app/models/admin/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/ + assert_migration "db/migrate/devise_create_admin_monsters.rb", /def change/ + end + test "update model migration when model exists" do run_generator %w(monster) assert_file "app/models/monster.rb" @@ -66,4 +72,4 @@ if DEVISE_ORM == :active_record end end end -end \ No newline at end of file +end