Sha256: 2947d29e96c95882966ec0d875fc26e693c9d101c1721c1398c1e11ae77aaacf

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 KB

Contents

require File.join(File.dirname(__FILE__),'..','spec_helper')
require 'ffaker'

def get_test_data(num=1000)
  file = File.join("spec","testdata","#{num}-data.txt")
  data = nil
  if File.exists?(file)
    data = open(file, 'r') {|f| Marshal.load(f)}
  else
    data = generate_fake_data(num)
    f = File.new(file, 'w')
    f.write Marshal.dump(data)
    f.close
  end
  data
end

private

PREFIX = ["Account", "Administrative", "Advertising", "Assistant", "Banking", "Business Systems", 
  "Computer", "Distribution", "IT", "Electronics", "Environmental", "Financial", "General", "Head", 
  "Laboratory", "Maintenance", "Medical", "Production", "Quality Assurance", "Software", "Technical", 
  "Chief", "Senior"] unless defined? PREFIX
SUFFIX = ["Clerk", "Analyst", "Manager", "Supervisor", "Plant Manager", "Mechanic", "Technician", "Engineer", 
  "Director", "Superintendent", "Specialist", "Technologist", "Estimator", "Scientist", "Foreman", "Nurse", 
  "Worker", "Helper", "Intern", "Sales", "Mechanic", "Planner", "Recruiter", "Officer", "Superintendent",
  "Vice President", "Buyer", "Production Supervisor", "Chef", "Accountant", "Executive"] unless defined? SUFFIX

def title
  prefix = PREFIX[rand(PREFIX.length)]
  suffix = SUFFIX[rand(SUFFIX.length)]

  "#{prefix} #{suffix}"
end

def generate_fake_data(num=1000,unique=false)
  res = {}
  num.times do |n|
    unique_prefix = ""
    if unique
      unique_prefix = "#{n}-#{Time.now.to_s}"
    end
    res[n.to_s] = {
      "FirstName" => Faker::Name.first_name + unique_prefix,
      "LastName" => Faker::Name.last_name + unique_prefix,
      "Email" =>  Faker::Internet.free_email + unique_prefix,
      "Company" => Faker::Company.name + unique_prefix,
      "JobTitle" => title + unique_prefix,
      "Phone1" => Faker::PhoneNumber.phone_number + unique_prefix
    }
  end
  res
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rhoconnect-4.0.4 spec/perf/perf_spec_helper.rb
rhoconnect-4.0.3 spec/perf/perf_spec_helper.rb
rhoconnect-4.0.2 spec/perf/perf_spec_helper.rb
rhoconnect-4.0.1 spec/perf/perf_spec_helper.rb
rhoconnect-4.0.0 spec/perf/perf_spec_helper.rb
rhoconnect-4.0.0.beta.24 spec/perf/perf_spec_helper.rb
rhoconnect-3.4.5 spec/perf/perf_spec_helper.rb
rhoconnect-4.0.0.beta.10 spec/perf/perf_spec_helper.rb
rhoconnect-4.0.0.beta.12 spec/perf/perf_spec_helper.rb
rhoconnect-3.4.4 spec/perf/perf_spec_helper.rb
rhoconnect-3.4.3 spec/perf/perf_spec_helper.rb
rhoconnect-3.4.2 spec/perf/perf_spec_helper.rb