seeds.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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