Permalink
Browse files

presence topic in comment.rb

  • Loading branch information...
1 parent d60bfce commit c95bb335d3798febaae31996d3a1a6fd6f898861 @ruseel committed Nov 20, 2012
Showing with 15 additions and 5 deletions.
  1. +2 −0 app/models/comment.rb
  2. +1 −1 test/functional/topics_controller_test.rb
  3. +12 −4 test/unit/comment_test.rb
View
@@ -3,5 +3,7 @@ class Comment < ActiveRecord::Base
belongs_to :topic
+ validates :topic, presence: true
validates :body, presence: true
+
end
@@ -52,7 +52,7 @@ class TopicsControllerTest < ActionController::TestCase
end
test "should handle reply" do
- post :create, topic: { subject: "1", body: "1" }
+ post :create, topic: { subject: @topic.subject, body: @topic.body }
parent = assigns(:topic)
post :create, topic: { subject: "reply-1", body: "reply-1" }, parent_id: parent.id
View
@@ -1,16 +1,24 @@
require 'test_helper'
class CommentTest < ActiveSupport::TestCase
+ setup do
+ @topic = topics(:one)
+ end
+
test "belongs_to topic" do
- t=Topic.new(subject: "subject", body: "body")
- c=Comment.new(body: "comment")
- c.topic = t
+ c=Comment.new(body: "comment", topic: @topic)
c.save
end
+ test "if not belongs_to topic, error" do
+ c=Comment.new(body: "comment")
+ assert_equal false, c.valid?
+ end
+
test "body should be presence" do
c=Comment.create(body: "")
assert_equal false, c.valid?
-
end
+
+
end

0 comments on commit c95bb33

Please sign in to comment.