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/enforce initial password length to follow devise #848

Merged
merged 2 commits into from Mar 7, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion lib/devise_invitable/models.rb
Expand Up @@ -397,7 +397,8 @@ def after_invitation_accepted(*args, &blk)
# lower + upper case, a digit and a symbol.
# For more unusual rules, this method can be overridden.
def random_password
'aA1!' + Devise.friendly_token[0, 20]
prefix = 'aA1!'
prefix + Devise.friendly_token(self.password_length.last-prefix.length)
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/models/invitable_test.rb
@@ -1,6 +1,10 @@
require 'test_helper'
require 'model_tests_helper'

class Validatable < User
devise :validatable, password_length: 10..20
end

class InvitableTest < ActiveSupport::TestCase

def setup
Expand Down Expand Up @@ -760,4 +764,10 @@ def assert_callbacks_status(callback, user, fired)
assert user.persisted?
assert user.errors.empty?
end

test 'should set initial password following devise password_length' do
user = Validatable.invite!(email: 'valid@email.com')
user.update_attributes(profile_id: 1)
assert_empty user.errors
end
end