Sha256: c3dd7378b1796b4da691deab680ef578c8c44a880339c3226a51634fb8a5548d

Contents?: true

Size: 1.84 KB

Versions: 27

Compression:

Stored size: 1.84 KB

Contents

require "test_helper"

class ControllersGeneratorTest < Rails::Generators::TestCase
  tests Devise::Generators::ControllersGenerator
  destination File.expand_path("../../tmp", __FILE__)
  setup :prepare_destination

  test "Assert no controllers are created with no params" do
    capture(:stderr) { run_generator }
    assert_no_file "app/controllers/sessions_controller.rb"
    assert_no_file "app/controllers/registrations_controller.rb"
    assert_no_file "app/controllers/confirmations_controller.rb"
    assert_no_file "app/controllers/passwords_controller.rb"
    assert_no_file "app/controllers/unlocks_controller.rb"
    assert_no_file "app/controllers/omniauth_callbacks_controller.rb"
  end

  test "Assert all controllers are properly created with scope param" do
    run_generator %w(users)
    assert_class_names 'users'

    run_generator %w(admins)
    assert_class_names 'admins'
  end

  test "Assert specified controllers with scope" do
    run_generator %w(users -c sessions)
    assert_file "app/controllers/users/sessions_controller.rb"
    assert_no_file "app/controllers/users/registrations_controller.rb"
    assert_no_file "app/controllers/users/confirmations_controller.rb"
    assert_no_file "app/controllers/users/passwords_controller.rb"
    assert_no_file "app/controllers/users/unlocks_controller.rb"
    assert_no_file "app/controllers/users/omniauth_callbacks_controller.rb"
  end

  private

    def assert_class_names(scope, options = {})
      base_dir = "app/controllers#{scope.blank? ? '' : ('/' + scope)}"
      scope_prefix = scope.blank? ? '' : (scope.camelize + '::')
      controllers = options[:controllers] ||
        %w(confirmations passwords registrations sessions unlocks omniauth_callbacks)

      controllers.each do |c|
        assert_file "#{base_dir}/#{c}_controller.rb", /#{scope_prefix + c.camelize}/
      end
    end
end

Version data entries

27 entries across 27 versions & 5 rubygems

Version Path
devise-4.3.0 test/generators/controllers_generator_test.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/devise-4.2.1/test/generators/controllers_generator_test.rb
devise-4.2.1 test/generators/controllers_generator_test.rb
devise-4.2.0 test/generators/controllers_generator_test.rb
devise-3.5.10 test/generators/controllers_generator_test.rb
devise-4.0.3 test/generators/controllers_generator_test.rb
devise-4.1.1 test/generators/controllers_generator_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/devise-4.1.0/test/generators/controllers_generator_test.rb
devise-4.1.0 test/generators/controllers_generator_test.rb
devise-3.5.9 test/generators/controllers_generator_test.rb
devise-4.0.2 test/generators/controllers_generator_test.rb
devise-4.0.1 test/generators/controllers_generator_test.rb
devise-3.5.8 test/generators/controllers_generator_test.rb
devise-3.5.7 test/generators/controllers_generator_test.rb
devise-4.0.0 test/generators/controllers_generator_test.rb
devise-4.0.0.rc2 test/generators/controllers_generator_test.rb
devise-4.0.0.rc1 test/generators/controllers_generator_test.rb
devise-3.5.6 test/generators/controllers_generator_test.rb
devise-3.5.5 test/generators/controllers_generator_test.rb
devise-3.5.4 test/generators/controllers_generator_test.rb