Skip to content

Instantly share code, notes, and snippets.

@CodePint
Created May 17, 2018 20:27
Show Gist options
  • Save CodePint/a559c6d9dd9ffe9e9173c670d3e8c442 to your computer and use it in GitHub Desktop.
Save CodePint/a559c6d9dd9ffe9e9173c670d3e8c442 to your computer and use it in GitHub Desktop.
# 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 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)
## Creating users
# All users are actually given {climber: true} by default, See test_climber.
users = [
@test_climber = User.create!(email: 'testing@climber.com', password: '123456', first_name: 'test', last_name: 'test',
user_name: 'test_climber'),
@grumpy_climber = User.create!(email: 'mean@user.com', password: '123456', first_name: 'Mike', last_name: 'Lloyd',
user_name: 'grumpy_climber_mike', climber: true),
@cool_route_setter = User.create!(email: 'cool_route_setter@user.com', password: '123456', first_name: 'Helen', last_name: 'May',
user_name: 'cool_setter_helen', climber: true, route_setter: true),
@old_gym_owner = User.create!(email: 'old_gym_owner@user.com', password: '123456', first_name: 'Bruce', last_name: 'Willis',
user_name: 'old_owner_bruce', climber: true, gym_owner: true),
@newbie_climber = User.create!(email: 'newbie_climber@user.com', password: '123456', first_name: 'George', last_name: 'Sterling',
user_name: 'newbie_climber_george', climber: true),
@easy_route_setter = User.create!(email: 'easy_route_setter@user.com', password: '123456', first_name: 'Geoff', last_name: 'Smith',
user_name: 'easy_setter_geoff', climber: true, route_setter: true),
@set_and_own = User.create!(email: 'set_and_own@user.com', password: '123456', first_name: 'Jill', last_name: 'Jones',
user_name: 'set_own_jill', climber: true, route_setter: true, gym_owner: true),
@north_owner = User.create!(email: 'north_owner@user.com', password: '123456', first_name: 'Adam', last_name: 'Shields',
user_name: 'north_owner', climber: true, gym_owner: true)
]
## Creating gyms
gyms = [
@stronghold_gym = Gym.create!(gym_name: "Stronghold gym", about: "Brand new bouldering gym in Tottenham Hale",
address: "Tottenham Hale, London", email: "stronghold@gmail.com" ),
@castle_climbing_gym = Gym.create!( gym_name: "The Castle Gym", about: "Classic multi story climbing gym in central london",
address: "Finsbury Park, London", email: "castleclimbing@gmail.com" ),
@the_works_gym = Gym.create!(gym_name: "The Works Gym", about: "Bouldering centre in south Sheffield",
address: "Heeley, Sheffield", email: "theworksgym@gmail.com" )
]
## Creating routes
routes = [
Route.create!(user_id: @cool_route_setter.id, gym_id: @stronghold_gym.id, identifier: "Knee bar extreme",
route_setter_comments: "jam the knee in!", grade: 3),
Route.create!(user_id: @cool_route_setter.id, gym_id: @stronghold_gym.id, identifier: "Heel hook fun",
route_setter_comments: "hook the heel in!", grade: 7),
Route.create!(user_id: @easy_route_setter.id, gym_id: @castle_climbing_gym.id, identifier: "High ball view",
route_setter_comments: "dont look down!", grade: 5),
Route.create!(user_id: @easy_route_setter.id, gym_id: @castle_climbing_gym.id, identifier: "Slab slip",
route_setter_comments: "try not to slip!", grade: 2),
Route.create!(user_id: @set_and_own.id, gym_id: @the_works_gym.id, identifier: "northern number",
route_setter_comments: "find me on the north wall.", grade: 6),
Route.create!(user_id: @set_and_own.id, gym_id: @the_works_gym.id, identifier: "peak practice",
route_setter_comments: "hone your skills here.", grade: 1)
]
## creating climbs
# completion_type_local = ["Flash", "On-sight", "Sent", "Unsent"]
climb_comments = ["Great climb", "Wow, jeeze that was tough", "Send it!", "Ill come back to this one.",
"grade was soft", "hard for the grade", "Really enjoyed this route"]
climbs = []
def create_climbs(comments, climbs, routes, users)
routes.each do |route|
users.each do |user|
completion_type_rand = (Climb::COMPLETION_TYPE).sample
grade_rating = rand((route.grade - 1)..(route.grade + 1))
if completion_type_rand != "Unsent"
completed = true
end
if completed
completed_count = rand(1..3)
end
climb_report = route.climbs.create!(
user_id: user.id, climb_comment: comments.sample, completion_type: completion_type_rand,
completed: completed, attempt_count: rand(1..10), completed_count: completed_count,
grade_rating: grade_rating, enjoy_rating: rand(1..10)
)
climbs << climb_report
end
end
end
create_climbs(climb_comments, climbs, routes, users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment