seeds.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. school.administrators << user
  18. school.save
  19. 10.times do |n|
  20. name = Faker::Name.name
  21. email = "example-#{n+1}@example.com"
  22. password = "password"
  23. login = "example_#{n+1}"
  24. birth_date = Faker::Date.between(15.years.ago, 70.years.ago)
  25. phone = Faker::PhoneNumber.cell_phone
  26. User.create!(name: name,
  27. email: email,
  28. login: login,
  29. password: password,
  30. password_confirmation: password,
  31. birth_date: birth_date,
  32. phone: phone,
  33. school: school)
  34. end
  35. conversation = Conversation.create!(name: "Important conversation")
  36. ConversationParticipation.create!(conversation: conversation, user: user)
  37. 10.times do |n|
  38. content = Faker::Lorem.sentence(10)
  39. Message.create!(user: user, conversation: conversation, content: content)
  40. end