Sprankelprachtig aan/afmeldsysteem

seeds.rb 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # This file should contain all the record creation needed to seed the database with its default values.
  2. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
  3. #
  4. # Examples:
  5. #
  6. # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
  7. # Character.create(name: 'Luke', movie: movies.first)
  8. require 'byebug'
  9. exit if Rails.env.production?
  10. its_me = Person.create!(
  11. first_name: 'Maarten',
  12. infix: 'van den',
  13. last_name: 'Berg',
  14. email: 'maarten@maartenberg.nl',
  15. is_admin: true
  16. )
  17. User.create!(
  18. email: 'maarten@maartenberg.nl',
  19. person: its_me,
  20. password: 'aardbei123',
  21. password_confirmation: 'aardbei123',
  22. confirmed: true
  23. )
  24. Person.create!(
  25. first_name: 'Henkie',
  26. last_name: 'Gekke',
  27. email: 'gekkehenkie@maartenberg.nl'
  28. )
  29. default_test_group = Group.create!(
  30. name: 'Teststam'
  31. )
  32. 2.times do
  33. Group.create!(
  34. name: Faker::Team.name
  35. )
  36. end
  37. 15.times do
  38. Person.create!(
  39. first_name: Faker::Name.first_name,
  40. last_name: Faker::Name.last_name,
  41. email: "testuser#{i}@maartenberg.nl"
  42. )
  43. end
  44. Activity.create!(
  45. name: 'Fikkie stoken ofzo',
  46. description: 'Een scout trekt er samen met anderen op uit',
  47. location: 'In het bos in het bos',
  48. start: 4.weeks.since,
  49. end: 4.weeks.since + 2.hours,
  50. deadline: 3.weeks.since,
  51. group: default_test_group
  52. )
  53. Group.all.each do |g|
  54. 10.times do
  55. starttime = Faker::Time.between(Time.zone.now, 1.year.since, :morning)
  56. endtime = Faker::Time.between(1.hour.since(starttime), 1.day.since(starttime), :afternoon)
  57. deadline = 5.days.ago(starttime)
  58. Activity.create!(
  59. name: Faker::Hacker.ingverb,
  60. description: Faker::Hipster.sentence,
  61. location: Faker::Address.city,
  62. start: starttime,
  63. end: endtime,
  64. deadline: deadline,
  65. group: g,
  66. no_response_action: Faker::Boolean.boolean
  67. )
  68. end
  69. end
  70. Person.all.each do |p|
  71. Group.all.each do |g|
  72. next unless Faker::Boolean.boolean(0.75)
  73. Member.create!(
  74. person: p,
  75. group: g,
  76. is_leader: Faker::Boolean.boolean(0.1)
  77. )
  78. g.activities.each do |a|
  79. notes = (Faker::Hipster.sentence if Faker::Boolean.boolean(0.15))
  80. # Participants are created on adding to group, no need to create
  81. part = Participant.find_by(
  82. activity: a,
  83. person: p
  84. )
  85. part.update!(
  86. is_organizer: Faker::Boolean.boolean(0.1),
  87. attending: [true, false, nil].sample,
  88. notes: notes
  89. )
  90. end
  91. end
  92. end