Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/controllers/names_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions test/integration/user_signup_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading