require "test_helper"
class UserControllerTest < ActionController::TestCase
- api_fixtures
-
def setup
stub_hostip_requests
end
basic_authorization(user.email, "test")
get :api_gpx_files
assert_response :success
- assert_equal "text/xml", response.content_type
+ assert_equal "application/xml", response.content_type
# check the data that is returned
assert_select "gpx_file[id='#{trace1.id}']", 1 do
end
def test_list_get
+ user = create(:user)
+ moderator_user = create(:moderator_user)
+ administrator_user = create(:administrator_user)
+ _suspended_user = create(:user, :suspended)
+ _ip_user = create(:user, :creation_ip => "1.2.3.4")
+
+ # There are now 7 users - the five above, plus two extra "granters" for the
+ # moderator_user and administrator_user
+ assert_equal 7, User.count
+
# Shouldn't work when not logged in
get :list
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path
- session[:user] = create(:user).id
+ session[:user] = 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] = create(:moderator_user).id
+ session[:user] = 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] = create(:administrator_user).id
+ session[:user] = administrator_user.id
+ # Note there is a header row, so all row counts are users + 1
# 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
+ assert_select "table#user_list tr", :count => 7 + 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
+ assert_select "table#user_list tr", :count => 1 + 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
+ assert_select "table#user_list tr", :count => 1 + 1
end
def test_list_get_paginated
session[:user] = create(:administrator_user).id
+ # 100 examples, an administrator, and a granter for the admin.
+ assert_equal 102, User.count
+
get :list
assert_response :success
assert_template :list
get :list, :page => 3
assert_response :success
assert_template :list
- assert_select "table#user_list tr", :count => 28
+ assert_select "table#user_list tr", :count => 3
end
def test_list_post_confirm