-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
1 addition
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'faker' | ||
|
||
# frozen_string_literal: true | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) | ||
# Character.create(name: "Luke", movie: movies.first) | ||
|
||
## User Seeds for local dev testing and setup. | ||
|
||
LOCATIONS = ['Nairobi', 'Mombasa', # Kenya | ||
'Kampala', 'Entebbe', # Uganda | ||
'Dar es Salaam', 'Arusha', # Tanzania | ||
'Bujumbura', 'Gitega', # Burundi | ||
'Kigali', 'Butare'].freeze # Rwanda | ||
|
||
def build_user | ||
user = User.new | ||
|
||
user.email = Faker::Internet.email | ||
pass = Faker::Internet.password | ||
user.password = pass | ||
user.password_confirmation = pass | ||
user.github_username = Faker::Internet.username | ||
user.name = Faker::Name.name | ||
user.phone_number = Faker::Number.number(digits: 10) | ||
|
||
user.save if user.valid? | ||
end | ||
|
||
def build_country | ||
country = Country.new | ||
|
||
country.name = %w[Kenya Uganda Tanzania Rwanda Burundi].sample | ||
|
||
country.save if country.valid? | ||
end | ||
|
||
def build_chapter | ||
chapter = Chapter.new | ||
|
||
chapter.name = [Faker::Name.middle_name.to_s, 'Chapter'].join(' ') | ||
chapter.country = Country.all.sample | ||
chapter.location = LOCATIONS.sample | ||
chapter.description = "The East African chapter in #{chapter.location}" | ||
|
||
chapter.save if chapter.valid? | ||
end | ||
|
||
10.times do | ||
build_user | ||
end | ||
|
||
5.times do | ||
build_country | ||
end | ||
|
||
10.times do | ||
build_chapter | ||
end | ||
# Character.create(name: "Luke", movie: movies.first) |