<commit_before>require_relative '../models/message.rb'
require_relative '../models/package.rb'
require_relative '../models/patron.rb'
require_relative '../models/pool.rb'
require_relative '../models/locker.rb'
require 'securerandom'

FactoryGirl.define do
  factory :pool do
    name 'empty_pool'

    # Create a pool with patrons
    factory :pool_with_patrons do
      name 'busy_pool'
      after(:create) do |pool|
        create_list(:patron, 5, pool: pool)
      end
    end

    # Throw patrons in this pool by default
    factory :default_pool do
      name 'default_pool'
    end

    after(:create) do |pool|
      pool.save
    end
  end

  factory :message do
    association :to, factory: :patron
    factory(:hello_msg) { text 'Oh hai' }
  end

  factory :package do

    # A received package
    factory(:received_pack) do
      received true
      en_route true
      assigned true
      failed false
    end

    # A package en route
    factory(:en_route_pack) do
      received false
      en_route true
      assigned true
      failed false
    end

    # An assigned package
    factory(:assigned_pack) do
      received false
      en_route false
      assigned true
      failed false
    end

    # A failed package
    factory(:failed_pack) { failed true }

    before(:create) do |package|
      # Set the default hungry man
      if package.hungry_man.nil?
        create(:hman) unless Patron.where(_id: 'hman').exists?
        package.hungry_man = Patron.find('hman')
      end
      # Set the default delivery man
      if package.delivery_man.nil?
        create(:dman) unless Patron.where(_id: 'dman').exists?
        package.delivery_man = Patron.find('dman')
      end
    end
  end

  # Create a patron
  factory :patron do
    slack_user false

    # Delivery man
    factory(:dman) do
      slack_user_id 'dman'
      _id 'dman'
    end

    # Hungry man
    factory(:hman) do
      slack_user_id 'hman'
      _id 'hman'
    end

    # Automatically add the patron to a pool, creating the pool if needed.
    before(:create) do |patron|
      if patron.pool.nil?
        create(:default_pool) unless Pool.where(name: 'default_pool').exists?
        patron.pool = Pool.where(name: 'default_pool').first
      end
    end
  end
end<commit_msg>Updated factories<commit_after>require_relative '../models/message.rb'
require_relative '../models/package.rb'
require_relative '../models/patron.rb'
require_relative '../models/pool.rb'
require_relative '../models/locker.rb'
require 'securerandom'

FactoryGirl.define do
  factory :pool do
    name 'empty_pool'

    # Create a pool with patrons
    factory :pool_with_patrons do
      name 'busy_pool'
      after(:create) do |pool|
        create_list(:patron, 5, pool: pool)
      end
    end

    # Throw patrons in this pool by default
    factory :default_pool do
      name 'default_pool'
    end

    after(:create) do |pool|
      pool.save
    end
  end

  factory :message do
    association :to, factory: :patron
    factory(:hello_msg) { text 'Oh hai' }
  end

  factory :package do

    # A received package
    factory(:received_pack) do
      received true
      en_route true
      assigned true
      failed false
    end

    # A package en route
    factory(:en_route_pack) do
      received false
      en_route true
      assigned true
      failed false
    end

    # An assigned package
    factory(:assigned_pack) do
      received false
      en_route false
      assigned true
      failed false
    end

    # A failed package
    factory(:failed_pack) { failed true }

    before(:create) do |package|
      # Set the default hungry man
      if package.hungry_man.nil?
        create(:hman) unless Patron.where(_id: 'hman').exists?
        package.hungry_man = Patron.find('hman')
      end
      # Set the default delivery man
      if package.delivery_man.nil?
        create(:dman) unless Patron.where(_id: 'dman').exists?
        package.delivery_man = Patron.find('dman')
      end
    end
  end

  # Create a patron
  factory :patron do
    slack_user false

    # Slack patron
    factory(:slack_patron) do
      slack_user_id 'xxx'
      slack_user = true
    end

    # Delivery man
    factory(:dman) do
      slack_user_id 'dman'
      _id 'dman'
    end

    # Hungry man
    factory(:hman) do
      slack_user_id 'hman'
      _id 'hman'
    end

    # Automatically add the patron to a pool, creating the pool if needed.
    before(:create) do |patron|
      if patron.pool.nil?
        create(:default_pool) unless Pool.where(name: 'default_pool').exists?
        patron.pool = Pool.where(name: 'default_pool').first
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0863324764353042, 'fraction_numerical': 0.0004284490145672665, 'mean_word_length': 2.378437047756874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5478059', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1424, 'n_words': 425}