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:
- 10083 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | require 'posts_controller' |
3 | |
4 | # Re-raise errors caught by the controller. |
5 | class PostsController; def rescue_action(e) raise e end; end |
6 | |
7 | class PostsControllerTest < Test::Unit::TestCase |
8 | all_fixtures |
9 | def setup |
10 | @controller = PostsController.new |
11 | @request = ActionController::TestRequest.new |
12 | @response = ActionController::TestResponse.new |
13 | end |
14 | |
15 | def test_should_create_reply |
16 | counts = lambda { [Post.count, forums(:rails).posts_count, users(:aaron).posts_count, topics(:pdi).posts_count] } |
17 | equal = lambda { [forums(:rails).topics_count] } |
18 | old_counts = counts.call |
19 | old_equal = equal.call |
20 | |
21 | login_as :aaron |
22 | post :create, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :post => { :body => 'blah' } |
23 | assert_redirected_to topic_path(:forum_id => forums(:rails).id, :id => topics(:pdi).id, :anchor => assigns(:post).dom_id, :page => '1') |
24 | assert_equal topics(:pdi), assigns(:topic) |
25 | [forums(:rails), users(:aaron), topics(:pdi)].each &:reload |
26 | |
27 | assert_equal old_counts.collect { |n| n + 1}, counts.call |
28 | assert_equal old_equal, equal.call |
29 | end |
30 | |
31 | def test_should_create_reply_with_xml |
32 | content_type 'application/xml' |
33 | authorize_as :aaron |
34 | post :create, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :post => { :body => 'blah' }, :format => 'xml' |
35 | assert_response :created |
36 | assert_equal formatted_post_url(:forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :id => assigns(:post), :format => :xml), @response.headers["Location"] |
37 | end |
38 | |
39 | def test_should_update_topic_replied_at_upon_replying |
40 | old=topics(:pdi).replied_at |
41 | login_as :aaron |
42 | post :create, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :post => { :body => 'blah' } |
43 | assert_not_equal(old, topics(:pdi).reload.replied_at) |
44 | assert old < topics(:pdi).reload.replied_at |
45 | end |
46 | |
47 | def test_should_reply_with_no_body |
48 | assert_difference Post, :count, 0 do |
49 | login_as :aaron |
50 | post :create, :forum_id => forums(:rails).id, :topic_id => posts(:pdi).id, :post => {} |
51 | assert_redirected_to topic_path(:forum_id => forums(:rails).id, :id => posts(:pdi).id, :anchor => 'reply-form', :page => '1') |
52 | end |
53 | end |
54 | |
55 | def test_should_delete_reply |
56 | counts = lambda { [Post.count, forums(:rails).posts_count, users(:sam).posts_count, topics(:pdi).posts_count] } |
57 | equal = lambda { [forums(:rails).topics_count] } |
58 | old_counts = counts.call |
59 | old_equal = equal.call |
60 | |
61 | login_as :aaron |
62 | delete :destroy, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :id => posts(:pdi_reply).id |
63 | assert_redirected_to topic_path(:forum_id => forums(:rails), :id => topics(:pdi)) |
64 | [forums(:rails), users(:sam), topics(:pdi)].each &:reload |
65 | |
66 | assert_equal old_counts.collect { |n| n - 1}, counts.call |
67 | assert_equal old_equal, equal.call |
68 | end |
69 | |
70 | def test_should_delete_reply_with_xml |
71 | content_type 'application/xml' |
72 | authorize_as :aaron |
73 | delete :destroy, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :id => posts(:pdi_reply).id, :format => 'xml' |
74 | assert_response :success |
75 | end |
76 | |
77 | def test_should_delete_reply_as_moderator |
78 | assert_difference Post, :count, -1 do |
79 | login_as :sam |
80 | delete :destroy, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :id => posts(:pdi_rebuttal).id |
81 | end |
82 | end |
83 | |
84 | def test_should_delete_topic_if_deleting_the_last_reply |
85 | assert_difference Post, :count, -1 do |
86 | assert_difference Topic, :count, -1 do |
87 | login_as :aaron |
88 | delete :destroy, :forum_id => forums(:rails).id, :topic_id => topics(:il8n).id, :id => posts(:il8n).id |
89 | assert_redirected_to forum_path(forums(:rails)) |
90 | assert_raise(ActiveRecord::RecordNotFound) { topics(:il8n).reload } |
91 | end |
92 | end |
93 | end |
94 | |
95 | def test_can_edit_own_post |
96 | login_as :sam |
97 | put :update, :forum_id => forums(:comics).id, :topic_id => topics(:galactus).id, :id => posts(:silver_surfer).id, :post => {} |
98 | assert_redirected_to topic_path(:forum_id => forums(:comics), :id => topics(:galactus), :anchor => posts(:silver_surfer).dom_id, :page => '1') |
99 | end |
100 | |
101 | def test_can_edit_own_post_with_xml |
102 | content_type 'application/xml' |
103 | authorize_as :sam |
104 | put :update, :forum_id => forums(:comics).id, :topic_id => topics(:galactus).id, :id => posts(:silver_surfer).id, :post => {}, :format => 'xml' |
105 | assert_response :success |
106 | end |
107 | |
108 | |
109 | def test_can_edit_other_post_as_moderator |
110 | login_as :sam |
111 | put :update, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :id => posts(:pdi_rebuttal).id, :post => {} |
112 | assert_redirected_to topic_path(:forum_id => forums(:rails), :id => posts(:pdi), :anchor => posts(:pdi_rebuttal).dom_id, :page => '1') |
113 | end |
114 | |
115 | def test_cannot_edit_other_post |
116 | login_as :sam |
117 | put :update, :forum_id => forums(:comics).id, :topic_id => topics(:galactus).id, :id => posts(:galactus).id, :post => {} |
118 | assert_redirected_to login_path |
119 | end |
120 | |
121 | def test_cannot_edit_other_post_with_xml |
122 | content_type 'application/xml' |
123 | authorize_as :sam |
124 | put :update, :forum_id => forums(:comics).id, :topic_id => topics(:galactus).id, :id => posts(:galactus).id, :post => {}, :format => 'xml' |
125 | assert_response 401 |
126 | end |
127 | |
128 | def test_cannot_edit_own_post_user_id |
129 | login_as :sam |
130 | put :update, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :id => posts(:pdi_reply).id, :post => { :user_id => 32 } |
131 | assert_redirected_to topic_path(:forum_id => forums(:rails), :id => posts(:pdi), :anchor => posts(:pdi_reply).dom_id, :page => '1') |
132 | assert_equal users(:sam).id, posts(:pdi_reply).reload.user_id |
133 | end |
134 | |
135 | def test_can_edit_other_post_as_admin |
136 | login_as :aaron |
137 | put :update, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :id => posts(:pdi_rebuttal).id, :post => {} |
138 | assert_redirected_to topic_path(:forum_id => forums(:rails), :id => posts(:pdi), :anchor => posts(:pdi_rebuttal).dom_id, :page => '1') |
139 | end |
140 | |
141 | def test_should_view_post_as_xml |
142 | get :show, :forum_id => forums(:rails).id, :topic_id => topics(:pdi).id, :id => posts(:pdi_rebuttal).id, :format => 'xml' |
143 | assert_response :success |
144 | assert_select 'post' |
145 | end |
146 | |
147 | def test_should_view_recent_posts |
148 | get :index |
149 | assert_response :success |
150 | assert_models_equal [posts(:il8n), posts(:shield_reply), posts(:shield), posts(:silver_surfer), posts(:galactus), posts(:ponies), posts(:pdi_rebuttal), posts(:pdi_reply), posts(:pdi), posts(:sticky)], assigns(:posts) |
151 | assert_select 'html>head' |
152 | end |
153 | |
154 | def test_should_view_posts_by_forum |
155 | get :index, :forum_id => forums(:comics).id |
156 | assert_response :success |
157 | assert_models_equal [posts(:shield_reply), posts(:shield), posts(:silver_surfer), posts(:galactus)], assigns(:posts) |
158 | assert_select 'html>head' |
159 | end |
160 | |
161 | def test_should_view_posts_by_user |
162 | get :index, :user_id => users(:sam).id |
163 | assert_response :success |
164 | assert_models_equal [posts(:shield), posts(:silver_surfer), posts(:ponies), posts(:pdi_reply), posts(:sticky)], assigns(:posts) |
165 | assert_select 'html>head' |
166 | end |
167 | |
168 | def test_should_view_recent_posts_with_xml |
169 | content_type 'application/xml' |
170 | get :index, :format => 'xml' |
171 | assert_response :success |
172 | assert_models_equal [posts(:il8n), posts(:shield_reply), posts(:shield), posts(:silver_surfer), posts(:galactus), posts(:ponies), posts(:pdi_rebuttal), posts(:pdi_reply), posts(:pdi), posts(:sticky)], assigns(:posts) |
173 | assert_select 'posts>post' |
174 | end |
175 | |
176 | def test_should_view_posts_by_forum_with_xml |
177 | content_type 'application/xml' |
178 | get :index, :forum_id => forums(:comics).id, :format => 'xml' |
179 | assert_response :success |
180 | assert_models_equal [posts(:shield_reply), posts(:shield), posts(:silver_surfer), posts(:galactus)], assigns(:posts) |
181 | assert_select 'posts>post' |
182 | end |
183 | |
184 | def test_should_view_posts_by_user_with_xml |
185 | content_type 'application/xml' |
186 | get :index, :user_id => users(:sam).id, :format => 'xml' |
187 | assert_response :success |
188 | assert_models_equal [posts(:shield), posts(:silver_surfer), posts(:ponies), posts(:pdi_reply), posts(:sticky)], assigns(:posts) |
189 | assert_select 'posts>post' |
190 | end |
191 | |
192 | def test_should_view_monitored_posts |
193 | get :monitored, :user_id => users(:aaron).id |
194 | assert_models_equal [posts(:pdi_reply)], assigns(:posts) |
195 | end |
196 | |
197 | def test_should_search_recent_posts |
198 | get :search, :q => 'pdi' |
199 | assert_response :success |
200 | assert_models_equal [posts(:pdi_rebuttal), posts(:pdi_reply), posts(:pdi)], assigns(:posts) |
201 | end |
202 | |
203 | def test_should_search_posts_by_forum |
204 | get :search, :forum_id => forums(:comics).id, :q => 'galactus' |
205 | assert_response :success |
206 | assert_models_equal [posts(:silver_surfer), posts(:galactus)], assigns(:posts) |
207 | end |
208 | |
209 | def test_should_view_recent_posts_as_rss |
210 | get :index, :format => 'rss' |
211 | assert_response :success |
212 | assert_models_equal [posts(:il8n), posts(:shield_reply), posts(:shield), posts(:silver_surfer), posts(:galactus), posts(:ponies), posts(:pdi_rebuttal), posts(:pdi_reply), posts(:pdi), posts(:sticky)], assigns(:posts) |
213 | end |
214 | |
215 | def test_should_view_posts_by_forum_as_rss |
216 | get :index, :forum_id => forums(:comics).id, :format => 'rss' |
217 | assert_response :success |
218 | assert_models_equal [posts(:shield_reply), posts(:shield), posts(:silver_surfer), posts(:galactus)], assigns(:posts) |
219 | end |
220 | |
221 | def test_should_view_posts_by_user_as_rss |
222 | get :index, :user_id => users(:sam).id, :format => 'rss' |
223 | assert_response :success |
224 | assert_models_equal [posts(:shield), posts(:silver_surfer), posts(:ponies), posts(:pdi_reply), posts(:sticky)], assigns(:posts) |
225 | end |
226 | |
227 | def test_disallow_new_post_to_locked_topic |
228 | galactus = topics(:galactus) |
229 | galactus.locked = 1 |
230 | galactus.save |
231 | login_as :aaron |
232 | post :create, :forum_id => forums(:comics).id, :topic_id => topics(:galactus).id, :post => { :body => 'blah' } |
233 | assert_redirected_to topic_path(:forum_id => forums(:comics), :id => topics(:galactus)) |
234 | assert_equal 'This topic is locked.', flash[:notice] |
235 | end |
236 | end |