class Object

Public Instance Methods

batch_create(count) { || ... } click to toggle source
# File lib/shared_sample_data.rb, line 26
def batch_create(count)
  ActiveRecord::Base.transaction do
    if Rails.env.development?
      bar = RakeProgressbar.new(count)
      count.times do
        bar.inc
        yield
      end
      bar.finished
    else
      count.times { yield }
    end
  end
end
create_non_active_student(predefined_student = nil) click to toggle source
# File lib/shared_sample_data.rb, line 117
def create_non_active_student(predefined_student = nil)
  if predefined_student
    Gaku::Student.where(predefined_student).first_or_create!
  else
    random_student = random_person.merge(enrollment_status_code: @enrollment_status_applicant)
    Gaku::Student.where(random_student).first_or_create!
  end
end
create_student_with_full_info(predefined_student = nil) click to toggle source
# File lib/shared_sample_data.rb, line 90
def create_student_with_full_info(predefined_student = nil)
  if predefined_student
    student = Gaku::Student.where(predefined_student).first_or_create!
  else
    random_student = random_person.merge(enrollment_status_code: @enrollment_status)
    student = Gaku::Student.where(random_student).first_or_create!
  end

  student.addresses.where(random_address).first_or_create!

  [random_email, random_home_phone, random_mobile_phone].each do |params|
    Gaku::ContactCreation.new(params.merge(contactable: student)).save!
  end

  student.notes.where(random_note).first_or_create!
  student.notes.where(random_note).first_or_create!

  guardian = Gaku::Guardian.where(random_person).first_or_create!
  guardian.addresses.where(random_address).first_or_create!

  [random_email, random_home_phone, random_mobile_phone].each do |params|
    Gaku::ContactCreation.new(params.merge(contactable: guardian)).save!
  end

  student.guardians << guardian
end
create_teacher_with_full_info(predefined_teacher = nil) click to toggle source
# File lib/shared_sample_data.rb, line 126
def create_teacher_with_full_info(predefined_teacher = nil)
  if predefined_teacher
    teacher = Gaku::Teacher.where(predefined_teacher).first_or_create!
  else
    random_teacher = random_person
    teacher = Gaku::Teacher.where(random_teacher).first_or_create!
  end

  teacher.addresses.create!(random_address)

  [random_email, random_home_phone, random_mobile_phone].each do |params|
    Gaku::ContactCreation.new(params.merge(contactable: teacher)).save!
  end

  teacher.notes.create!(random_note)
  teacher.notes.create!(random_note)
end
random_address() click to toggle source
# File lib/shared_sample_data.rb, line 78
def random_address
  {
    address1: FFaker::Address.street_address,
    address2: FFaker::Address.street_address,
    title: 'Home address',
    zipcode: '452-0813',
    city: 'Nagoya',
    country: @country,
    state: @state
  }
end
random_email() click to toggle source
# File lib/shared_sample_data.rb, line 64
def random_email
  {
    data: FFaker::Internet.email,
    contact_type_id: @email.id
  }
end
random_home_phone() click to toggle source
# File lib/shared_sample_data.rb, line 50
def random_home_phone
  {
    data: FFaker::PhoneNumber.phone_number,
    contact_type_id: @home_phone.id
  }
end
random_mobile_phone() click to toggle source
# File lib/shared_sample_data.rb, line 57
def random_mobile_phone
  {
    data: FFaker::PhoneNumber.phone_number,
    contact_type_id: @mobile_phone.id
  }
end
random_note() click to toggle source
# File lib/shared_sample_data.rb, line 71
def random_note
  {
    title: FFaker::Lorem.word,
    content: FFaker::Lorem.sentence
  }
end
random_person() click to toggle source
# File lib/shared_sample_data.rb, line 41
def random_person
  {
    name: FFaker::Name.first_name,
    middle_name: FFaker::Name.first_name,
    surname: FFaker::Name.last_name,
    birth_date: Date.today - rand(1000)
  }
end