Show More
Commit Description:
force log out when password change
Commit Description:
force log out when password change
References:
File last commit:
Show/Diff file:
Action:
test/functional/user_admin_controller_test.rb
| 142 lines
| 3.1 KiB
| text/x-ruby
| RubyLexer
|
|
r0 | require File.dirname(__FILE__) + '/../test_helper' | ||
require 'user_admin_controller' | ||||
# Re-raise errors caught by the controller. | ||||
class UserAdminController; def rescue_action(e) raise e end; end | ||||
|
r275 | class UserAdminControllerTest < ActionController::TestCase | ||
|
r0 | fixtures :users | ||
|
r58 | fixtures :roles | ||
fixtures :rights | ||||
|
r0 | |||
def setup | ||||
@controller = UserAdminController.new | ||||
@request = ActionController::TestRequest.new | ||||
@response = ActionController::TestResponse.new | ||||
|
r58 | @first_id = users(:john).id | ||
@admin_id = users(:mary).id | ||||
end | ||||
def test_should_not_allow_new_user_to_see | ||||
get :list | ||||
assert_redirected_to :controller => 'main', :action => 'login' | ||||
|
r0 | end | ||
|
r58 | def test_should_not_allow_normal_user_to_see | ||
john = users(:john) | ||||
get :list, {}, {:user_id => john.id} | ||||
assert_redirected_to :controller => 'main', :action => 'login' | ||||
end | ||||
def test_should_allow_admin_to_see | ||||
mary = users(:mary) | ||||
get :list, {}, {:user_id => mary.id} | ||||
assert_template 'user_admin/list' | ||||
end | ||||
|
r0 | def test_index | ||
|
r58 | get :index, {}, {:user_id => @admin_id} | ||
|
r0 | assert_response :success | ||
assert_template 'list' | ||||
end | ||||
def test_list | ||||
|
r58 | get :list, {}, {:user_id => @admin_id} | ||
|
r0 | |||
assert_response :success | ||||
assert_template 'list' | ||||
assert_not_nil assigns(:users) | ||||
end | ||||
def test_show | ||||
|
r58 | get :show, {:id => @first_id}, {:user_id => @admin_id} | ||
|
r0 | |||
assert_response :success | ||||
assert_template 'show' | ||||
assert_not_nil assigns(:user) | ||||
end | ||||
def test_new | ||||
|
r58 | get :new, {}, {:user_id => @admin_id} | ||
|
r0 | |||
assert_response :success | ||||
assert_template 'new' | ||||
assert_not_nil assigns(:user) | ||||
end | ||||
|
r58 | def test_create_with_correct_confirmation_password | ||
|
r0 | num_users = User.count | ||
|
r58 | post :create, {:user => { | ||
:login => 'test', | ||||
:full_name => 'hello', | ||||
:password => 'abcde', | ||||
:password_confirmation => 'abcde' | ||||
}}, {:user_id => @admin_id} | ||||
|
r0 | |||
assert_response :redirect | ||||
assert_redirected_to :action => 'list' | ||||
assert_equal num_users + 1, User.count | ||||
end | ||||
|
r58 | def test_create_with_wrong_confirmation_password | ||
num_users = User.count | ||||
post :create, {:user => { | ||||
:login => 'test', | ||||
:full_name => 'hello', | ||||
:password => 'abcde', | ||||
:password_confirmation => 'abcdef' | ||||
}}, {:user_id => @admin_id} | ||||
assert_response :success | ||||
assert_template 'new' | ||||
assert_equal num_users, User.count | ||||
end | ||||
|
r0 | def test_edit | ||
|
r58 | get :edit, {:id => @first_id}, {:user_id => @admin_id} | ||
|
r0 | |||
assert_response :success | ||||
assert_template 'edit' | ||||
assert_not_nil assigns(:user) | ||||
end | ||||
def test_update | ||||
|
r58 | post :update, { | ||
:id => @first_id, | ||||
:user => { | ||||
:login => 'test', | ||||
:full_name => 'hello', | ||||
:password => 'abcde', | ||||
:password_confirmation => 'abcde' | ||||
} | ||||
}, {:user_id => @admin_id} | ||||
|
r0 | assert_response :redirect | ||
assert_redirected_to :action => 'show', :id => @first_id | ||||
end | ||||
def test_destroy | ||||
assert_nothing_raised { | ||||
User.find(@first_id) | ||||
} | ||||
|
r58 | post :destroy, {:id => @first_id}, {:user_id => @admin_id} | ||
|
r0 | assert_response :redirect | ||
assert_redirected_to :action => 'list' | ||||
assert_raise(ActiveRecord::RecordNotFound) { | ||||
User.find(@first_id) | ||||
} | ||||
end | ||||
end | ||||