Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 173
- Log:
Updated to latest release of Beast according to the "getting started with
Beast" guide at:http://beast.caboo.se/forums/1/topics/381
This check-in includes frozen Edge Rails and has the beginnings of
configuration for the ROOL site included.
- Author:
- rool
- Date:
- Fri Mar 02 15:59:12 +0000 2007
- Size:
- 7404 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | require 'topics_controller' |
3 | |
4 | # Re-raise errors caught by the controller. |
5 | class TopicsController; def rescue_action(e) raise e end; end |
6 | |
7 | class TopicsControllerTest < Test::Unit::TestCase |
8 | all_fixtures |
9 | |
10 | def setup |
11 | @controller = TopicsController.new |
12 | @request = ActionController::TestRequest.new |
13 | @response = ActionController::TestResponse.new |
14 | end |
15 | |
16 | def test_should_get_index |
17 | get :index, :forum_id => 1 |
18 | assert_redirected_to forum_path(1) |
19 | end |
20 | |
21 | def test_should_get_index_as_xml |
22 | content_type 'application/xml' |
23 | get :index, :forum_id => 1, :format => 'xml' |
24 | assert_response :success |
25 | assert_select 'topics>topic' |
26 | end |
27 | |
28 | def test_should_show_topic_as_rss |
29 | get :show, :forum_id => forums(:rails).id, :id => topics(:pdi).id, :format => 'rss' |
30 | assert_response :success |
31 | assert_select 'channel' |
32 | end |
33 | |
34 | def test_should_show_topic_as_xml |
35 | content_type 'application/xml' |
36 | get :show, :forum_id => forums(:rails).id, :id => topics(:pdi).id, :format => 'xml' |
37 | assert_response :success |
38 | assert_select 'topic' |
39 | end |
40 | |
41 | def test_should_get_new |
42 | login_as :aaron |
43 | get :new, :forum_id => 1 |
44 | assert_response :success |
45 | end |
46 | |
47 | def test_sticky_and_locked_protected_from_non_admin |
48 | login_as :joe |
49 | assert ! users(:joe).admin? |
50 | assert ! users(:joe).moderator_of?(:rails) |
51 | post :create, :forum_id => forums(:rails).id, :topic => { :title => 'blah', :sticky => "1", :locked => "1", :body => 'foo' } |
52 | assert assigns(:topic) |
53 | assert ! assigns(:topic).sticky? |
54 | assert ! assigns(:topic).locked? |
55 | end |
56 | |
57 | def test_sticky_and_locked_allowed_to_moderator |
58 | login_as :sam |
59 | assert ! users(:sam).admin? |
60 | assert users(:sam).moderator_of?(forums(:rails)) |
61 | post :create, :forum_id => forums(:rails).id, :topic => { :title => 'blah', :sticky => "1", :locked => "1", :body => 'foo' } |
62 | assert assigns(:topic) |
63 | assert assigns(:topic).sticky? |
64 | assert assigns(:topic).locked? |
65 | end |
66 | |
67 | def test_should_allow_admin_to_sticky_and_lock |
68 | login_as :aaron |
69 | post :create, :forum_id => forums(:rails).id, :topic => { :title => 'blah2', :sticky => "1", :locked => "1", :body => 'foo' } |
70 | assert assigns(:topic).sticky? |
71 | assert assigns(:topic).locked? |
72 | end |
73 | |
74 | def test_should_create_topic |
75 | counts = lambda { [Topic.count, Post.count, forums(:rails).topics_count, forums(:rails).posts_count, users(:aaron).posts_count] } |
76 | old = counts.call |
77 | |
78 | login_as :aaron |
79 | post :create, :forum_id => forums(:rails).id, :topic => { :title => 'blah', :body => 'foo' } |
80 | assert assigns(:topic) |
81 | assert assigns(:post) |
82 | assert_redirected_to topic_path(forums(:rails), assigns(:topic)) |
83 | [forums(:rails), users(:aaron)].each &:reload |
84 | |
85 | assert_equal old.collect { |n| n + 1}, counts.call |
86 | end |
87 | |
88 | def test_should_create_topic_with_xml |
89 | content_type 'application/xml' |
90 | authorize_as :aaron |
91 | post :create, :forum_id => forums(:rails).id, :topic => { :title => 'blah', :body => 'foo' }, :format => 'xml' |
92 | assert_response :created |
93 | assert_equal formatted_topic_url(:forum_id => forums(:rails), :id => assigns(:topic), :format => :xml), @response.headers["Location"] |
94 | end |
95 | |
96 | def test_should_delete_topic |
97 | counts = lambda { [Post.count, forums(:rails).topics_count, forums(:rails).posts_count] } |
98 | old = counts.call |
99 | |
100 | login_as :aaron |
101 | delete :destroy, :forum_id => forums(:rails).id, :id => topics(:ponies).id |
102 | assert_redirected_to forum_path(forums(:rails)) |
103 | [forums(:rails), users(:aaron)].each &:reload |
104 | |
105 | assert_equal old.collect { |n| n - 1}, counts.call |
106 | end |
107 | |
108 | def test_should_delete_topic_with_xml |
109 | content_type 'application/xml' |
110 | authorize_as :aaron |
111 | delete :destroy, :forum_id => forums(:rails).id, :id => topics(:ponies).id, :format => 'xml' |
112 | assert_response :success |
113 | end |
114 | |
115 | def test_should_allow_moderator_to_delete_topic |
116 | assert_difference Topic, :count, -1 do |
117 | login_as :sam |
118 | delete :destroy, :forum_id => forums(:rails).id, :id => topics(:pdi).id |
119 | end |
120 | end |
121 | |
122 | def test_should_update_views_for_show |
123 | assert_difference topics(:pdi), :views do |
124 | get :show, :forum_id => forums(:rails).id, :id => topics(:pdi).id |
125 | assert_response :success |
126 | topics(:pdi).reload |
127 | end |
128 | end |
129 | |
130 | def test_should_not_update_views_for_show_via_rss |
131 | assert_difference topics(:pdi), :views, 0 do |
132 | get :show, :forum_id => forums(:rails).id, :id => topics(:pdi).id, :format => 'rss' |
133 | assert_response :success |
134 | topics(:pdi).reload |
135 | end |
136 | end |
137 | |
138 | def test_should_not_add_viewed_topic_to_session_on_show_rss |
139 | login_as :aaron |
140 | get :show, :forum_id => forums(:rails).id, :id => topics(:pdi).id, :format => 'rss' |
141 | assert_response :success |
142 | assert session[:topics].blank? |
143 | end |
144 | |
145 | def test_should_update_views_for_show_except_topic_author |
146 | login_as :aaron |
147 | views=topics(:pdi).views |
148 | get :show, :forum_id => forums(:rails).id, :id => topics(:pdi).id |
149 | assert_response :success |
150 | assert_equal views, topics(:pdi).reload.views |
151 | end |
152 | |
153 | def test_should_show_topic |
154 | get :show, :forum_id => forums(:rails).id, :id => topics(:pdi).id |
155 | assert_response :success |
156 | assert_equal topics(:pdi), assigns(:topic) |
157 | assert_models_equal [posts(:pdi), posts(:pdi_reply), posts(:pdi_rebuttal)], assigns(:posts) |
158 | end |
159 | |
160 | def test_should_show_other_post |
161 | get :show, :forum_id => forums(:rails).id, :id => topics(:ponies).id |
162 | assert_response :success |
163 | assert_equal topics(:ponies), assigns(:topic) |
164 | assert_models_equal [posts(:ponies)], assigns(:posts) |
165 | end |
166 | |
167 | def test_should_get_edit |
168 | login_as :aaron |
169 | get :edit, :forum_id => 1, :id => 1 |
170 | assert_response :success |
171 | end |
172 | |
173 | def test_should_update_own_post |
174 | login_as :sam |
175 | put :update, :forum_id => forums(:rails).id, :id => topics(:ponies).id, :topic => { } |
176 | assert_redirected_to topic_path(forums(:rails), assigns(:topic)) |
177 | end |
178 | |
179 | def test_should_update_with_xml |
180 | content_type 'application/xml' |
181 | authorize_as :sam |
182 | put :update, :forum_id => forums(:rails).id, :id => topics(:ponies).id, :topic => { }, :format => 'xml' |
183 | assert_response :success |
184 | end |
185 | |
186 | def test_should_not_update_user_id_of_own_post |
187 | login_as :sam |
188 | put :update, :forum_id => forums(:rails).id, :id => topics(:ponies).id, :topic => { :user_id => 32 } |
189 | assert_redirected_to topic_path(forums(:rails), assigns(:topic)) |
190 | assert_equal users(:sam).id, posts(:ponies).reload.user_id |
191 | end |
192 | |
193 | def test_should_not_update_other_post |
194 | login_as :sam |
195 | put :update, :forum_id => forums(:comics).id, :id => topics(:galactus).id, :topic => { } |
196 | assert_redirected_to login_path |
197 | end |
198 | |
199 | def test_should_not_update_other_post_with_xml |
200 | content_type 'application/xml' |
201 | authorize_as :sam |
202 | put :update, :forum_id => forums(:comics).id, :id => topics(:galactus).id, :topic => { }, :format => 'xml' |
203 | assert_response :unauthorized |
204 | end |
205 | |
206 | def test_should_update_other_post_as_moderator |
207 | login_as :sam |
208 | put :update, :forum_id => forums(:rails).id, :id => topics(:pdi).id, :topic => { } |
209 | assert_redirected_to topic_path(forums(:rails), assigns(:topic)) |
210 | end |
211 | |
212 | def test_should_update_other_post_as_admin |
213 | login_as :aaron |
214 | put :update, :forum_id => forums(:rails).id, :id => topics(:ponies), :topic => { } |
215 | assert_redirected_to topic_path(forums(:rails), assigns(:topic)) |
216 | end |
217 | end |