Commit 656d9344b7b1de0a38f9251815c9ab4a6a032a3b

Add an Author model

Commit diff

app/models/author.rb

 
1class Author < ActiveRecord::Base
2 validates_presence_of :name, :email, :open_id
3end
toggle raw diff

db/migrate/007_create_authors.rb

 
1class CreateAuthors < ActiveRecord::Migration
2 def self.up
3 create_table :authors do |t|
4 t.string :name
5 t.string :email
6 t.string :open_id
7 end
8 end
9
10 def self.down
11 drop_table :authors
12 end
13end
toggle raw diff

db/schema.rb

 
99#
1010# It's strongly recommended to check this file into your version control system.
1111
12ActiveRecord::Schema.define(:version => 6) do
12ActiveRecord::Schema.define(:version => 7) do
13
14 create_table "authors", :force => true do |t|
15 t.string "name"
16 t.string "email"
17 t.string "open_id"
18 end
1319
1420 create_table "comments", :force => true do |t|
1521 t.integer "post_id", :null => false
2323 t.string "author_url", :default => "", :null => false
2424 t.string "author_email", :default => "", :null => false
2525 t.string "author_openid_authority", :default => "", :null => false
26 t.text "body", :default => "", :null => false
27 t.text "body_html", :default => "", :null => false
26 t.text "body", :null => false
27 t.text "body_html", :null => false
2828 t.datetime "created_at"
2929 t.datetime "updated_at"
3030 end
3535 create_table "pages", :force => true do |t|
3636 t.string "title", :default => "", :null => false
3737 t.string "slug", :default => "", :null => false
38 t.text "body", :default => "", :null => false
39 t.text "body_html", :default => "", :null => false
38 t.text "body", :null => false
39 t.text "body_html", :null => false
4040 t.datetime "created_at"
4141 t.datetime "updated_at"
4242 end
4747 create_table "posts", :force => true do |t|
4848 t.string "title", :default => "", :null => false
4949 t.string "slug", :default => "", :null => false
50 t.text "body", :default => "", :null => false
51 t.text "body_html", :default => "", :null => false
50 t.text "body", :null => false
51 t.text "body_html", :null => false
5252 t.boolean "active", :default => true, :null => false
5353 t.integer "approved_comments_count", :default => 0, :null => false
5454 t.string "cached_tag_list"
toggle raw diff

spec/models/authors_spec.rb

 
1require File.dirname(__FILE__) + '/../spec_helper'
2
3describe Author, 'validations' do
4 def valid_author_attributes
5 {
6 :name => "Don Alias",
7 :email => "don@enkiblog.com",
8 :open_id => "http://enkiblog.com"
9 }
10 end
11
12 it 'is valid with valid_author_attributes' do
13 Author.new(valid_author_attributes).should be_valid
14 end
15
16 it 'is invalid with no name' do
17 Author.new(valid_author_attributes.merge(:name => '')).should_not be_valid
18 end
19
20 it 'is invalid with no email' do
21 Author.new(valid_author_attributes.merge(:email => '')).should_not be_valid
22 end
23
24 it 'is invalid with no open_id' do
25 Author.new(valid_author_attributes.merge(:open_id => '')).should_not be_valid
26 end
27end
toggle raw diff