UsersController tests cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4501 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
a49c7f95e2
commit
758f2f0a4e
|
@ -120,54 +120,12 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
assert project_ids.include?(2) #private project admin can see
|
assert project_ids.include?(2) #private project admin can see
|
||||||
end
|
end
|
||||||
|
|
||||||
context "GET :new" do
|
def test_new
|
||||||
setup do
|
|
||||||
get :new
|
get :new
|
||||||
end
|
|
||||||
|
|
||||||
should_assign_to :user
|
assert_response :success
|
||||||
should_respond_with :success
|
assert_template :new
|
||||||
should_render_template :new
|
assert assigns(:user)
|
||||||
end
|
|
||||||
|
|
||||||
context "POST :create" do
|
|
||||||
context "when successful" do
|
|
||||||
setup do
|
|
||||||
post :create, :user => {
|
|
||||||
:firstname => 'John',
|
|
||||||
:lastname => 'Doe',
|
|
||||||
:login => 'jdoe',
|
|
||||||
:password => 'test',
|
|
||||||
:password_confirmation => 'test',
|
|
||||||
:mail => 'jdoe@gmail.com',
|
|
||||||
:mail_notification => 'none'
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
should_assign_to :user
|
|
||||||
should_respond_with :redirect
|
|
||||||
should_redirect_to('user edit') { {:controller => 'users', :action => 'edit', :id => User.find_by_login('jdoe')}}
|
|
||||||
|
|
||||||
should 'set the users mail notification' do
|
|
||||||
user = User.last
|
|
||||||
assert_equal 'none', user.mail_notification
|
|
||||||
end
|
|
||||||
|
|
||||||
should 'set the password' do
|
|
||||||
user = User.first(:order => 'id DESC')
|
|
||||||
assert user.check_password?('test')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when unsuccessful" do
|
|
||||||
setup do
|
|
||||||
post :create, :user => {}
|
|
||||||
end
|
|
||||||
|
|
||||||
should_assign_to :user
|
|
||||||
should_respond_with :success
|
|
||||||
should_render_template :new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create
|
def test_create
|
||||||
|
@ -205,6 +163,23 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
assert mail.body.include?('secret')
|
assert mail.body.include?('secret')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_create_with_failure
|
||||||
|
assert_no_difference 'User.count' do
|
||||||
|
post :create, :user => {}
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'new'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_edit
|
||||||
|
get :edit, :id => 2
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'edit'
|
||||||
|
assert_equal User.find(2), assigns(:user)
|
||||||
|
end
|
||||||
|
|
||||||
def test_update
|
def test_update
|
||||||
ActionMailer::Base.deliveries.clear
|
ActionMailer::Base.deliveries.clear
|
||||||
put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
|
put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
|
||||||
|
@ -217,6 +192,15 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
assert ActionMailer::Base.deliveries.empty?
|
assert ActionMailer::Base.deliveries.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_update_with_failure
|
||||||
|
assert_no_difference 'User.count' do
|
||||||
|
put :update, :id => 2, :user => {:firstname => ''}
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'edit'
|
||||||
|
end
|
||||||
|
|
||||||
def test_update_with_group_ids_should_assign_groups
|
def test_update_with_group_ids_should_assign_groups
|
||||||
put :update, :id => 2, :user => {:group_ids => ['10']}
|
put :update, :id => 2, :user => {:group_ids => ['10']}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue