-require 'test_helper'
+require "test_helper"
class UserControllerTest < ActionController::TestCase
- fixtures :users
-
+ fixtures :users, :user_blocks, :user_roles, :changesets, :gpx_files, :messages
+
##
# test all routes which lead to this controller
def test_routes
def test_user_create_success
user = new_user
- assert_difference('User.count', 1) do
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
- post :save, {}, {:new_user => user}
+ assert_difference("User.count", 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
+ post :save, {}, { :new_user => user }
end
end
assert_match /#{@url}/, register_email.body.to_s
# Check the page
- assert_redirected_to :action => 'confirm', :display_name => user.display_name
+ assert_redirected_to :action => "confirm", :display_name => user.display_name
ActionMailer::Base.deliveries.clear
end
user = new_user
user.email = users(:public_user).email
- assert_no_difference('User.count') do
- assert_no_difference('ActionMailer::Base.deliveries.size') do
- post :save, {}, {:new_user => user}
+ assert_no_difference("User.count") do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
+ post :save, {}, { :new_user => user }
end
end
assert_response :success
- assert_template 'new'
+ assert_template "new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
end
user = new_user
user.email = users(:public_user).email.upcase
- assert_no_difference('User.count') do
- assert_no_difference('ActionMailer::Base.deliveries.size') do
- post :save, {}, {:new_user => user}
+ assert_no_difference("User.count") do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
+ post :save, {}, { :new_user => user }
end
end
assert_response :success
- assert_template 'new'
+ assert_template "new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
end
-
+
def test_user_create_submit_duplicate_name
user = new_user
user.display_name = users(:public_user).display_name
- assert_no_difference('User.count') do
- assert_no_difference('ActionMailer::Base.deliveries.size') do
- post :save, {}, {:new_user => user}
+ assert_no_difference("User.count") do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
+ post :save, {}, { :new_user => user }
end
end
assert_response :success
- assert_template 'new'
+ assert_template "new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
end
-
+
def test_user_create_submit_duplicate_name_uppercase
user = new_user
user.display_name = users(:public_user).display_name.upcase
- assert_no_difference('User.count') do
- assert_no_difference('ActionMailer::Base.deliveries.size') do
- post :save, {}, {:new_user => user}
+ assert_no_difference("User.count") do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
+ post :save, {}, { :new_user => user }
end
end
assert_response :success
- assert_template 'new'
+ assert_template "new"
assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
end
def test_user_save_referer_params
user = new_user
- assert_difference('User.count', 1) do
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
- post :save, {}, {:new_user => user,
- :referer => '/edit?editor=id#map=1/2/3'}
- end
+ assert_difference("User.count", 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
+ post :save, {}, { :new_user => user,
+ :referer => "/edit?editor=id#map=1/2/3" }
+ end
end
- assert_equal welcome_path(:editor => 'id', :zoom => 1, :lat => 2, :lon => 3),
+ assert_equal welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3),
user.tokens.order("id DESC").first.referer
ActionMailer::Base.deliveries.clear
@request.cookies["_osm_session"] = user.display_name
post :confirm, :confirm_string => token.token
- assert_redirected_to :action => 'confirm'
+ assert_redirected_to :action => "confirm"
assert_match /expired/, flash[:error]
end
@request.cookies["_osm_session"] = user.display_name
post :confirm, :confirm_string => token.token
- assert_redirected_to :action => 'login'
+ assert_redirected_to :action => "login"
assert_match /confirmed/, flash[:error]
end
# Test resetting using the address as recorded for a user that has an
# address which is duplicated in a different case by another user
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :lost_password, :user => { :email => users(:normal_user).email }
end
assert_response :redirect
# Test resetting using an address that matches a different user
# that has the same address in a different case
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :lost_password, :user => { :email => users(:normal_user).email.upcase }
end
assert_response :redirect
# Test resetting using an address that is a case insensitive match
# for more than one user but not an exact match for either
- assert_difference('ActionMailer::Base.deliveries.size', 0) do
+ assert_difference("ActionMailer::Base.deliveries.size", 0) do
post :lost_password, :user => { :email => users(:normal_user).email.titlecase }
end
assert_response :success
# Test resetting using the address as recorded for a user that has an
# address which is case insensitively unique
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :lost_password, :user => { :email => users(:public_user).email }
end
assert_response :redirect
# Test resetting using an address that matches a user that has the
# same (case insensitively unique) address in a different case
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :lost_password, :user => { :email => users(:public_user).email.upcase }
end
assert_response :redirect
# Make sure that you are redirected to the login page when
# you are not logged in
- get :account, { :display_name => user.display_name }
+ get :account, :display_name => user.display_name
assert_response :redirect
assert_redirected_to :controller => :user, :action => "login", :referer => "/user/test/account"
# Changing email to one that exists should fail
user.new_email = users(:public_user).email
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
end
assert_response :success
# Changing email to one that exists should fail, regardless of case
user.new_email = users(:public_user).email.upcase
- assert_no_difference('ActionMailer::Base.deliveries.size') do
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
end
assert_response :success
# Changing email to one that doesn't exist should work
user.new_email = "new_tester@example.com"
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
end
assert_response :success
assert_equal user.new_email, email.to.first
ActionMailer::Base.deliveries.clear
end
-
+
# Check that the user account page will display and contains some relevant
# information for the user
def test_user_view_account
# Test a non-existent user
- get :view, {:display_name => "unknown"}
+ get :view, :display_name => "unknown"
assert_response :not_found
-
+
# Test a normal user
- get :view, {:display_name => "test"}
+ get :view, :display_name => "test"
assert_response :success
assert_select "div#userinformation" do
assert_select "a[href^='/user/test/history']", 1
assert_select "a[href='/user/test/blocks_by']", 0
assert_select "a[href='/blocks/new/test']", 0
end
-
+
# Test a user who has been blocked
- get :view, {:display_name => "blocked"}
+ get :view, :display_name => "blocked"
assert_response :success
assert_select "div#userinformation" do
assert_select "a[href^='/user/blocked/history']", 1
assert_select "a[href='/user/blocked/blocks_by']", 0
assert_select "a[href='/blocks/new/blocked']", 0
end
-
+
# Test a moderator who has applied blocks
- get :view, {:display_name => "moderator"}
+ get :view, :display_name => "moderator"
assert_response :success
assert_select "div#userinformation" do
assert_select "a[href^='/user/moderator/history']", 1
session[:user] = users(:normal_user).id
# Test the normal user
- get :view, {:display_name => "test"}
+ get :view, :display_name => "test"
assert_response :success
assert_select "div#userinformation" do
assert_select "a[href^='/user/test/history']", 1
session[:user] = users(:moderator_user).id
# Test the normal user
- get :view, {:display_name => "test"}
+ get :view, :display_name => "test"
assert_response :success
assert_select "div#userinformation" do
assert_select "a[href^='/user/test/history']", 1
# check that nothing is returned when not logged in
get :api_details
assert_response :unauthorized
-
+
# check that we get a response when logged in
basic_authorization(users(:normal_user).email, "test")
get :api_details
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# When not logged in a GET should ask us to login
- get :make_friend, {:display_name => friend.display_name}
+ get :make_friend, :display_name => friend.display_name
assert_redirected_to :controller => :user, :action => "login", :referer => make_friend_path(:display_name => friend.display_name)
# When not logged in a POST should error
- post :make_friend, {:display_name => friend.display_name}
+ post :make_friend, :display_name => friend.display_name
assert_response :forbidden
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# When logged in a GET should get a confirmation page
- get :make_friend, {:display_name => friend.display_name}, {"user" => user}
+ get :make_friend, { :display_name => friend.display_name }, { "user" => user }
assert_response :success
assert_template :make_friend
assert_select "form" do
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# The GET should preserve any referer
- get :make_friend, {:display_name => friend.display_name, :referer => "/test"}, {"user" => user}
+ get :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { "user" => user }
assert_response :success
assert_template :make_friend
assert_select "form" do
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# When logged in a POST should add the friendship
- assert_difference('ActionMailer::Base.deliveries.size', 1) do
- post :make_friend, {:display_name => friend.display_name}, {"user" => user}
+ assert_difference("ActionMailer::Base.deliveries.size", 1) do
+ post :make_friend, { :display_name => friend.display_name }, { "user" => user }
end
assert_redirected_to user_path(:display_name => friend.display_name)
assert_match /is now your friend/, flash[:notice]
ActionMailer::Base.deliveries.clear
# A second POST should report that the friendship already exists
- assert_no_difference('ActionMailer::Base.deliveries.size') do
- post :make_friend, {:display_name => friend.display_name}, {"user" => user}
+ assert_no_difference("ActionMailer::Base.deliveries.size") do
+ post :make_friend, { :display_name => friend.display_name }, { "user" => user }
end
assert_redirected_to user_path(:display_name => friend.display_name)
assert_match /You are already friends with/, flash[:warning]
assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# When not logged in a GET should ask us to login
- get :remove_friend, {:display_name => friend.display_name}
+ get :remove_friend, :display_name => friend.display_name
assert_redirected_to :controller => :user, :action => "login", :referer => remove_friend_path(:display_name => friend.display_name)
# When not logged in a POST should error
- post :remove_friend, {:display_name => friend.display_name}
+ post :remove_friend, :display_name => friend.display_name
assert_response :forbidden
assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# When logged in a GET should get a confirmation page
- get :remove_friend, {:display_name => friend.display_name}, {"user" => user}
+ get :remove_friend, { :display_name => friend.display_name }, { "user" => user }
assert_response :success
assert_template :remove_friend
assert_select "form" do
assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# The GET should preserve any referer
- get :remove_friend, {:display_name => friend.display_name, :referer => "/test"}, {"user" => user}
+ get :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { "user" => user }
assert_response :success
assert_template :remove_friend
assert_select "form" do
assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# When logged in a POST should remove the friendship
- post :remove_friend, {:display_name => friend.display_name}, {"user" => user}
+ post :remove_friend, { :display_name => friend.display_name }, { "user" => user }
assert_redirected_to user_path(:display_name => friend.display_name)
assert_match /was removed from your friends/, flash[:notice]
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# A second POST should report that the friendship does not exist
- post :remove_friend, {:display_name => friend.display_name}, {"user" => user}
+ post :remove_friend, { :display_name => friend.display_name }, { "user" => user }
assert_redirected_to user_path(:display_name => friend.display_name)
assert_match /is not one of your friends/, flash[:error]
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
def test_set_status
# Try without logging in
- get :set_status, {:display_name => users(:normal_user).display_name, :status => "suspended"}
+ get :set_status, :display_name => users(:normal_user).display_name, :status => "suspended"
assert_response :redirect
assert_redirected_to :action => :login, :referer => set_status_user_path(:status => "suspended")
# Now try as a normal user
- get :set_status, {:display_name => users(:normal_user).display_name, :status => "suspended"}, {:user => users(:normal_user).id}
+ get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
# Finally try as an administrator
- get :set_status, {:display_name => users(:normal_user).display_name, :status => "suspended"}, {:user => users(:administrator_user).id}
+ get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
assert_equal "suspended", User.find(users(:normal_user).id).status
def test_delete
# Try without logging in
- get :delete, {:display_name => users(:normal_user).display_name, :status => "suspended"}
+ get :delete, :display_name => users(:normal_user).display_name, :status => "suspended"
assert_response :redirect
assert_redirected_to :action => :login, :referer => delete_user_path(:status => "suspended")
# Now try as a normal user
- get :delete, {:display_name => users(:normal_user).display_name, :status => "suspended"}, {:user => users(:normal_user).id}
+ get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
# Finally try as an administrator
- get :delete, {:display_name => users(:normal_user).display_name, :status => "suspended"}, {:user => users(:administrator_user).id}
+ get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name