Skip to content
Browse files

add model comment

  • Loading branch information...
1 parent 6bb5f84 commit 7f270be9750b70569903a033738f8d85033246f6 @ruseel committed Nov 14, 2012
View
5 app/models/comment.rb
@@ -0,0 +1,5 @@
+class Comment < ActiveRecord::Base
+ attr_accessible :body, :topic_id, :topic
+
+ belongs_to :topic
+end
View
10 db/migrate/20121114072129_create_comments.rb
@@ -0,0 +1,10 @@
+class CreateComments < ActiveRecord::Migration
+ def change
+ create_table :comments do |t|
+ t.string :topic_id
+ t.text :body
+
+ t.timestamps
+ end
+ end
+end
View
9 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121109051941) do
+ActiveRecord::Schema.define(:version => 20121114072129) do
create_table "admins", :force => true do |t|
t.string "email"
@@ -21,6 +21,13 @@
t.datetime "updated_at", :null => false
end
+ create_table "comments", :force => true do |t|
+ t.string "topic_id"
+ t.text "body"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "topics", :force => true do |t|
t.integer "admin_id"
t.string "subject"
View
9 test/fixtures/comments.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ topic_id: MyString
+ body: MyText
+
+two:
+ topic_id: MyString
+ body: MyText
View
10 test/unit/comment_test.rb
@@ -0,0 +1,10 @@
+require 'test_helper'
+
+class CommentTest < ActiveSupport::TestCase
+ test "belongs_to topic" do
+ t=Topic.new(subject: "subject", body: "body")
+ c=Comment.new(body: "comment")
+ c.topic = t
+ c.save
+ end
+end

0 comments on commit 7f270be

Please sign in to comment.
Something went wrong with that request. Please try again.