Examples

Real-world examples of using FakeDataDSL.

E-Commerce Application

# schemas/ecommerce.dsl
User:
  id: uuid
  email: email unique
  name: name
  created_at: past_date(days: 365)

Product:
  id: uuid
  name: product_name
  category: product_category
  price: money(min: 10, max: 1000)
  sku: sku

Order:
  id: uuid
  user_id: reference(User, id)
  product_id: reference(Product, id)
  quantity: number(1..10)
  total: formula(quantity * price)
  status: enum(placed: 60%, processing: 30%, shipped: 10%)
  created_at: past_date(days: 30)

Social Media Platform

# schemas/social.dsl
User:
  id: uuid
  username: username unique
  email: email unique
  full_name: full_name
  bio: text(50..200) optional
  avatar_url: url optional
  created_at: past_date(days: 730)

Post:
  id: uuid
  author_id: reference(User, id)
  content: text(100..1000)
  likes: number(0..10000)
  created_at: past_date(days: 30)

Comment:
  id: uuid
  post_id: reference(Post, id)
  author_id: reference(User, id)
  content: text(10..500)
  created_at: past_date(days: 7)

Healthcare System

# schemas/healthcare.dsl
Patient:
  id: uuid
  first_name: first_name
  last_name: last_name
  date_of_birth: past_date(days: 36500)  # ~100 years
  blood_type: blood_type
  medical_record_number: medical_code(type: :icd10)

VitalSigns:
  patient_id: reference(Patient, id)
  heart_rate: heart_rate(min: 60, max: 100)
  bmi: bmi(range: 18.5..30.0)
  recorded_at: past_date(days: 7)

Diagnosis:
  patient_id: reference(Patient, id)
  code: medical_code(type: :icd10)
  description: text(50..500)
  diagnosed_at: past_date(days: 365)

Financial Application

# schemas/finance.dsl
Account:
  id: uuid
  account_number: account_number
  bank_name: bank_name
  iban: iban(country: :us)
  balance: transaction_amount(min: 0, max: 100000)
  currency: currency

Transaction:
  id: uuid
  from_account_id: reference(Account, id)
  to_account_id: reference(Account, id)
  amount: transaction_amount(min: 1, max: 10000)
  currency: currency
  status: enum(pending: 20%, completed: 75%, failed: 5%)
  created_at: past_date(days: 30)

Payment:
  id: uuid
  account_id: reference(Account, id)
  credit_card: credit_card(type: :visa)
  amount: transaction_amount(min: 10, max: 1000)
  status: enum(approved: 90%, declined: 10%)
  processed_at: past_date(days: 7)

Testing Scenarios

Edge Case Testing

# Generate edge cases
schema = registry.schema('User')
edge_records = schema.generate_many(100, mode: :edge)

# Test validation
edge_records.each do |record|
  validate_user(record)  # Should handle edge cases
end

Invalid Data Testing

# Generate invalid data
invalid_records = schema.generate_many(100, mode: :invalid)

# Test error handling
invalid_records.each do |record|
  expect { create_user(record) }.to raise_error(ValidationError)
end

Performance Testing

# Generate with latency
User:
  @latency 50ms..200ms
  id: uuid
  name: name

# Measure generation time
start = Time.now
records = schema.generate_many(1000)
duration = Time.now - start
puts "Generated 1000 records in #{duration}s"

See Also