X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/15b104f4ff4614aa78c01180b6a9b89dd5a1400f..983e21db2e3ccc5f645f40a5f076d35e2b7897c2:/test/controllers/user_controller_test.rb diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index e149b83c7..ba4b2ff3a 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -20,6 +20,10 @@ class UserControllerTest < ActionController::TestCase { :path => "/api/0.6/user/gpx_files", :method => :get }, { :controller => "user", :action => "api_gpx_files" } ) + assert_routing( + { :path => "/api/0.6/users", :method => :get }, + { :controller => "user", :action => "api_users" } + ) assert_routing( { :path => "/login", :method => :get }, @@ -126,7 +130,7 @@ class UserControllerTest < ActionController::TestCase assert_routing( { :path => "/user/username", :method => :get }, - { :controller => "user", :action => "view", :display_name => "username" } + { :controller => "user", :action => "show", :display_name => "username" } ) assert_routing( @@ -567,7 +571,7 @@ class UserControllerTest < ActionController::TestCase stub_gravatar_request(user.new_email, 200) confirm_string = user.tokens.create.token # precondition gravatar should be turned off - assert !user.image_use_gravatar + assert_not user.image_use_gravatar post :confirm_email, :params => { :confirm_string => confirm_string } assert_response :redirect assert_redirected_to :action => :account, :display_name => user.display_name @@ -588,7 +592,7 @@ class UserControllerTest < ActionController::TestCase assert_redirected_to :action => :account, :display_name => user.display_name assert_match /Confirmed your change of email address/, flash[:notice] # gravatar use should now be disabled - assert !User.find(user.id).image_use_gravatar + assert_not User.find(user.id).image_use_gravatar end def test_terms_new_user @@ -931,14 +935,14 @@ class UserControllerTest < ActionController::TestCase # Check that the user account page will display and contains some relevant # information for the user - def test_view + def test_show # Test a non-existent user - get :view, :params => { :display_name => "unknown" } + get :show, :params => { :display_name => "unknown" } assert_response :not_found # Test a normal user user = create(:user) - get :view, :params => { :display_name => user.display_name } + get :show, :params => { :display_name => user.display_name } assert_response :success assert_select "div#userinformation" do assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1 @@ -954,7 +958,7 @@ class UserControllerTest < ActionController::TestCase # Test a user who has been blocked blocked_user = create(:user) create(:user_block, :user => blocked_user) - get :view, :params => { :display_name => blocked_user.display_name } + get :show, :params => { :display_name => blocked_user.display_name } assert_response :success assert_select "div#userinformation" do assert_select "a[href^='/user/#{ERB::Util.u(blocked_user.display_name)}/history']", 1 @@ -970,7 +974,7 @@ class UserControllerTest < ActionController::TestCase # Test a moderator who has applied blocks moderator_user = create(:moderator_user) create(:user_block, :creator => moderator_user) - get :view, :params => { :display_name => moderator_user.display_name } + get :show, :params => { :display_name => moderator_user.display_name } assert_response :success assert_select "div#userinformation" do assert_select "a[href^='/user/#{ERB::Util.u(moderator_user.display_name)}/history']", 1 @@ -987,7 +991,7 @@ class UserControllerTest < ActionController::TestCase session[:user] = user.id # Test the normal user - get :view, :params => { :display_name => user.display_name } + get :show, :params => { :display_name => user.display_name } assert_response :success assert_select "div#userinformation" do assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1 @@ -1004,7 +1008,7 @@ class UserControllerTest < ActionController::TestCase session[:user] = create(:moderator_user).id # Test the normal user - get :view, :params => { :display_name => user.display_name } + get :show, :params => { :display_name => user.display_name } assert_response :success assert_select "div#userinformation" do assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1 @@ -1024,13 +1028,13 @@ class UserControllerTest < ActionController::TestCase seen_user = create(:user, :terms_seen => true) not_seen_user = create(:user, :terms_seen => false) - get :view, :params => { :display_name => agreed_user.display_name } + get :show, :params => { :display_name => agreed_user.display_name } assert_response :success assert_select "div#userinformation" do assert_select "p", :count => 0, :text => /Contributor terms/ end - get :view, :params => { :display_name => seen_user.display_name } + get :show, :params => { :display_name => seen_user.display_name } assert_response :success # put @response.body assert_select "div#userinformation" do @@ -1038,7 +1042,7 @@ class UserControllerTest < ActionController::TestCase assert_select "p", /Declined/ end - get :view, :params => { :display_name => not_seen_user.display_name } + get :show, :params => { :display_name => not_seen_user.display_name } assert_response :success assert_select "div#userinformation" do assert_select "p", :count => 1, :text => /Contributor terms/ @@ -1146,6 +1150,48 @@ class UserControllerTest < ActionController::TestCase end end + def test_api_users + user1 = create(:user, :description => "test1", :terms_agreed => Date.yesterday) + user2 = create(:user, :description => "test2", :terms_agreed => Date.yesterday) + user3 = create(:user, :description => "test3", :terms_agreed => Date.yesterday) + + get :api_users, :params => { :users => user1.id } + assert_response :success + assert_equal "text/xml", response.content_type + assert_select "user", :count => 1 do + assert_select "user[id='#{user1.id}']", :count => 1 + assert_select "user[id='#{user2.id}']", :count => 0 + assert_select "user[id='#{user3.id}']", :count => 0 + end + + get :api_users, :params => { :users => user2.id } + assert_response :success + assert_equal "text/xml", response.content_type + assert_select "user", :count => 1 do + assert_select "user[id='#{user1.id}']", :count => 0 + assert_select "user[id='#{user2.id}']", :count => 1 + assert_select "user[id='#{user3.id}']", :count => 0 + end + + get :api_users, :params => { :users => "#{user1.id},#{user3.id}" } + assert_response :success + assert_equal "text/xml", response.content_type + assert_select "user", :count => 2 do + assert_select "user[id='#{user1.id}']", :count => 1 + assert_select "user[id='#{user2.id}']", :count => 0 + assert_select "user[id='#{user3.id}']", :count => 1 + end + + get :api_users, :params => { :users => create(:user, :suspended).id } + assert_response :not_found + + get :api_users, :params => { :users => create(:user, :deleted).id } + assert_response :not_found + + get :api_users, :params => { :users => 0 } + assert_response :not_found + end + def test_api_gpx_files user = create(:user) trace1 = create(:trace, :user => user) do |trace| @@ -1344,12 +1390,12 @@ class UserControllerTest < ActionController::TestCase # Now try as a normal user get :set_status, :params => { :display_name => user.display_name, :status => "suspended" }, :session => { :user => user } assert_response :redirect - assert_redirected_to :action => :view, :display_name => user.display_name + assert_redirected_to :action => :show, :display_name => user.display_name # Finally try as an administrator get :set_status, :params => { :display_name => user.display_name, :status => "suspended" }, :session => { :user => create(:administrator_user) } assert_response :redirect - assert_redirected_to :action => :view, :display_name => user.display_name + assert_redirected_to :action => :show, :display_name => user.display_name assert_equal "suspended", User.find(user.id).status end @@ -1364,12 +1410,12 @@ class UserControllerTest < ActionController::TestCase # Now try as a normal user get :delete, :params => { :display_name => user.display_name, :status => "suspended" }, :session => { :user => user } assert_response :redirect - assert_redirected_to :action => :view, :display_name => user.display_name + assert_redirected_to :action => :show, :display_name => user.display_name # Finally try as an administrator get :delete, :params => { :display_name => user.display_name, :status => "suspended" }, :session => { :user => create(:administrator_user) } assert_response :redirect - assert_redirected_to :action => :view, :display_name => user.display_name + assert_redirected_to :action => :show, :display_name => user.display_name # Check that the user was deleted properly user.reload