Generators on engine fix

This commit is contained in:
Rodrigo Flores 2012-04-27 17:57:44 -03:00
parent f6c06ac786
commit afc3888391
2 changed files with 22 additions and 1 deletions

View File

@ -22,10 +22,15 @@ module ActiveRecord
end
def inject_devise_content
inject_into_class(model_path, class_name, model_contents + <<CONTENT) if model_exists?
content = model_contents + <<CONTENT
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
CONTENT
indent_size = class_name.to_s.split("::").size - 1
content = content.split("\n").map { |line| " " * indent_size + line}.join("\n")
inject_into_class(model_path, class_name.to_s.split("::").last, content) if model_exists?
end
def migration_data

View File

@ -34,4 +34,20 @@ if DEVISE_ORM == :active_record
assert_no_migration "db/migrate/devise_create_monsters.rb"
end
end
class RailsEngine ; end
class ActiveRecordGeneratorTest < Rails::Generators::TestCase
tests ActiveRecord::Generators::DeviseGenerator
destination File.expand_path("../../tmp", __FILE__)
setup :prepare_destination
test "all files are properly created" do
swap Rails::Generators, :namespace => RailsEngine do
run_generator ["monster"]
assert_file "app/models/rails_engine/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
end
end
end
end