
namespace :db do
  desc "Fill database with sample data"
  task populate: :environment do
    admin = User.create!(name: "Nathan Marley",
                         email: "nathan.marley@gmail.com",
                         password: "foobar",
                         password_confirmation: "foobar")
    admin.toggle!(:admin)
    3.times do |n|
      name     = Faker::Name.name
      email    = "example-#{n+1}@railstutorial.org"
      password = "password"
      User.create!(name: name,
                   email: email,
                   password: password,
                   password_confirmation: password)
    end
    users = User.all(limit: 6)
    35.times do
      #content = Faker::Lorem.sentence(5)
      #users.each { |user| user.microposts.create!(content: content) }
      name    = Faker::Lorem.sentence(2).slice(0, 40)
      users.each do |user|
        list = user.lists.create!(name: name)
        7.times do
            content = Faker::Lorem.sentence(3)
            item = list.items.create!(content: content)
        end
      end
    end
  end
end

