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 NoMethodError in random_password #850

Merged
merged 3 commits into from Apr 14, 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
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -29,3 +29,4 @@ webrat.log

# Generated test files
tmp/*
test/rails_app/tmp/
4 changes: 3 additions & 1 deletion lib/devise_invitable/models.rb
Expand Up @@ -397,8 +397,10 @@ 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
length = respond_to?(:password_length) ? password_length : Devise.password_length

prefix = 'aA1!'
prefix + Devise.friendly_token(self.password_length.last-prefix.length)
prefix + Devise.friendly_token(length.last - prefix.length)
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions test/models/invitable_test.rb
Expand Up @@ -765,9 +765,15 @@ def assert_callbacks_status(callback, user, fired)
assert user.errors.empty?
end

test 'should set initial password following devise password_length' do
test 'should set initial password following Devise.password_length' do
user = User.invite!(email: 'valid@email.com')
assert_empty user.errors
assert_equal Devise.password_length.last, user.password.length
end

test 'should set initial passsword using :validatable with custom password_length' do
user = Validatable.invite!(email: 'valid@email.com')
user.update_attributes(profile_id: 1)
assert_empty user.errors
assert_equal Validatable.password_length.last, user.password.length
end
end