diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index 1ae5af87..fabe66f8 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -5,8 +5,10 @@ class Devise::RegistrationsController < DeviseController # GET /resource/sign_up def new build_resource({}) - @validatable = Devise.mappings[resource_name].modules.include?(:validatable) - @minimum_password_length = Devise.password_length.min + @validatable = devise_mapping.validatable? + if @validatable + @minimum_password_length = resource_class.password_length.min + end respond_with self.resource end diff --git a/test/controllers/passwords_controller_test.rb b/test/controllers/passwords_controller_test.rb index 3d4c0f20..3c225cbf 100644 --- a/test/controllers/passwords_controller_test.rb +++ b/test/controllers/passwords_controller_test.rb @@ -12,7 +12,7 @@ class PasswordsControllerTest < ActionController::TestCase def put_update_with_params put :update, "user" => { - "reset_password_token" => @raw, "password" => "123456", "password_confirmation" => "123456" + "reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567" } end diff --git a/test/integration/registerable_test.rb b/test/integration/registerable_test.rb index 4bfdf39c..3e58076d 100644 --- a/test/integration/registerable_test.rb +++ b/test/integration/registerable_test.rb @@ -36,6 +36,12 @@ class RegistrationTest < ActionDispatch::IntegrationTest assert_current_url "/?custom=1" end + test 'a guest admin should not see a warning about minimum password length' do + get new_admin_session_path + assert_not_contain 'characters minimum' + end + + def user_sign_up ActionMailer::Base.deliveries.clear @@ -47,6 +53,11 @@ class RegistrationTest < ActionDispatch::IntegrationTest click_button 'Sign up' end + test 'a guest user should see a warning about minimum password length' do + get new_user_registration_path + assert_contain '7 characters minimum' + end + test 'a guest user should be able to sign up successfully and be blocked by confirmation' do user_sign_up diff --git a/test/models/authenticatable_test.rb b/test/models/authenticatable_test.rb index f57d1bdf..3d791d44 100644 --- a/test/models/authenticatable_test.rb +++ b/test/models/authenticatable_test.rb @@ -6,7 +6,7 @@ class AuthenticatableTest < ActiveSupport::TestCase end test 'find_first_by_auth_conditions allows custom filtering parameters' do - user = User.create!(email: "example@example.com", password: "123456") + user = User.create!(email: "example@example.com", password: "1234567") assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }), user assert_nil User.find_first_by_auth_conditions({ email: "example@example.com" }, id: user.id.to_s.next) end diff --git a/test/models/validatable_test.rb b/test/models/validatable_test.rb index c73b4389..c8dc6877 100644 --- a/test/models/validatable_test.rb +++ b/test/models/validatable_test.rb @@ -86,10 +86,10 @@ class ValidatableTest < ActiveSupport::TestCase end end - test 'should require a password with minimum of 6 characters' do + test 'should require a password with minimum of 7 characters' do user = new_user(password: '12345', password_confirmation: '12345') assert user.invalid? - assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join + assert_equal 'is too short (minimum is 7 characters)', user.errors[:password].join end test 'should require a password with maximum of 128 characters long' do diff --git a/test/rails_app/lib/shared_user.rb b/test/rails_app/lib/shared_user.rb index 511c23ca..adb0e333 100644 --- a/test/rails_app/lib/shared_user.rb +++ b/test/rails_app/lib/shared_user.rb @@ -4,7 +4,7 @@ module SharedUser included do devise :database_authenticatable, :confirmable, :lockable, :recoverable, :registerable, :rememberable, :timeoutable, - :trackable, :validatable, :omniauthable + :trackable, :validatable, :omniauthable, password_length: 7..128 attr_accessor :other_key