Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (58 sloc) 1.59 KB
# -*- encoding: utf-8 -*-
# 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 rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
#
# helpers
def seed_section(title)
section "BEGIN: #{title}"
yield if block_given?
section "END"
end
def section(message)
$stdout.puts "\n"
$stdout.puts "== #{message}"
$stdout.puts "\n"
end
def info(message)
$stdout.puts "-- #{message}"
end
# seeds
seed_section 'Admin user' do
email = 'admin@notedetengas.es'
info "Creating the admin user with the email '#{email}'."
if User.find_by_email(email)
info "The user exists. Skipping."
else
User.create(email: email,
password: 'admin123',
password_confirmation: 'admin123')
info "User created."
end
end
seed_section 'Categories' do
%w(Música Cine).each do |name|
info "Creating the category '#{name}'."
if Category.find_by_slug(name.parameterize)
info "The category '#{name}' exists. Skipping."
else
Category.create(name: name)
info "Category '#{name}' created."
end
end
end
seed_section 'Cities' do
%w(Madrid Valladolid Barcelona).each do |name|
info "Creating the city '#{name}'."
if City.find_by_name(name)
info "The city '#{name}' exists. Skipping."
else
City.create(name: name)
info "City '#{name}' created."
end
end
end