Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DeviseCreateDefaultAdminUser migration for Rails 3.0 #1629

Merged
merged 1 commit into from Aug 31, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/generators/active_admin/devise/devise_generator.rb
Expand Up @@ -35,14 +35,24 @@ def set_namespace_for_path

def add_default_user_to_migration
# Don't assume that we have a migration!
devise_migrations = Dir["db/migrate/*_devise_create_#{table_name}.rb"]
if devise_migrations.size > 0
inject_into_file Dir["db/migrate/*_devise_create_#{table_name}.rb"].first,
devise_migration_file = Dir["db/migrate/*_devise_create_#{table_name}.rb"].first
return if devise_migration_file.nil?

devise_migration_content = File.read(devise_migration_file)

if devise_migration_content["def change"]
inject_into_file devise_migration_file,
"def migrate(direction)\n super\n # Create a default user\n AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password') if direction == :up\n end\n\n ",
:before => "def change"
elsif devise_migration_content[/def (self.)?up/]
inject_into_file devise_migration_file,
"# Create a default user\n #{class_name}.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')\n\n ",
:before => "add_index :#{table_name}, :email"
else
puts devise_migration_content
raise "Failed to add default admin user to migration."
end
end

end
end
end