Test "register"

This commit is contained in:
cryptogopher 2023-04-14 01:09:18 +02:00
parent cc857a74bf
commit 5615113b9f
3 changed files with 26 additions and 0 deletions

View File

@ -78,3 +78,10 @@ possibly with different Ruby versions:
Use `RAILS_ENV="development"` for rake commands and running rails server. Use `RAILS_ENV="development"` for rake commands and running rails server.
Use `RAILS_ENV="test"` for running tests. Use `RAILS_ENV="test"` for running tests.
### Running tests
Single test:
bin/rails test test/system/users_test.rb --name test_register

View File

@ -27,6 +27,21 @@ class UsersTest < ApplicationSystemTestCase
assert_text t('devise.failure.invalid', authentication_keys: User.human_attribute_name(:email)) assert_text t('devise.failure.invalid', authentication_keys: User.human_attribute_name(:email))
end end
# TODO: require e-mail confirmation on registration
test "register" do
visit new_user_session_url
click_link t(:register)
fill_in User.human_attribute_name(:email).capitalize, with: random_email
password = random_password
fill_in User.human_attribute_name(:password).capitalize, with: password
fill_in t('users.registrations.new.password_confirmation'), with: password
assert_difference ->{User.count}, 1 do
click_on t(:register)
end
assert_no_current_path new_user_registration_path
assert_text t('devise.registrations.signed_up')
end
#test "visiting the index" do #test "visiting the index" do
# visit users_url # visit users_url
# assert_selector "h1", text: "Users" # assert_selector "h1", text: "Users"

View File

@ -18,4 +18,8 @@ class ActiveSupport::TestCase
def random_password def random_password
SecureRandom.alphanumeric rand(Rails.configuration.devise.password_length) SecureRandom.alphanumeric rand(Rails.configuration.devise.password_length)
end end
def random_email
"%s@%s.%s" % (1..3).map { SecureRandom.alphanumeric(rand(1..20)) }
end
end end