+ def test_list_get
+ # Shouldn't work when not logged in
+ get :list
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path
+
+ session[:user] = users(:normal_user).id
+
+ # Shouldn't work when logged in as a normal user
+ get :list
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path
+
+ session[:user] = users(:moderator_user).id
+
+ # Shouldn't work when logged in as a moderator
+ get :list
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path
+
+ session[:user] = users(:administrator_user).id
+
+ # Should work when logged in as an administrator
+ get :list
+ assert_response :success
+ assert_template :list
+ assert_select "table#user_list tr", :count => User.count + 1
+
+ # Should be able to limit by status
+ get :list, :status => "suspended"
+ assert_response :success
+ assert_template :list
+ assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
+
+ # Should be able to limit by IP address
+ get :list, :ip => "1.2.3.4"
+ assert_response :success
+ assert_template :list
+ assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
+ end
+
+ def test_list_get_paginated
+ 1.upto(100).each do |n|
+ User.create(:display_name => "extra_#{n}",
+ :email => "extra#{n}@example.com",
+ :pass_crypt => "extraextra")
+ end
+
+ session[:user] = users(:administrator_user).id
+
+ get :list
+ assert_response :success
+ assert_template :list
+ assert_select "table#user_list tr", :count => 51
+
+ get :list, :page => 2
+ assert_response :success
+ assert_template :list
+ assert_select "table#user_list tr", :count => 51
+
+ get :list, :page => 3
+ assert_response :success
+ assert_template :list
+ assert_select "table#user_list tr", :count => 25
+ end
+
+ def test_list_post_confirm
+ inactive_user = users(:inactive_user)
+ suspended_user = users(:suspended_user)
+
+ # Shouldn't work when not logged in
+ assert_no_difference "User.active.count" do
+ post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
+ assert_equal "pending", inactive_user.reload.status
+ assert_equal "suspended", suspended_user.reload.status
+
+ session[:user] = users(:normal_user).id
+
+ # Shouldn't work when logged in as a normal user
+ assert_no_difference "User.active.count" do
+ post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
+ assert_equal "pending", inactive_user.reload.status
+ assert_equal "suspended", suspended_user.reload.status
+
+ session[:user] = users(:moderator_user).id
+
+ # Shouldn't work when logged in as a moderator
+ assert_no_difference "User.active.count" do
+ post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
+ assert_equal "pending", inactive_user.reload.status
+ assert_equal "suspended", suspended_user.reload.status
+
+ session[:user] = users(:administrator_user).id
+
+ # Should work when logged in as an administrator
+ assert_difference "User.active.count", 2 do
+ post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :list
+ assert_equal "confirmed", inactive_user.reload.status
+ assert_equal "confirmed", suspended_user.reload.status
+ end
+
+ def test_list_post_hide
+ normal_user = users(:normal_user)
+ confirmed_user = users(:confirmed_user)
+
+ # Shouldn't work when not logged in
+ assert_no_difference "User.active.count" do
+ post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
+ assert_equal "active", normal_user.reload.status
+ assert_equal "confirmed", confirmed_user.reload.status
+
+ session[:user] = users(:normal_user).id
+
+ # Shouldn't work when logged in as a normal user
+ assert_no_difference "User.active.count" do
+ post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
+ assert_equal "active", normal_user.reload.status
+ assert_equal "confirmed", confirmed_user.reload.status
+
+ session[:user] = users(:moderator_user).id
+
+ # Shouldn't work when logged in as a moderator
+ assert_no_difference "User.active.count" do
+ post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
+ assert_equal "active", normal_user.reload.status
+ assert_equal "confirmed", confirmed_user.reload.status
+
+ session[:user] = users(:administrator_user).id
+
+ # Should work when logged in as an administrator
+ assert_difference "User.active.count", -2 do
+ post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :list
+ assert_equal "deleted", normal_user.reload.status
+ assert_equal "deleted", confirmed_user.reload.status
+ end
+