2024-12-31 16:34:52 +08:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class UsersSignupTest < ActionDispatch::IntegrationTest
|
2025-01-06 18:38:39 +08:00
|
|
|
|
|
|
|
def setup
|
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
end
|
|
|
|
|
2024-12-31 16:34:52 +08:00
|
|
|
test "invalid signup information" do
|
|
|
|
get signup_path
|
2025-01-04 10:21:22 +08:00
|
|
|
assert_no_difference "User.count" do
|
2024-12-31 16:34:52 +08:00
|
|
|
post users_path, params: { user: { name: "",
|
|
|
|
email: "user@invalid",
|
|
|
|
password: "foo",
|
|
|
|
password_confirmation: "bar" } }
|
|
|
|
end
|
2025-01-04 10:21:22 +08:00
|
|
|
assert_template "users/new"
|
|
|
|
assert_select "div#error_explanation"
|
|
|
|
assert_select "div.alert-danger"
|
2024-12-31 16:34:52 +08:00
|
|
|
end
|
|
|
|
|
2025-01-06 18:38:39 +08:00
|
|
|
test "valid signup information with account activation" do
|
2024-12-31 16:34:52 +08:00
|
|
|
get signup_path
|
2025-01-04 10:21:22 +08:00
|
|
|
assert_difference "User.count", 1 do
|
|
|
|
post users_path, params: { user: { name: "Example User",
|
2025-01-06 18:38:39 +08:00
|
|
|
email: "user@example.com",
|
|
|
|
password: "password",
|
|
|
|
password_confirmation: "password" } }
|
2024-12-31 16:34:52 +08:00
|
|
|
end
|
2025-01-06 18:38:39 +08:00
|
|
|
# follow_redirect!
|
|
|
|
# assert_template "users/show"
|
|
|
|
# assert_not flash.notice
|
|
|
|
# assert is_logged_in?
|
|
|
|
|
|
|
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
|
|
user = assigns(:user)
|
|
|
|
assert_not user.activated?
|
|
|
|
# 尝试激活前登陆
|
|
|
|
log_in_as(user)
|
|
|
|
assert_not is_logged_in?
|
|
|
|
# 激活令牌无效
|
|
|
|
get edit_account_activation_path("invalid token", email: user.email)
|
|
|
|
assert_not is_logged_in?
|
|
|
|
# 令牌有效,邮箱错误
|
|
|
|
get edit_account_activation_path(user.activation_token, email: 'wrong')
|
|
|
|
assert_not is_logged_in?
|
|
|
|
# 令牌有效
|
|
|
|
get edit_account_activation_path(user.activation_token, email: user.email)
|
|
|
|
assert user.reload.activated?
|
2024-12-31 16:34:52 +08:00
|
|
|
follow_redirect!
|
2025-01-06 18:38:39 +08:00
|
|
|
assert_template 'users/show'
|
2025-01-02 11:59:27 +08:00
|
|
|
assert is_logged_in?
|
2024-12-31 16:34:52 +08:00
|
|
|
end
|
|
|
|
end
|