Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com> This commit refactors the entire application to replace the 'parties' concept with 'events'. All controllers, models, views, and related files have been updated to reflect this change. The parties table has been replaced with an events table, and all related functionality has been updated accordingly.
66 lines
2.4 KiB
Ruby
Executable File
66 lines
2.4 KiB
Ruby
Executable File
require "test_helper"
|
|
|
|
class UserTest < ActiveSupport::TestCase
|
|
# Test that User model exists
|
|
test "should be a class" do
|
|
assert_kind_of Class, User
|
|
end
|
|
|
|
# Test Devise modules
|
|
test "should include devise modules" do
|
|
user = User.new
|
|
assert user.respond_to?(:email)
|
|
assert user.respond_to?(:encrypted_password)
|
|
end
|
|
|
|
# Test associations
|
|
test "should have many events" do
|
|
association = User.reflect_on_association(:events)
|
|
assert_equal :has_many, association.macro
|
|
assert_equal :destroy, association.options[:dependent]
|
|
end
|
|
|
|
test "should have many tickets" do
|
|
association = User.reflect_on_association(:tickets)
|
|
assert_equal :has_many, association.macro
|
|
assert_equal :destroy, association.options[:dependent]
|
|
end
|
|
|
|
# Test first_name validations
|
|
test "should validate presence of first_name" do
|
|
user = User.new(last_name: "Doe")
|
|
refute user.valid?, "User with blank first_name should be invalid"
|
|
assert_not_nil user.errors[:first_name], "No validation error for blank first_name"
|
|
end
|
|
|
|
test "should validate length of first_name" do
|
|
# Test minimum length
|
|
user = User.new(first_name: "A", last_name: "Doe")
|
|
refute user.valid?, "User with first_name shorter than 3 chars should be invalid"
|
|
assert_not_nil user.errors[:first_name], "No validation error for too short first_name"
|
|
|
|
# Test maximum length
|
|
user = User.new(first_name: "A" * 13, last_name: "Doe")
|
|
refute user.valid?, "User with first_name longer than 12 chars should be invalid"
|
|
assert_not_nil user.errors[:first_name], "No validation error for too long first_name"
|
|
end
|
|
|
|
# Test last_name validations
|
|
test "should validate presence of last_name" do
|
|
user = User.new(first_name: "John")
|
|
refute user.valid?, "User with blank last_name should be invalid"
|
|
assert_not_nil user.errors[:last_name], "No validation error for blank last_name"
|
|
end
|
|
|
|
test "should validate length of last_name" do
|
|
# Test minimum length
|
|
user = User.new(first_name: "John", last_name: "Do")
|
|
refute user.valid?, "User with last_name shorter than 3 chars should be invalid"
|
|
assert_not_nil user.errors[:last_name], "No validation error for too short last_name"
|
|
|
|
# Test maximum length
|
|
user = User.new(first_name: "John", last_name: "D" * 13)
|
|
refute user.valid?, "User with last_name longer than 12 chars should be invalid"
|
|
assert_not_nil user.errors[:last_name], "No validation error for too long last_name"
|
|
end
|
|
end |