Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Seeds and small db fixes

  • Loading branch information...
commit 55b0c240a30d17b1931fbfc28cedf0f4578d4bc6 1 parent 2735ff8
@mattyoho mattyoho authored
View
3  Rakefile
@@ -5,3 +5,6 @@
require File.expand_path('../config/application', __FILE__)
SimpleFeed::Application.load_tasks
+
+desc "Set up the app db and data"
+task "boot" => ["db:drop", "db:create", "db:migrate", "db:seed"]
View
1  db/migrate/20120514203212_create_feed_items.rb
@@ -2,7 +2,6 @@ class CreateFeedItems < ActiveRecord::Migration
def change
create_table :feed_items do |t|
t.text :body
- t.string :title
t.timestamps
end
View
3  db/migrate/20120514205458_sorcery_core.rb
@@ -8,9 +8,10 @@ def self.up
t.timestamps
end
+ add_index :users, :username, unique: true, nil: false
end
def self.down
drop_table :users
end
-end
+end
View
2  db/migrate/20120515022004_create_feeds.rb
@@ -7,6 +7,8 @@ def change
t.timestamps
end
+ add_index :feeds, :user_id, unique: true, nil: false
+ add_index :feeds, :name, unique: true, nil: false
add_column :feed_items, :feed_id, :integer
end
end
View
6 db/schema.rb
@@ -15,7 +15,6 @@
create_table "feed_items", :force => true do |t|
t.text "body"
- t.string "title"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "type"
@@ -31,6 +30,9 @@
t.datetime "updated_at", :null => false
end
+ add_index "feeds", ["name"], :name => "index_feeds_on_name", :unique => true
+ add_index "feeds", ["user_id"], :name => "index_feeds_on_user_id", :unique => true
+
create_table "users", :force => true do |t|
t.string "username", :null => false
t.string "email"
@@ -40,4 +42,6 @@
t.datetime "updated_at", :null => false
end
+ add_index "users", ["username"], :name => "index_users_on_username", :unique => true
+
end
View
43 db/seeds.rb
@@ -1,7 +1,36 @@
-# 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)
+matt = User.create(username: "mattyoho", email: "matt.yoho@livingsocial.com", password: 'hungry', password_confirmation: 'hungry')
+
+matt_items = [
+ {type: "TextItem", body: "Copy and paste is not a software design principle."},
+ {type: "LinkItem", body: "I hear this place has some cool people in it.", link_url: "http://hungryacademy.com/"},
+ {type: "ImageItem", body: "Cats are funny.", image_url: "http://www.funnycatpictures.net/wp-content/uploads/2012/04/funny-cat-riding-a-bike2.jpg"}
+]
+
+jeff = User.create(username: "j3", email: "jeff@jumpstartlab.com", password: 'hungry', password_confirmation: 'hungry')
+
+jeff_items = [
+ {type: "TextItem", body: "I've been thinking of buying a machete"},
+ {type: "LinkItem", body: "I teach here!", link_url: "http://hungryacademy.com/"},
+ {type: "ImageItem", body: "Cats are kinda dumb.", image_url: "http://cdn2.funnycorner.net/funny-pictures/6177/funny-cat-and-computer-mouse.jpg"}
+]
+
+21.times do |n|
+ if rand(2) == 1
+ attrs = matt_items[n % 3].dup
+ kind = attrs.delete(:type)
+ matt.feed.feed_item_of(kind).new(attrs).save
+
+ attrs = jeff_items[n % 3].dup
+ kind = attrs.delete(:type)
+ jeff.feed.feed_item_of(kind).new(attrs).save
+ else
+ attrs = jeff_items[n % 3].dup
+ kind = attrs.delete(:type)
+ jeff.feed.feed_item_of(kind).new(attrs).save
+
+ attrs = matt_items[n % 3].dup
+ kind = attrs.delete(:type)
+ matt.feed.feed_item_of(kind).new(attrs).save
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.