Permalink
Browse files

Comment model

  • Loading branch information...
dce committed May 31, 2011
1 parent 51fcbbc commit 775cddd062bdf2682ea051352bc52fb982b7cf33
Showing with 43 additions and 1 deletion.
  1. +7 −0 app/models/comment.rb
  2. +2 −0 app/models/post.rb
  3. +16 −0 db/migrate/20110531192110_create_comments.rb
  4. +10 −1 db/schema.rb
  5. +8 −0 test/unit/comment_test.rb
View
@@ -0,0 +1,7 @@
+class Comment < ActiveRecord::Base
+ belongs_to :post
+
+ validates_presence_of :name, :email, :comment
+
+ default_scope :order => "created_at DESC"
+end
View
@@ -1,4 +1,6 @@
class Post < ActiveRecord::Base
+ has_many :comments
+
validates_presence_of :title
scope :published, :conditions => { :published => true }
@@ -0,0 +1,16 @@
+class CreateComments < ActiveRecord::Migration
+ def self.up
+ create_table :comments do |t|
+ t.string :name
+ t.string :email
+ t.text :comment
+ t.integer :post_id
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :comments
+ end
+end
View
@@ -10,7 +10,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110531185937) do
+ActiveRecord::Schema.define(:version => 20110531192110) do
+
+ create_table "comments", :force => true do |t|
+ t.string "name"
+ t.string "email"
+ t.text "comment"
+ t.integer "post_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "posts", :force => true do |t|
t.string "title"
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class CommentTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end

0 comments on commit 775cddd

Please sign in to comment.