49 lines
1.2 KiB
Ruby
49 lines
1.2 KiB
Ruby
|
require "test_helper"
|
||
|
|
||
|
class UserTest < ActiveSupport::TestCase
|
||
|
test "full name returns first and last name" do
|
||
|
assert_equal "Trevor Vallender", users(:trevor).full_name
|
||
|
end
|
||
|
|
||
|
test "username must exist" do
|
||
|
assert_must_exist(users(:trevor), "username")
|
||
|
end
|
||
|
|
||
|
test "username must be unique" do
|
||
|
user1 = User.first
|
||
|
user2 = User.second
|
||
|
user1.username = user2.username
|
||
|
assert_not user1.valid?
|
||
|
end
|
||
|
|
||
|
test "email must exist" do
|
||
|
assert_must_exist(users(:trevor), "email")
|
||
|
end
|
||
|
|
||
|
test "email must be unique" do
|
||
|
user1 = User.first
|
||
|
user2 = User.second
|
||
|
user1.email = user2.email
|
||
|
assert_not user1.valid?
|
||
|
end
|
||
|
|
||
|
test "email must be a valid email" do
|
||
|
user = users(:trevor)
|
||
|
user.email = "trevor"
|
||
|
assert_not user.valid?
|
||
|
assert_includes user.errors[:email], "must be a valid email address"
|
||
|
end
|
||
|
|
||
|
test "first name must exist" do
|
||
|
assert_must_exist(users(:trevor), "first_name")
|
||
|
end
|
||
|
|
||
|
test "password reset token is invalid after password changed" do
|
||
|
user = users(:trevor)
|
||
|
token = user.generate_token_for(:password_reset)
|
||
|
assert_equal user, User.find_by_token_for(:password_reset, token)
|
||
|
user.update(password: "new_password")
|
||
|
assert_nil User.find_by_token_for(:password_reset, token)
|
||
|
end
|
||
|
end
|