Skip to content

Instantly share code, notes, and snippets.

@meskallito
Last active December 26, 2015 09:19
Show Gist options
  • Select an option

  • Save meskallito/7128913 to your computer and use it in GitHub Desktop.

Select an option

Save meskallito/7128913 to your computer and use it in GitHub Desktop.
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
# Following user should use 'Authorization' http header: Basic YWRtaW5AZXhhbXBsZS5jb206MTIzNDU2
require 'factory_girl'
FactoryGirl.find_definitions
[ User,
Organization,
Branch,
Department,
Employee,
DepartmentMembership,
BranchMembership,
Query,
Role,
Address,
PiDefinition,
PiAssignment ].each(&:destroy_all)
def torf
[true, false].sample
end
organization = FactoryGirl.create :organization
branches = FactoryGirl.create_list :branch, 50, organization: organization
departments = FactoryGirl.create_list :department, 50, organization: organization
pi_definitions = []
tags = %w(taxable insurable pensionable)
categories = %w(deduction benefit earning)
static_instructions = %W(pension_plan federal_tax provincial_tax employment_insurance)
10.times do |time|
pi_definition = FactoryGirl.create(:pi_definition,
organization: organization,
use_formula: true,
category: categories.sample,
formula: '1000 * value_from_context',
formula_code: "custom_instruction#{time}")
pi_definitions << pi_definition
FactoryGirl.create :pi_tag, name: tags.sample, pi_definition: pi_definition
end
tags.each { |tag| FactoryGirl.create :pi_tag, name: tag, pi_alias: 'salary' }
static_instructions.each do |static_alias|
PiAssignment.create(assignable: organization, for_all_employees: torf, enabled: torf, context: {}, pi_alias: static_alias)
end
pi_definitions.each do |definition|
PiAssignment.create(assignable: organization, for_all_employees: torf, enabled: torf, context: { value_from_context: 1 }, pi_definition: definition)
end
departments.each do |department|
static_instructions.sample(3).each do |static|
PiAssignment.create(assignable: department, for_all_employees: torf, enabled: torf, context: {}, pi_alias: static)
end
pi_definitions.sample(8).each do |definition|
PiAssignment.create(assignable: department, for_all_employees: torf, enabled: torf, context: { value_from_context: 0.1 }, pi_definition: definition)
end
end
branches.each do |branch|
static_instructions.sample(3).each do |static|
PiAssignment.create(assignable: branch, for_all_employees: torf, enabled: torf, context: {}, pi_alias: static)
end
pi_definitions.sample(8).each do |definition|
PiAssignment.create(assignable: branch, for_all_employees: torf, enabled: torf, context: { value_from_context: 0.2 }, pi_definition: definition)
end
end
1000.times do
employee = FactoryGirl.create :employee, organization: organization, primary_department_id: departments.sample.id, primary_branch_id: branches.sample.id
static_instructions.sample(2).each do |static|
PiAssignment.create(assignable: employee, for_all_employees: torf, enabled: torf, context: {}, pi_alias: static)
end
pi_definitions.sample(2).each do |definition|
PiAssignment.create(assignable: employee, for_all_employees: torf, enabled: torf, context: { value_from_context: 0.3 }, pi_definition: definition)
end
end
user = User.create email: 'admin@example.com', password: '123456'
user.add_role :provider_admin
user.confirm!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment