beast rev 2066
[beast-modified.git] / test / functional / forums_controller_test.rb
blobcb7ce155cb87bf9fc08b43a3aae37f04af3e3a19
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
8   all_fixtures
10   def setup
11     @controller = ForumsController.new
12     @request    = ActionController::TestRequest.new
13     @response   = ActionController::TestResponse.new
14   end
16   # test remembering pages
17   
18   def test_forum_index_resets_page_variable
19     @request.session[:forum_page]=Hash.new(1)
20     get :index, :id => 1
21     assert_equal nil, session[:forum_page]
22   end
23   
24   def test_forum_view_sets_page_variable
25     get :show, :id =>1, :page =>3 
26     assert_equal 3, session[:forum_page][1]
27   end
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(';'))
33     get :index
34     assert_equal users(:sam).id, session[:user_id]
35   end
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
40     users(:aaron).save!
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]
44   end
46   def test_should_get_index
47     get :index
48     assert_response :success
49     assert assigns(:forums)
50     assert_select 'html>head'
51   end
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'
58   end
60   def test_should_get_new
61     login_as :aaron
62     get :new
63     assert_response :success
64   end
65   
66   def test_should_require_admin
67     login_as :sam
68     get :new
69     assert_redirected_to login_path
70   end
71   
72   def test_should_create_forum
73     login_as :aaron
74     assert_difference Forum, :count do
75       post :create, :forum => { :name => 'yeah' }
76     end
77     
78     assert_redirected_to forums_path
79   end
80   
81   def test_should_create_forum_with_xml
82     content_type 'application/xml'
83     authorize_as :aaron
85     assert_difference Forum, :count do
86       post :create, :forum => { :name => 'yeah' }, :format => 'xml'
87     end
88     
89     assert_response :created
90     assert_equal formatted_forum_url(:id => assigns(:forum), :format => :xml), @response.headers["Location"]
91   end
93   def test_should_show_forum
94     get :show, :id => 1
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'
100   end
101   
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'
107   end
109   def test_should_get_edit
110     login_as :aaron
111     get :edit, :id => 1
112     assert_response :success
113   end
114   
115   def test_should_update_forum
116     login_as :aaron
117     put :update, :id => 1, :forum => { }
118     assert_redirected_to forums_path
119   end
121   def test_should_update_forum_with_xml
122     authorize_as :aaron
123     content_type 'application/xml'
124     put :update, :id => 1, :forum => { }, :format => 'xml'
125     assert_response :success
126   end
128   def test_should_destroy_forum
129     login_as :aaron
130     old_count = Forum.count
131     delete :destroy, :id => 1
132     assert_equal old_count-1, Forum.count
133     
134     assert_redirected_to forums_path
135   end
137   def test_should_destroy_forum_with_xml
138     authorize_as :aaron
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
144   end