2024-05-26 10:45:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-14 19:01:32 +00:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class UsersControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
test "should get new" do
|
|
|
|
get new_user_url
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2024-05-29 16:17:06 +00:00
|
|
|
test "should get show" do
|
|
|
|
sign_in users(:trevor)
|
|
|
|
get user_url(users(:trevor))
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2024-04-14 19:01:32 +00:00
|
|
|
test "should create user" do
|
|
|
|
assert_changes("User.count", +1) do
|
|
|
|
post(users_url, params: { user: user_params })
|
|
|
|
end
|
2024-04-21 14:01:10 +00:00
|
|
|
assert_redirected_to login_path
|
2024-04-14 19:01:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "should email user for confirmation" do
|
|
|
|
assert_emails(+1) do
|
|
|
|
post(users_url, params: { user: user_params })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should alert to invalid user" do
|
|
|
|
assert_no_changes("User.count") do
|
|
|
|
post(users_url, params: { user: { username: "new_user" } })
|
|
|
|
end
|
|
|
|
assert_response :unprocessable_entity
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user_params
|
|
|
|
{
|
|
|
|
username: "new_user",
|
|
|
|
password: "password",
|
|
|
|
email: "new_user@ex.com",
|
|
|
|
first_name: "new",
|
|
|
|
last_name: "user",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|