1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'forums_controller'
4 # Re-raise errors caught by the controller.
5 class ForumsController; def rescue_action(e) raise e end; end
7 class ForumsControllerTest < Test::Unit::TestCase
11 @controller = ForumsController.new
12 @request = ActionController::TestRequest.new
13 @response = ActionController::TestResponse.new
16 # test remembering pages
18 def test_forum_index_resets_page_variable
19 @request.session[:forum_page]=Hash.new(1)
21 assert_equal nil, session[:forum_page]
24 def test_forum_view_sets_page_variable
25 get :show, :id =>1, :page =>3
26 assert_equal 3, session[:forum_page][1]
31 def test_remember_me_logs_into_home
32 @request.cookies['login_token'] = CGI::Cookie.new('login_token', [users(:sam).id.to_s, users(:sam).login_key].join(';'))
34 assert_equal users(:sam).id, session[:user_id]
37 def test_remember_me_logs_in_when_login_required
38 users(:aaron).login_key = "8305f94ab2b92f99137abbc235ee28e5"
39 users(:aaron).login_key_expires_at = Time.now.utc+1.week
41 @request.cookies['login_token'] = CGI::Cookie.new('login_token', [users(:aaron).id.to_s, users(:aaron).login_key].join(';'))
42 get :edit, :id => users(:aaron).id
43 assert_equal users(:aaron).id, session[:user_id]
46 def test_should_get_index
48 assert_response :success
49 assert assigns(:forums)
50 assert_select 'html>head'
53 def test_should_get_index_with_xml
54 content_type 'application/xml'
55 get :index, :format => 'xml'
56 assert_response :success
57 assert_select 'forums>forum'
60 def test_should_get_new
63 assert_response :success
66 def test_should_require_admin
69 assert_redirected_to login_path
72 def test_should_create_forum
74 assert_difference Forum, :count do
75 post :create, :forum => { :name => 'yeah' }
78 assert_redirected_to forums_path
81 def test_should_create_forum_with_xml
82 content_type 'application/xml'
85 assert_difference Forum, :count do
86 post :create, :forum => { :name => 'yeah' }, :format => 'xml'
89 assert_response :created
90 assert_equal formatted_forum_url(:id => assigns(:forum), :format => :xml), @response.headers["Location"]
93 def test_should_show_forum
95 assert_response :success
96 assert assigns(:topics)
97 # sticky should be first
98 assert_equal(topics(:sticky), assigns(:topics).first)
99 assert_select 'html>head'
102 def test_should_show_forum_with_xml
103 content_type 'application/xml'
104 get :show, :id => 1, :format => 'xml'
105 assert_response :success
106 assert_select 'forum'
109 def test_should_get_edit
112 assert_response :success
115 def test_should_update_forum
117 put :update, :id => 1, :forum => { }
118 assert_redirected_to forums_path
121 def test_should_update_forum_with_xml
123 content_type 'application/xml'
124 put :update, :id => 1, :forum => { }, :format => 'xml'
125 assert_response :success
128 def test_should_destroy_forum
130 old_count = Forum.count
131 delete :destroy, :id => 1
132 assert_equal old_count-1, Forum.count
134 assert_redirected_to forums_path
137 def test_should_destroy_forum_with_xml
139 content_type 'application/xml'
140 old_count = Forum.count
141 delete :destroy, :id => 1, :format => 'xml'
142 assert_equal old_count-1, Forum.count
143 assert_response :success