Fix error if no users are selected for a bulk update
This commit is contained in:
parent
432fa57e61
commit
56e9580de9
2 changed files with 17 additions and 1 deletions
|
@ -33,7 +33,7 @@ module Users
|
|||
##
|
||||
# update status of selected users
|
||||
def update
|
||||
ids = params[:user].keys.collect(&:to_i)
|
||||
ids = params.fetch(:user, {}).keys.collect(&:to_i)
|
||||
|
||||
User.where(:id => ids).update_all(:status => "confirmed") if params[:confirm]
|
||||
User.where(:id => ids).update_all(:status => "deleted") if params[:hide]
|
||||
|
|
|
@ -210,6 +210,14 @@ module Users
|
|||
|
||||
session_for(create(:administrator_user))
|
||||
|
||||
# Should do nothing when no users selected
|
||||
assert_no_difference "User.active.count" do
|
||||
put users_list_path, :params => { :confirm => 1 }
|
||||
end
|
||||
assert_redirected_to :action => :show
|
||||
assert_equal "pending", inactive_user.reload.status
|
||||
assert_equal "suspended", suspended_user.reload.status
|
||||
|
||||
# Should work when logged in as an administrator
|
||||
assert_difference "User.active.count", 2 do
|
||||
put users_list_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
|
||||
|
@ -254,6 +262,14 @@ module Users
|
|||
|
||||
session_for(create(:administrator_user))
|
||||
|
||||
# Should do nothing when no users selected
|
||||
assert_no_difference "User.active.count" do
|
||||
put users_list_path, :params => { :hide => 1 }
|
||||
end
|
||||
assert_redirected_to :action => :show
|
||||
assert_equal "active", normal_user.reload.status
|
||||
assert_equal "confirmed", confirmed_user.reload.status
|
||||
|
||||
# Should work when logged in as an administrator
|
||||
assert_difference "User.active.count", -2 do
|
||||
put users_list_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue