Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ruseel/rboard
base: 64146d2c1b
...
head fork: ruseel/rboard
compare: d60bfcee8d
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
7 app/controllers/comments_controller.rb
@@ -12,13 +12,16 @@ def show
# end
def create
- @comment = Comment.new(params[:comment])
@topic = Topic.find(params[:topic_id])
+
+ @comment = Comment.new(params[:comment])
@comment.topic = @topic
if @topic && @comment.save
redirect_to @topic
else
- render :back, notice: "댓글 작성이 실패했습니다."
+ flash[:notice] = "empty body"
+ @comments = @topic.comments
+ render "topics/show"
end
end
View
2  app/models/comment.rb
@@ -2,4 +2,6 @@ class Comment < ActiveRecord::Base
attr_accessible :body, :topic_id, :topic
belongs_to :topic
+
+ validates :body, presence: true
end
View
3  app/models/topic.rb
@@ -10,6 +10,9 @@ class Topic < ActiveRecord::Base
allow_nil: true,
converter: :to_i
+ validates :subject, presence: true, length: { minimum: 3, maximum: 50 }
+ validates :body, presence: true
+
default_scope { order("boardish desc") }
def parent=(p)
View
3  app/views/topics/show.html.erb
@@ -8,6 +8,9 @@
</div>
<div class="comments">
+ <% flash.each do |k, v| %>
+ <div class="flash <%= k %>"><%= v %></div>
+ <% end %>
<ul>
<% @comments.each do |c| %>
<li><%= c.body %></li>
View
5 test/functional/comments_controller_test.rb
@@ -33,6 +33,11 @@ class CommentsControllerTest < ActionController::TestCase
assert_redirected_to @topic
end
+ test "error message for empty body" do
+ post :create, comment: {}, topic_id: @topic
+ assert_equal "empty body", flash[:notice]
+ end
+
test "should get edit" do
get :edit, id: @comment
assert_response :success
View
6 test/unit/comment_test.rb
@@ -7,4 +7,10 @@ class CommentTest < ActiveSupport::TestCase
c.topic = t
c.save
end
+
+ test "body should be presence" do
+ c=Comment.create(body: "")
+ assert_equal false, c.valid?
+
+ end
end
View
27 test/unit/topic_test.rb
@@ -1,11 +1,38 @@
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: @topic.body)
+ assert_equal false, t.valid?
+ assert_equal 2, t.errors[:subject].size
+
+ 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 "subject length is too long" do
+ t=Topic.create(subject: "a"*51, body: @topic.body)
+ assert_equal false, t.valid?
+ assert t.errors[:subject].join(',').include?("is too long")
+ end
+
test "create sub topic" do
parent=Topic.create(subject: "parent", body: "parent")
children=Topic.create(subject: "children", body: "children", parent: parent)

No commit comments for this range

Something went wrong with that request. Please try again.