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:
- 6908 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | require 'users_controller' |
3 | |
4 | # Re-raise errors caught by the controller. |
5 | class UsersController |
6 | def rescue_action(exception) |
7 | exception.is_a?(ActiveRecord::RecordInvalid) ? render_invalid_record(exception.record) : super |
8 | end |
9 | end |
10 | |
11 | class UsersControllerTest < Test::Unit::TestCase |
12 | all_fixtures |
13 | |
14 | def setup |
15 | @controller = UsersController.new |
16 | @request = ActionController::TestRequest.new |
17 | @response = ActionController::TestResponse.new |
18 | end |
19 | |
20 | def test_should_get_index |
21 | get :index |
22 | assert_response :success |
23 | assert assigns(:users) |
24 | assert_select 'html>head' |
25 | end |
26 | |
27 | def test_should_get_index_as_xml |
28 | get :index, :format => 'xml' |
29 | assert_response :success |
30 | assert_select 'users>user' |
31 | end |
32 | |
33 | def test_should_get_new |
34 | get :new |
35 | assert_response :success |
36 | end |
37 | |
38 | def test_should_not_allow_user_creation_with_xml |
39 | post :create, :user => { :login => 'nico', :email => 'nico@email.com', :password => 'fooey', :password_confirmation => 'fooey' }, :format => 'xml' |
40 | assert_response 406 |
41 | end |
42 | |
43 | def test_should_create_user |
44 | assert_difference User, :count do |
45 | post :create, :user => { :login => 'nico', :email => 'nico@email.com', :password => 'fooey', :password_confirmation => 'fooey' } |
46 | end |
47 | assert_not_nil assigns(:user).login_key |
48 | assert !assigns(:user).activated? |
49 | assert_redirected_to login_path |
50 | # => JOSH: can be removed if new sessions stuff works out |
51 | # assert_not_nil assigns(:user).last_seen_at |
52 | |
53 | # assert_redirected_to user_path(assigns(:user)) |
54 | end |
55 | |
56 | def test_should_reset_login_key_for_forgotten_password |
57 | old_key = users(:sam).login_key |
58 | assert_difference User, :count, 0 do |
59 | post :create, :email => users(:sam).email |
60 | end |
61 | assert_redirected_to login_path |
62 | assert old_key != users(:sam).reload.login_key |
63 | end |
64 | |
65 | def test_should_require_password |
66 | assert_difference User, :count, 0 do |
67 | post :create, :user => { :password => '', :password_confirmation => '', :login => '', :email => '' } |
68 | assert_template 'new' |
69 | end |
70 | end |
71 | |
72 | def test_should_not_bomb_when_resetting_invalid_email |
73 | assert_difference User, :count, 0 do |
74 | post :create, :email => 'whatever' |
75 | end |
76 | assert_redirected_to login_path |
77 | end |
78 | |
79 | def test_should_show_user |
80 | get :show, :id => 1 |
81 | assert_response :success |
82 | assert_select 'html>head' |
83 | end |
84 | |
85 | def test_should_show_user_with_xml |
86 | get :show, :id => 1, :format => 'xml' |
87 | assert_response :success |
88 | assert_select 'user' |
89 | end |
90 | |
91 | def test_should_require_valid_user |
92 | login_as :sam |
93 | get :edit, :id => users(:aaron).id |
94 | assert_redirected_to login_path |
95 | end |
96 | |
97 | def test_should_get_edit |
98 | login_as :aaron |
99 | get :edit, :id => users(:aaron).id |
100 | assert_response :success |
101 | end |
102 | |
103 | def test_should_get_edit_as_admin |
104 | login_as :aaron |
105 | get :edit, :id => users(:sam).id |
106 | assert_response :success |
107 | end |
108 | |
109 | def test_should_update_user |
110 | login_as :aaron |
111 | put :update, :id => 1, :user => { } |
112 | assert_redirected_to edit_user_path(assigns(:user)) |
113 | end |
114 | |
115 | def test_should_update_user_with_xml |
116 | authorize_as :aaron |
117 | put :update, :id => 1, :user => { }, :format => 'xml' |
118 | assert_response :success |
119 | end |
120 | |
121 | def test_should_only_update_safe_fields |
122 | # non-admin should not be able to change all this stuff |
123 | login_as :sam |
124 | put :update, :id => users(:sam).id, :user => { :login => "ruby", :created_at => "2005-10-24", :updated_at => "2004-10-24", :last_login_at => "2005-10-24", :last_seen_at => "2005-10-24", :posts_count => "1000", :admin => "1" } |
125 | assert_redirected_to edit_user_path(assigns(:user)) |
126 | assert_equal users(:sam), assigns(:user) |
127 | [:created_at, :last_login_at, :posts_count, :admin].each do |attr| |
128 | assert_equal users(:sam).send(attr), assigns(:user).send(attr), "#{attr}" |
129 | end |
130 | assert_not_equal 2004, users(:sam).reload.updated_at.year |
131 | assert_not_equal 2005, users(:sam).last_seen_at |
132 | assert_equal 'sam', users(:sam).login |
133 | assert_equal 2, users(:sam).posts_count |
134 | assert !users(:sam).admin? |
135 | end |
136 | |
137 | def test_admin_can_destroy_user |
138 | login_as :aaron |
139 | old_count = User.count |
140 | delete :destroy, :id => 2 |
141 | assert_equal old_count-1, User.count |
142 | |
143 | assert_redirected_to users_path |
144 | end |
145 | |
146 | def test_normal_user_cannot_destroy_others |
147 | login_as :sam |
148 | old_count = User.count |
149 | delete :destroy, :id => 1 |
150 | assert_equal old_count, User.count |
151 | |
152 | assert_redirected_to login_path |
153 | end |
154 | |
155 | def test_admin_can_destroy_user_with_xml |
156 | authorize_as :aaron |
157 | old_count = User.count |
158 | delete :destroy, :id => 2, :format => 'xml' |
159 | assert_equal old_count-1, User.count |
160 | |
161 | assert_response :success |
162 | end |
163 | |
164 | def test_normal_user_cannot_destroy_others_with_xml |
165 | authorize_as :sam |
166 | old_count = User.count |
167 | delete :destroy, :id => 1, :format => 'xml' |
168 | assert_equal old_count, User.count |
169 | |
170 | assert_response 401 |
171 | end |
172 | |
173 | def test_should_not_allow_setting_admin_with_xml |
174 | authorize_as :aaron |
175 | post :admin, :id => users(:sam).id, :user => { :admin => '1' }, :format => 'xml' |
176 | assert_response 406 |
177 | end |
178 | |
179 | def test_should_set_admin |
180 | assert !users(:sam).admin? |
181 | |
182 | login_as :aaron |
183 | post :admin, :id => users(:sam).id, :user => { :admin => '1' } |
184 | assert_redirected_to user_path(users(:sam)) |
185 | |
186 | assert users(:sam).reload.admin? |
187 | end |
188 | |
189 | def test_should_add_moderator |
190 | assert !users(:sam).moderator_of?(forums(:comics)) |
191 | |
192 | login_as :aaron |
193 | post :admin, :id => users(:sam).id, :user => { :admin => '1' }, :moderator => forums(:comics) |
194 | assert_redirected_to user_path(users(:sam)) |
195 | |
196 | assert users(:sam).moderator_of?(forums(:comics)) |
197 | end |
198 | |
199 | def test_should_require_admin_to_set_admin_properties |
200 | login_as :sam |
201 | post :admin, :id => users(:sam).id |
202 | assert_redirected_to login_path |
203 | end |
204 | |
205 | # users should not be able to destroy themselves unless we're using AAP or something |
206 | def test_normal_user_cannot_destroy_themselves |
207 | login_as :sam |
208 | assert_difference User, :count, 0 do |
209 | delete :destroy, :id => users(:sam).id |
210 | end |
211 | assert_redirected_to login_path |
212 | end |
213 | |
214 | def test_should_not_activate_user_with_xml |
215 | get :activate, :key => users(:kyle).login_key, :format => 'xml' |
216 | assert_response 406 |
217 | end |
218 | |
219 | def test_should_activate_user |
220 | assert !users(:kyle).activated? |
221 | get :activate, :key => users(:kyle).login_key |
222 | assert_redirected_to home_path |
223 | assert users(:kyle).reload.activated? |
224 | assert_equal users(:kyle).id, session[:user_id] |
225 | end |
226 | |
227 | def test_should_not_activate_invalid_key |
228 | get :activate, :key => 'bad key' |
229 | assert_redirected_to home_path |
230 | end |
231 | |
232 | def test_should_not_disturb_activated_user |
233 | assert users(:sam).activated? |
234 | get :activate, :key => users(:sam).login_key |
235 | assert users(:sam).reload.activated? |
236 | assert_redirected_to home_path |
237 | end |
238 | end |