Permalink
Browse files

subject is too short

  • Loading branch information...
1 parent c9ec6e1 commit 71467b02892246660519b661ba699b75d9b55ae0 @ruseel committed Nov 20, 2012
Showing with 15 additions and 4 deletions.
  1. +2 −1 app/models/topic.rb
  2. +13 −3 test/unit/topic_test.rb
View
@@ -10,7 +10,8 @@ class Topic < ActiveRecord::Base
allow_nil: true,
converter: :to_i
- validates :subject, :body, presence: true
+ validates :subject, presence: true, length: { minimum: 3 }
+ validates :body, presence: true
default_scope { order("boardish desc") }
View
@@ -1,22 +1,32 @@
require 'test_helper'
class TopicTest < ActiveSupport::TestCase
+ setup do
+ @topic = topics(:one)
+ end
+
test "create new topic without parent" do
t=Topic.create(subject: "one", body: "one")
assert_not_nil t.boardish
end
test "empty subject or empty body" do
- t=Topic.create(subject: "", body: "abc")
+ t=Topic.create(subject: "", body: @topic.body)
assert_equal false, t.valid?
- assert_equal 1, t.errors[:subject].size
+ assert_equal 2, t.errors[:subject].size
- t=Topic.create(subject: "s", body: "")
+ t=Topic.create(subject: @topic.subject, body: "")
assert_equal false, t.valid?
assert_equal 0, t.errors[:subject].size
assert_equal 1, t.errors[:body].size
end
+ test "subject length is too short" do
+ t=Topic.create(subject: "a", body: @topic.body)
+ assert_equal false, t.valid?
+ assert t.errors[:subject].join(',').include?("is too short")
+ end
+
test "create sub topic" do
parent=Topic.create(subject: "parent", body: "parent")
children=Topic.create(subject: "children", body: "children", parent: parent)

0 comments on commit 71467b0

Please sign in to comment.