Skip to content
Open
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
48 changes: 12 additions & 36 deletions test/controllers/names_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,24 @@
require 'test_helper'

class NamesControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers

setup do
@name = names(:one)
@user = users(:contributor)
sign_in(@user)
end

test 'should get index' do
get names_url
assert_response :success
end

test 'should get new' do
get new_name_url
assert_response :success
end

test 'should create name' do
assert_difference('Name.count') do
post names_url, params: { name: { name: @name.name } }
test 'submits a new name' do
assert_difference('Name.count', 1) do
post names_url, params: { name: { name: 'Testimonas exampleensis' } }
end

assert_redirected_to name_url(Name.last)
end

test 'should show name' do
get name_url(@name)
assert_response :success
end

test 'should get edit' do
get edit_name_url(@name)
assert_response :success
end

test 'should update name' do
patch name_url(@name), params: { name: { name: @name.name } }
assert_redirected_to name_url(@name)
end

test 'should destroy name' do
assert_difference('Name.count', -1) do
delete name_url(@name)
end
name = Name.find_by!(name: 'Testimonas exampleensis')

assert_redirected_to names_url
assert_equal 'Draft', name.status_name
assert_equal @user, name.created_by
assert name.observing?(@user)
assert_redirected_to name_url(name)
end
end
22 changes: 13 additions & 9 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
one:
username: user_one
email: user_one@example.com

two:
username: user_two
email: user_two@example.com

contributor:
username: contributor
email: contributor@example.com
contributor: true
confirmed_at: 2026-01-01 00:00:00
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