1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Added Controller Generator and tests to go along with it.

This commit is contained in:
Matthew Burket 2011-05-30 23:07:20 -05:00
parent 97659a1193
commit 4f446241a4
3 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,18 @@
require 'tmpdir'
module Devise
module Generators
class ControllersGenerator < Rails::Generators::Base
source_root File.expand_path("../../../../app/controllers", __FILE__)
desc "Copies all Devise controllers to your application."
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy controllers to"
def copy_controllers
directory "devise", "app/controllers/#{scope || :devise}"
end
end
end
end

View file

@ -0,0 +1,29 @@
require "test_helper"
class ControllersGeneratorTest < Rails::Generators::TestCase
tests Devise::Generators::ControllersGenerator
destination File.expand_path("../../tmp", __FILE__)
setup :prepare_destination
test "Assert all controllers are properly created with no params" do
run_generator
assert_files
end
test "Assert all controllers are properly created with scope param param" do
run_generator %w(users)
assert_files "users"
run_generator %w(admins)
assert_files "admins"
end
def assert_files(scope = nil, template_engine = nil)
scope = "devise" if scope.nil?
assert_file "app/controllers/#{scope}/confirmations_controller.rb"
assert_file "app/controllers/#{scope}/omniauth_callbacks_controller.rb"
assert_file "app/controllers/#{scope}/passwords_controller.rb"
assert_file "app/controllers/#{scope}/sessions_controller.rb"
assert_file "app/controllers/#{scope}/unlocks_controller.rb"
end
end

View file

@ -25,3 +25,4 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
require "rails/generators/test_case"
require "generators/devise/install_generator"
require "generators/devise/views_generator"
require "generators/devise/controllers_generator"