2024-07-26 23:24:54 -04:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class UsersControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
|
|
|
@user = users(:one)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should get index" do
|
2024-09-08 21:07:51 -04:00
|
|
|
login(@user.email)
|
2024-07-26 23:24:54 -04:00
|
|
|
get users_url
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should get new" do
|
|
|
|
get new_user_url
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should create user" do
|
2024-09-08 22:18:56 -04:00
|
|
|
stub_environment(REGISTRATION_ALLOWED: "true") do
|
|
|
|
assert_difference("User.count") do
|
|
|
|
params = {
|
|
|
|
user: {
|
|
|
|
email: "userthree@example.local",
|
|
|
|
password: "secret",
|
|
|
|
password_confirmation: "secret"
|
|
|
|
}
|
2024-07-26 23:24:54 -04:00
|
|
|
}
|
2024-09-08 22:18:56 -04:00
|
|
|
post users_url, params: params
|
|
|
|
end
|
2024-07-26 23:24:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_redirected_to user_url(User.last)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should show user" do
|
2024-09-08 21:07:51 -04:00
|
|
|
login(@user.email)
|
2024-07-26 23:24:54 -04:00
|
|
|
get user_url(@user)
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should get edit" do
|
2024-09-08 21:07:51 -04:00
|
|
|
login(@user.email)
|
2024-07-26 23:24:54 -04:00
|
|
|
get edit_user_url(@user)
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should update user" do
|
2024-09-08 21:07:51 -04:00
|
|
|
login(@user.email)
|
2024-07-26 23:24:54 -04:00
|
|
|
patch user_url(@user), params: { user: { email: @user.email, password: "secret", password_confirmation: "secret" } }
|
|
|
|
assert_redirected_to user_url(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should destroy user" do
|
2024-09-08 21:07:51 -04:00
|
|
|
login(@user.email)
|
2024-07-26 23:24:54 -04:00
|
|
|
assert_difference("User.count", -1) do
|
|
|
|
delete user_url(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_redirected_to users_url
|
|
|
|
end
|
|
|
|
end
|