Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 171
- Log:
Initial import of Beast 0.9 from downloaded Tarball. Beast is a Ruby
On Rails based forum application. The original tarball came from the
following location:http://s3.amazonaws.com/beast-forum/beast-0.9.tar.gz
The forum post which announced this version's availability was at:
http://beast.caboo.se/forums/1/topics/446
- Author:
- rool
- Date:
- Fri Mar 02 15:51:55 +0000 2007
- Size:
- 5055 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | require 'users_controller' |
3 | |
4 | # Re-raise errors caught by the controller. |
5 | class UsersController; def rescue_action(e) raise e end; end |
6 | |
7 | class UsersControllerTest < Test::Unit::TestCase |
8 | all_fixtures |
9 | |
10 | def setup |
11 | @controller = UsersController.new |
12 | @request = ActionController::TestRequest.new |
13 | @response = ActionController::TestResponse.new |
14 | end |
15 | |
16 | def test_should_get_index |
17 | get :index |
18 | assert_response :success |
19 | assert assigns(:users) |
20 | end |
21 | |
22 | def test_should_get_new |
23 | get :new |
24 | assert_response :success |
25 | end |
26 | |
27 | def test_should_create_user |
28 | assert_difference User, :count do |
29 | post :create, :user => { :login => 'nico', :email => 'nico@email.com', :password => 'fooey', :password_confirmation => 'fooey' } |
30 | end |
31 | assert_not_nil assigns(:user).login_key |
32 | assert !assigns(:user).activated? |
33 | assert_redirected_to login_path |
34 | # => JOSH: can be removed if new sessions stuff works out |
35 | # assert_not_nil assigns(:user).last_seen_at |
36 | |
37 | # assert_redirected_to user_path(assigns(:user)) |
38 | end |
39 | |
40 | def test_should_reset_login_key_for_forgotten_password |
41 | old_key = users(:sam).login_key |
42 | assert_difference User, :count, 0 do |
43 | post :create, :email => users(:sam).email |
44 | end |
45 | assert_redirected_to login_path |
46 | assert old_key != users(:sam).reload.login_key |
47 | end |
48 | |
49 | def test_should_not_bomb_when_resetting_invalid_email |
50 | assert_difference User, :count, 0 do |
51 | post :create, :email => 'whatever' |
52 | end |
53 | assert_redirected_to login_path |
54 | end |
55 | |
56 | def test_should_show_user |
57 | get :show, :id => 1 |
58 | assert_response :success |
59 | end |
60 | |
61 | def test_should_require_valid_user |
62 | login_as :sam |
63 | get :edit, :id => users(:aaron).id |
64 | assert_redirected_to login_path |
65 | end |
66 | |
67 | def test_should_get_edit |
68 | login_as :aaron |
69 | get :edit, :id => users(:aaron).id |
70 | assert_response :success |
71 | end |
72 | |
73 | def test_should_get_edit_as_admin |
74 | login_as :aaron |
75 | get :edit, :id => users(:sam).id |
76 | assert_response :success |
77 | end |
78 | |
79 | def test_should_update_user |
80 | login_as :aaron |
81 | put :update, :id => 1, :user => { } |
82 | assert_redirected_to user_path(assigns(:user)) |
83 | end |
84 | |
85 | def test_should_only_update_safe_fields |
86 | # non-admin should not be able to change all this stuff |
87 | login_as :sam |
88 | 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" } |
89 | assert_redirected_to user_path(assigns(:user)) |
90 | assert_equal users(:sam), assigns(:user) |
91 | [:created_at, :last_login_at, :posts_count, :admin].each do |attr| |
92 | assert_equal users(:sam).send(attr), assigns(:user).send(attr), "#{attr}" |
93 | end |
94 | assert_not_equal 2004, users(:sam).reload.updated_at.year |
95 | assert_not_equal 2005, users(:sam).last_seen_at |
96 | assert_equal 'sam', users(:sam).login |
97 | assert_equal 2, users(:sam).posts_count |
98 | assert !users(:sam).admin? |
99 | end |
100 | |
101 | def test_admin_can_destroy_user |
102 | login_as :aaron |
103 | old_count = User.count |
104 | delete :destroy, :id => 2 |
105 | assert_equal old_count-1, User.count |
106 | |
107 | assert_redirected_to users_path |
108 | end |
109 | |
110 | def test_normal_user_cannot_destroy_others |
111 | login_as :sam |
112 | old_count = User.count |
113 | delete :destroy, :id => 1 |
114 | assert_equal old_count, User.count |
115 | |
116 | assert_redirected_to login_path |
117 | end |
118 | |
119 | def test_should_set_admin |
120 | assert !users(:sam).admin? |
121 | |
122 | login_as :aaron |
123 | post :admin, :id => users(:sam).id, :user => { :admin => '1' } |
124 | assert_redirected_to user_path(users(:sam)) |
125 | |
126 | assert users(:sam).reload.admin? |
127 | end |
128 | |
129 | def test_should_add_moderator |
130 | assert !users(:sam).moderator_of?(forums(:comics)) |
131 | |
132 | login_as :aaron |
133 | post :admin, :id => users(:sam).id, :user => { :admin => '1' }, :moderator => forums(:comics) |
134 | assert_redirected_to user_path(users(:sam)) |
135 | |
136 | assert users(:sam).moderator_of?(forums(:comics)) |
137 | end |
138 | |
139 | def test_should_require_admin_to_set_admin_properties |
140 | login_as :sam |
141 | post :admin, :id => users(:sam).id |
142 | assert_redirected_to login_path |
143 | end |
144 | |
145 | # users should not be able to destroy themselves unless we're using AAP or something |
146 | def test_normal_user_cannot_destroy_themselves |
147 | login_as :sam |
148 | assert_difference User, :count, 0 do |
149 | delete :destroy, :id => users(:sam).id |
150 | end |
151 | assert_redirected_to login_path |
152 | end |
153 | |
154 | def test_should_activate_user |
155 | assert !users(:kyle).activated? |
156 | get :activate, :key => users(:kyle).login_key |
157 | assert_redirected_to home_path |
158 | assert users(:kyle).reload.activated? |
159 | assert_equal users(:kyle).id, session[:user_id] |
160 | end |
161 | |
162 | def test_should_not_activate_invalid_key |
163 | get :activate, :key => 'bad key' |
164 | assert_redirected_to home_path |
165 | end |
166 | |
167 | def test_should_not_disturb_activated_user |
168 | assert users(:sam).activated? |
169 | get :activate, :key => users(:sam).login_key |
170 | assert users(:sam).reload.activated? |
171 | assert_redirected_to home_path |
172 | end |
173 | end |