Skip to content

Commit

Permalink
Creates seed data per #32 - still needs sane values for the positions…
Browse files Browse the repository at this point in the history
… table
  • Loading branch information
August committed Feb 28, 2012
1 parent 8e7c453 commit 23f7eba
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
# 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).

#It's important to use find_or_create_by_{attribute} so as to prevent duplicate creation of records

# Populate the 3 major 'kinds' of content we know as of now.
# There is discussion to move this to a static array / config elsewhere,
# but I don't have a solid grasp on the system-wide reprecussions of that
# change at the moment.
kinds = Kind.create([{:name => 'Graphics'}, {:name => 'Ticker'}, {:name => 'Text'}])

["Graphics", "Ticker", "Text"].each do |kind|
Kind.find_or_create_by_name kind
end

# Establish the 4 major display areas a template usually has.
# In my quick sample, this code will make 68% of the Concerto 1 fields match
# up correct with the new Concerto 2 fields. Magic will have to handle the other
# 42% of fields with stranger names like "Graphics (Full-Screen)"
kinds.each do |kind|
# We use a verbose (and ineffecient) query to find the type
# because the create statement doesn't garuntee success,
# in that case we'll hope a duplicate existed and blocked the validation.
field = Field.create({:name => kind.name, :kind => Kind.where(:name => kind.name).first})

Kind.all.each do |kind|
field = Field.find_or_create_by_name({:name => kind.name, :kind => Kind.where(:name => kind.name).first})
end
# The time is just a special text field.
Field.create({:name => 'Time', :kind => Kind.where(:name => 'Text').first})
Field.find_or_create_by_name({:name => 'Time', :kind => Kind.where(:name => 'Text').first})

#Create an initial group
Group.find_or_create_by_name(:name => "Concerto Admins")

#Create an initial user
user = User.find_or_create_by_email(:email => "ConcertoAdmin@concerto.test", :first_name => "Concerto", :last_name => "Admin", :password => "concerto2")
user.is_admin = 1
user.save

#Associate user with initial group
Membership.create(:user_id => 1, :group_id => 1, :level => 9)

#Create an initial feed
Feed.find_or_create_by_name(:name => "Concerto", :description => "Initial Concerto Feed", :group_id => 1, :is_viewable => 1, :is_submittable => 1)

#Create an initial template
Template.find_or_create_by_name(:name => "Default Template", :author => "Concerto")

#Associate each field with a position in the template
concerto_template = Template.where(:name => "Default Template").first.id
Position.find_or_create_by_field_id_and_template_id(Field.where(:name => "Graphics").first.id,concerto_template, :top => ".1", :left => ".1", :bottom => ".9", :right => ".4")
Position.find_or_create_by_field_id_and_template_id(Field.where(:name => "Ticker").first.id,concerto_template, :top => ".1", :left => ".1", :bottom => ".9", :right => ".4")
Position.find_or_create_by_field_id_and_template_id(Field.where(:name => "Text").first.id,concerto_template, :top => ".1", :left => ".1", :bottom => ".9", :right => ".4")
Position.find_or_create_by_field_id_and_template_id(Field.where(:name => "Time").first.id,concerto_template, :top => ".1", :left => ".1", :bottom => ".9", :right => ".4")

0 comments on commit 23f7eba

Please sign in to comment.