From 8faaf63bd2ddaf48a10f988aea6b5f98aecf5884 Mon Sep 17 00:00:00 2001 From: vangberg Date: Mon, 15 Jun 2026 11:57:09 +0200 Subject: [PATCH 1/2] Add names controller test --- test/controllers/names_controller_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/controllers/names_controller_test.rb b/test/controllers/names_controller_test.rb index 7d12432f..cf4f4fe3 100644 --- a/test/controllers/names_controller_test.rb +++ b/test/controllers/names_controller_test.rb @@ -1,8 +1,24 @@ require 'test_helper' class NamesControllerTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + setup do @name = names(:unregistered) + @user = users(:contributor) + sign_in(@user) end + test 'submits a new name' do + assert_difference('Name.count', 1) do + post names_url, params: { name: { name: 'Testimonas exampleensis' } } + end + + name = Name.find_by!(name: 'Testimonas exampleensis') + + assert_equal 'Draft', name.status_name + assert_equal @user, name.created_by + assert name.observing?(@user) + assert_redirected_to name_url(name) + end end From 32f2123bc1d37cf7c73a02a4a55ba3deb1df8d9f Mon Sep 17 00:00:00 2001 From: vangberg Date: Mon, 15 Jun 2026 11:10:40 +0200 Subject: [PATCH 2/2] Add signup controller test --- config/environments/test.rb | 3 ++ test/integration/user_signup_test.rb | 54 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/integration/user_signup_test.rb diff --git a/config/environments/test.rb b/config/environments/test.rb index 0cb24249..17b79321 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped @@ -40,6 +42,7 @@ # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + config.action_mailer.default_url_options = { host: 'www.example.com' } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/test/integration/user_signup_test.rb b/test/integration/user_signup_test.rb new file mode 100644 index 00000000..7f7d789e --- /dev/null +++ b/test/integration/user_signup_test.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'test_helper' + +class UserSignupTest < ActionDispatch::IntegrationTest + test 'signs up and confirms a user' do # rubocop:disable Metrics/BlockLength + user_count = User.count + email_count = ActionMailer::Base.deliveries.size + + post user_registration_url, params: { + user: { + email: 'new-user@example.com', + username: 'new_user', + password: 'password123', + password_confirmation: 'password123', + family: 'User', + given: 'New', + affiliation: 'Primary institution', + # rubocop:disable Naming/VariableNumber + affiliation_2: 'Secondary institution', + # rubocop:enable Naming/VariableNumber + opt_regular_email: false, + opt_message_email: false, + opt_notification: false + } + } + + assert_equal user_count + 1, User.count + assert_equal email_count + 1, ActionMailer::Base.deliveries.size + + user = User.find_by!(email: 'new-user@example.com') + assert_equal 'new_user', user.username + assert_equal 'User', user.family + assert_equal 'New', user.given + assert_equal 'Primary institution', user.affiliation + assert_equal 'Secondary institution', user.affiliation_2 + assert_not user.opt_regular_email + assert_not user.opt_message_email + assert_not user.opt_notification + assert_not user.confirmed? + assert_response :redirect + + confirmation_link = Nokogiri::HTML( + ActionMailer::Base.deliveries.last.body.to_s + ).at_css('a[href*="/users/confirmation?confirmation_token="]') + + assert confirmation_link, 'confirmation email has no confirmation link' + + get confirmation_link['href'] + + assert user.reload.confirmed? + assert_response :redirect + end # rubocop:enable Metrics/BlockLength +end