Files
aperonight/test/models/user_test.rb
Kevin BATAILLE 884c6a8262 feat(auth): enhance user registration with names and improve UI
- Add first_name and last_name fields to User model with validations
- Configure Devise registrations controller to accept name parameters
- Update registration form with name fields and improved styling
- Replace Twitter Bootstrap pagination with custom Tailwind components
- Add French locale translations for pagination and models
- Update header styling with responsive design improvements
- Add EditorConfig for consistent code formatting
- Fix logout controller URL handling and improve JavaScript
- Update seed data and test fixtures with name attributes
- Add comprehensive model tests for name validations
- Add test.sh script for easier test execution

💘 Generated with Crush
Co-Authored-By: Crush <crush@charm.land>
2025-08-26 17:17:50 +02:00

66 lines
2.4 KiB
Ruby

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 parties" do
association = User.reflect_on_association(:parties)
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