Skip to content

Commit

Permalink
Comment model and Article-Comment associations were created
Browse files Browse the repository at this point in the history
  • Loading branch information
tayfunoziserikan committed Aug 18, 2014
1 parent 5d42aea commit ace2d12
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Article < ActiveRecord::Base
has_many :comments

validates :title, presence: true,
length: { minimum: 5 }
end
3 changes: 3 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Comment < ActiveRecord::Base
belongs_to :article
end
11 changes: 11 additions & 0 deletions db/migrate/20140818083621_create_comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :commenter
t.text :body
t.references :article, index: true

t.timestamps
end
end
end
12 changes: 11 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140817122829) do
ActiveRecord::Schema.define(version: 20140818083621) do

create_table "articles", force: true do |t|
t.string "title"
Expand All @@ -20,4 +20,14 @@
t.datetime "updated_at"
end

create_table "comments", force: true do |t|
t.string "commenter"
t.text "body"
t.integer "article_id"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "comments", ["article_id"], name: "index_comments_on_article_id"

end
11 changes: 11 additions & 0 deletions test/fixtures/comments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
commenter: MyString
body: MyText
article_id:

two:
commenter: MyString
body: MyText
article_id:
7 changes: 7 additions & 0 deletions test/models/comment_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CommentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit ace2d12

Please sign in to comment.