Skip to content

Commit ace2d12

Browse files
Comment model and Article-Comment associations were created
1 parent 5d42aea commit ace2d12

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

app/models/article.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Article < ActiveRecord::Base
2+
has_many :comments
3+
24
validates :title, presence: true,
35
length: { minimum: 5 }
46
end

app/models/comment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Comment < ActiveRecord::Base
2+
belongs_to :article
3+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CreateComments < ActiveRecord::Migration
2+
def change
3+
create_table :comments do |t|
4+
t.string :commenter
5+
t.text :body
6+
t.references :article, index: true
7+
8+
t.timestamps
9+
end
10+
end
11+
end

db/schema.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20140817122829) do
14+
ActiveRecord::Schema.define(version: 20140818083621) do
1515

1616
create_table "articles", force: true do |t|
1717
t.string "title"
@@ -20,4 +20,14 @@
2020
t.datetime "updated_at"
2121
end
2222

23+
create_table "comments", force: true do |t|
24+
t.string "commenter"
25+
t.text "body"
26+
t.integer "article_id"
27+
t.datetime "created_at"
28+
t.datetime "updated_at"
29+
end
30+
31+
add_index "comments", ["article_id"], name: "index_comments_on_article_id"
32+
2333
end

test/fixtures/comments.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
one:
4+
commenter: MyString
5+
body: MyText
6+
article_id:
7+
8+
two:
9+
commenter: MyString
10+
body: MyText
11+
article_id:

test/models/comment_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class CommentTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)