budget/test/controllers/users_controller_test.rb
Andrew Tomaka 543a9599e0
All checks were successful
Deploy / deploy (push) Successful in 4m1s
Hack in registration prevention (#37)
Reviewed-on: #37
2024-09-08 22:18:56 -04:00

62 lines
1.3 KiB
Ruby

require "test_helper"
class UsersControllerTest < ActionDispatch::IntegrationTest
setup do
@user = users(:one)
end
test "should get index" do
login(@user.email)
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
stub_environment(REGISTRATION_ALLOWED: "true") do
assert_difference("User.count") do
params = {
user: {
email: "userthree@example.local",
password: "secret",
password_confirmation: "secret"
}
}
post users_url, params: params
end
end
assert_redirected_to user_url(User.last)
end
test "should show user" do
login(@user.email)
get user_url(@user)
assert_response :success
end
test "should get edit" do
login(@user.email)
get edit_user_url(@user)
assert_response :success
end
test "should update user" do
login(@user.email)
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
login(@user.email)
assert_difference("User.count", -1) do
delete user_url(@user)
end
assert_redirected_to users_url
end
end