feat(test): Add comprehensive unit tests for all Rails models

- Create detailed unit tests for Party, TicketType, Ticket, User, and ApplicationRecord models
- Add fixture files for all models with valid test data
- Fix enum syntax in Party model for Rails 8 compatibility
- Add 60 total model tests covering validations, associations, and business logic
- Ensure all tests pass successfully

This provides full test coverage for the application's data models.
This commit is contained in:
kbe
2025-08-25 00:40:07 +02:00
parent 7f4aded5aa
commit 03717dc95b
8 changed files with 716 additions and 11 deletions

View File

@@ -6,23 +6,28 @@ class Party < ApplicationRecord
# published: Party is visible to public and can be discovered
# canceled: Party has been canceled by organizer
# sold_out: Party has reached capacity and tickets are no longer available
enum state: {
enum :state, {
draft: 0,
published: 1,
canceled: 2,
sold_out: 3
}, default: :draft
# === Relations ===
belongs_to :user
has_many :ticket_types, dependent: :destroy
has_many :tickets, through: :ticket_types
# Validations for party attributes
# Basic information
validates :name, presence: true, length: { minimum: 3, maximum: 100 }
validates :description, presence: true, length: { minimum: 10, maximum: 1000 }
validates :state, presence: true, inclusion: { in: states.keys }
# Venue information
validates :venue_name, presence: true, length: { maximum: 100 }
validates :venue_address, presence: true, length: { maximum: 200 }
# Geographic coordinates for map display
validates :latitude, presence: true, numericality: {
greater_than_or_equal_to: -90,
@@ -37,4 +42,4 @@ class Party < ApplicationRecord
scope :featured, -> { where(featured: true) } # Get featured parties for homepage
scope :published, -> { where(state: :published) } # Get publicly visible parties
scope :search_by_name, ->(query) { where("name ILIKE ?", "%#{query}%") } # Search by name (case-insensitive)
end
end