seeds.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. school = School.create!(name: "Fakeville High")
  9. user = User.create!(name: "Example User",
  10. login: "example",
  11. email: "example@example.com",
  12. password: "foobar",
  13. password_confirmation: "foobar",
  14. birth_date: 15.years.ago,
  15. phone: "(333) 333-3333",
  16. school: school,
  17. admin: true)
  18. school.administrators << user
  19. school.save
  20. 10.times do |n|
  21. name = Faker::Name.name
  22. email = "example-#{n+1}@example.com"
  23. password = "password"
  24. login = "example_#{n+1}"
  25. birth_date = Faker::Date.between(15.years.ago, 70.years.ago)
  26. phone = Faker::PhoneNumber.cell_phone
  27. User.create!(name: name,
  28. email: email,
  29. login: login,
  30. password: password,
  31. password_confirmation: password,
  32. birth_date: birth_date,
  33. phone: phone,
  34. school: school)
  35. end
  36. conversation = Conversation.create!(name: "Important conversation")
  37. ConversationParticipation.create!(conversation: conversation, user: user)
  38. 10.times do |n|
  39. content = Faker::Lorem.sentence(10)
  40. Message.create!(user: user, conversation: conversation, content: content)
  41. end
  42. 10.times do |n|
  43. name = Faker::Educator.course
  44. course = Course.create!(school: school, name: name, starts_on: DateTime.now, ends_on: 6.months.since)
  45. CourseParticipation.create!(course: course, user: user, role: :teacher)
  46. CourseParticipation.create!(course: course, user: User.find(2), role: :student)
  47. end
  48. 10.times do |n|
  49. description = Faker::Lorem.sentence(10)
  50. location = Faker::Address.street_address
  51. course = Course.find(1)
  52. start_at = (n + 1).hours.ago
  53. end_at = n.hours.ago
  54. Lecture.create(course: course, description: description, location: location, starts_at: start_at, ends_at: end_at)
  55. end
  56. 10.times do |n|
  57. description = Faker::Lorem.paragraph
  58. name = Faker::Lorem.sentence(2)
  59. course = Course.find(Faker::Number.between(1, 10))
  60. due_at = Faker::Number.between(1, 10).days.since
  61. Assignment.create(course: course, name: name, description: description, due_at: due_at)
  62. end
  63. 5.times do |n|
  64. name = Faker::Lorem.sentence(4)
  65. content = Faker::Lorem.paragraph
  66. course = Course.find(1)
  67. NewsPost.create(user: user, content: content, name: name, news_feed: course)
  68. end