Skip to content

Commit

Permalink
Restore test using Validatable and support both scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
rhymes authored and scambra committed Apr 14, 2021
1 parent 8dc54b7 commit c18b083
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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(Devise.password_length.last - prefix.length)
prefix + Devise.friendly_token(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 @@ -766,4 +770,10 @@ def assert_callbacks_status(callback, user, fired)
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')
assert_empty user.errors
assert_equal Validatable.password_length.last, user.password.length
end
end

0 comments on commit c18b083

Please sign in to comment.