From 5615113b9fd0e5e57e0e0e04ea975d85f5c52a49 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Fri, 14 Apr 2023 01:09:18 +0200 Subject: [PATCH] Test "register" --- README.md | 7 +++++++ test/system/users_test.rb | 15 +++++++++++++++ test/test_helper.rb | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 5191fb2..28d980f 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,10 @@ possibly with different Ruby versions: Use `RAILS_ENV="development"` for rake commands and running rails server. Use `RAILS_ENV="test"` for running tests. + + +### Running tests + +Single test: + + bin/rails test test/system/users_test.rb --name test_register diff --git a/test/system/users_test.rb b/test/system/users_test.rb index 8311d8d..1086cdc 100644 --- a/test/system/users_test.rb +++ b/test/system/users_test.rb @@ -27,6 +27,21 @@ class UsersTest < ApplicationSystemTestCase assert_text t('devise.failure.invalid', authentication_keys: User.human_attribute_name(:email)) 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 # visit users_url # assert_selector "h1", text: "Users" diff --git a/test/test_helper.rb b/test/test_helper.rb index d84ad99..4dbffc4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -18,4 +18,8 @@ class ActiveSupport::TestCase def random_password SecureRandom.alphanumeric rand(Rails.configuration.devise.password_length) end + + def random_email + "%s@%s.%s" % (1..3).map { SecureRandom.alphanumeric(rand(1..20)) } + end end