1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'topic_controller'
5 # Re-raise errors caught by the controller.
6 def rescue_action(e) raise e end
7 # disable flood detection
11 class TopicControllerTest < Test::Unit::TestCase
12 fixtures :forums, :topics, :posts, :settings, :groups, :users, :categories
14 @controller = TopicController.new
15 @request = ActionController::TestRequest.new
16 @response = ActionController::TestResponse.new
19 def test_construct_post
20 User.current_user = users(:admin)
21 for a in [:new, :create]
22 for p in [{:fid => forums(:f1).id}, {:id => topics(:f11).id}]
24 assert assigns(:post) != nil
25 assert assigns(:post).topic != nil
26 assert assigns(:post).topic.forum != nil
32 User.current_user = users(:admin)
33 params = {:fid => forums(:f1).id, :post => {:message => 'test', :hide_smilies => false}, :topic => {:subject => 'test'}}
34 post :create, params.merge({:preview => true})
35 assert_response :success # render :action => new
37 assert_redirected_to :controller => 'topic', :action => 'view'
38 assert assigns(:post) != nil
39 assert assigns(:post).new_record? == false
40 assert assigns(:post).topic.new_record? == false
42 params = {:id => topics(:f11).id, :post => {:message => 'test', :hide_smilies => false}}
43 post :create, params.merge({:preview => true})
44 assert_response :success
46 assert_redirected_to :controller => 'topic', :action => 'view'
47 assert assigns(:post) != nil
48 assert assigns(:post).new_record? == false
49 assert_equal assigns(:post).topic.id, topics(:f11).id
53 User.current_user = users(:admin)
54 params = {:pid => posts(:p1).id, :post => {:message => 'test', :hide_smilies => false} }
55 post :update, params.merge({:preview => true})
56 assert_response :success
58 assert_redirected_to :controller => 'topic', :action => 'view'
62 get :view, :id => topics(:f11).id
63 assert_response :success
65 get :view, :pid => posts(:p1).id
66 assert_response :success