Fixed post missing user error when create topic

This commit is contained in:
Rei
2014-01-07 00:39:15 +08:00
parent cc17b8b858
commit 015c5f4a59
2 changed files with 3 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ class TopicsController < ApplicationController
def create
@topic = Topic.new topic_params.merge(user: current_user)
@topic.posts.first.user = current_user
if @topic.save
redirect_to @topic
else

View File

@@ -28,6 +28,8 @@ class TopicsControllerTest < ActionController::TestCase
topic = Topic.last
assert_equal 'Title', topic.title
assert_equal 'Content', topic.posts.first.content
assert_not_nil topic.user
assert_equal topic.user, topic.posts.first.user
assert_redirected_to topic
end
end