Files
tsemple/test/controllers/topics_controller_test.rb
2014-01-05 21:05:00 +08:00

29 lines
715 B
Ruby

require 'test_helper'
class TopicsControllerTest < ActionController::TestCase
test "should get index page" do
3.times { create(:topic) }
get :index
assert_response :success, @response.body
end
test "should get new page" do
assert_require_logined do
get :new
end
assert_response :success, @response.body
end
test "should create topic" do
assert_difference "Topic.count" do
assert_require_logined do
post :create, topic: { title: 'Title', posts_attributes: [ content: 'Content' ] }
end
end
topic = Topic.last
assert_equal 'Title', topic.title
assert_equal 'Content', topic.posts.first.content
assert_redirected_to topic
end
end