Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

topic validation, empty body or empty subject

  • Loading branch information...
commit c9ec6e1db5749355371defe9e9be0cfdb4c0228c 1 parent 3f50714
@ruseel authored
Showing with 13 additions and 0 deletions.
  1. +2 −0  app/models/topic.rb
  2. +11 −0 test/unit/topic_test.rb
View
2  app/models/topic.rb
@@ -10,6 +10,8 @@ class Topic < ActiveRecord::Base
allow_nil: true,
converter: :to_i
+ validates :subject, :body, presence: true
+
default_scope { order("boardish desc") }
def parent=(p)
View
11 test/unit/topic_test.rb
@@ -6,6 +6,17 @@ class TopicTest < ActiveSupport::TestCase
assert_not_nil t.boardish
end
+ test "empty subject or empty body" do
+ t=Topic.create(subject: "", body: "abc")
+ assert_equal false, t.valid?
+ assert_equal 1, t.errors[:subject].size
+
+ t=Topic.create(subject: "s", body: "")
+ assert_equal false, t.valid?
+ assert_equal 0, t.errors[:subject].size
+ assert_equal 1, t.errors[:body].size
+ end
+
test "create sub topic" do
parent=Topic.create(subject: "parent", body: "parent")
children=Topic.create(subject: "children", body: "children", parent: parent)
Please sign in to comment.
Something went wrong with that request. Please try again.