seeds.rb revision 040c1d8fca47a84f09d96ca3c21caa0a2ed91e05
# 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).
#
# Create Admin User
:admin => true,
:password => 'foobar'
# Create Team
team = Team.create! \
:name => 'Lorem Ipsum',
:admin_user => user
# Create some other users
user = User.create! \
:email => "#{name}@example.com",
:password => 'foobar'
# add two users to the first team
team.users << user if i < 2
end
# Create initial logic configuration.
Logic.create! \
name: 'OWL',
uri: 'http://purl.net/dol/logics/OWL',
extension: 'owl',
mimetype: 'application/rdf+xml'
Logic.create! \
name: 'CommonLogic',
uri: 'http://purl.net/dol/logics/CommonLogic',
extension: 'clif',
mimetype: 'text/plain'
# Import ontologies
Dir["#{Rails.root}/test/fixtures/ontologies/*/*.{clf,clif,owl}"].each do |file|
basename = File.basename(file)
o = Ontology.new \
uri: "file://db/seeds/#{basename}",
name: basename.split(".")[0].capitalize,
description: Faker::Lorem.paragraph
v = o.versions.build raw_file: File.open(file)
v.user = user
v.created_at = rand(60).minutes.ago
o.save!
end
# Add permissions
Ontology.find_each do |o|
o.permissions.create! \
subject: Team.first,
role: 'owner'
end
Ontology.first.permissions.create! \
subject: User.first,
role: 'editor'
# Add comments
5.times do |n|
c = Ontology.first.comments.build \
text: (1 + rand(4)).times.map{ Faker::Lorem.paragraph(5+rand(10)) }.join("\n\n")
c.user = User.first
c.created_at = (60 - n*5).minutes.ago
c.save!
end