Skip to content

Instantly share code, notes, and snippets.

@johnmarinelli
Created December 28, 2015 00:07
Show Gist options
  • Save johnmarinelli/cde642d098359968e3f4 to your computer and use it in GitHub Desktop.
Save johnmarinelli/cde642d098359968e3f4 to your computer and use it in GitHub Desktop.
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
include FactoryGirl::Syntax::Methods
# Add more helper methods to be used by all tests here...
end
module FixtureFileHelpers
@@emails = []
@@numbers = []
@@count = 1
def create_applicants(num_of_applicants, start_date, end_date)
applicants = []
1.upto(num_of_applicants) do |a|
applicants.push(create_applicant(random_date start_date, end_date))
@@count = @@count + 1
end
applicants.join '\n'
end
def create_applicant(date_created)
app = %Q(
fix_#{@@count}:
first_name: first_#{@@count}
last_name: last_#{@@count}
email: #{random_email}
phone: #{random_phone}
phone_type: #{ Applicant::PHONE_TYPES.first }
workflow_state: #{ Applicant::WORKFLOW_STATES.first }
region: #{ Applicant::REGIONS.first }
created_at: #{ date_created }
)
end
def random_email
u = random_string 5
domain = random_string 5
@@emails.push("#{u}@#{domain}.com").last
end
def random_phone
@@numbers.push(random_number 9).last
end
def random_date(start_date, end_date)
r = (start_date..end_date)
len = r.count
r.to_a.shuffle[0, len].first
end
private
def random_string(len)
random len: len
end
def random_number(len)
random range: (1..9), len: len
end
def random(range: ('a'..'z'), len: )
range.to_a.shuffle[0, len].join
end
end
ActiveRecord::FixtureSet.context_class.send :include, FixtureFileHelpers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment