X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f8de0c1811a21a552541acd2288d191e872ca434..965f32d545d7c44ad7b36264b818b930a50d8901:/test/controllers/user_controller_test.rb diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index 609f3fe67..ede841032 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -209,6 +209,24 @@ class UserControllerTest < ActionController::TestCase end end + def test_new_view_logged_in + session[:user] = users(:normal_user).id + + get :new + assert_response :redirect + assert_redirected_to user_new_path(:cookie_test => "true") + get :new, :cookie_test => "true" + assert_response :redirect + assert_redirected_to root_path + + get :new, :referer => "/test" + assert_response :redirect + assert_redirected_to user_new_path(:referer => "/test", :cookie_test => "true") + get :new, :referer => "/test", :cookie_test => "true" + assert_response :redirect + assert_redirected_to "/test" + end + def test_new_success user = new_user @@ -332,6 +350,27 @@ class UserControllerTest < ActionController::TestCase assert_redirected_to "/test" end + def test_logout_with_token + token = users(:normal_user).tokens.create + + session[:token] = token.token + + get :logout + assert_response :success + assert_template :logout + assert_select "input[name=referer][value=?]", "" + assert_equal token.token, session[:token] + assert_not_nil UserToken.where(:id => token.id).first + + session_id = assert_select("input[name=session]").first["value"] + + get :logout, :session => session_id + assert_response :redirect + assert_redirected_to root_path + assert_nil session[:token] + assert_nil UserToken.where(:id => token.id).first + end + def test_confirm_get user = users(:inactive_user) confirm_string = user.tokens.create.token @@ -435,6 +474,8 @@ class UserControllerTest < ActionController::TestCase end def test_confirm_resend_success + session[:token] = users(:inactive_user).tokens.create.token + assert_difference "ActionMailer::Base.deliveries.size", 1 do get :confirm_resend, :display_name => users(:inactive_user).display_name end @@ -450,7 +491,17 @@ class UserControllerTest < ActionController::TestCase ActionMailer::Base.deliveries.clear end - def test_confirm_resend_failure + def test_confirm_resend_no_token + assert_no_difference "ActionMailer::Base.deliveries.size" do + get :confirm_resend, :display_name => users(:inactive_user).display_name + end + + assert_response :redirect + assert_redirected_to login_path + assert_match "User Inactive User not found.", flash[:error] + end + + def test_confirm_resend_unknown_user assert_no_difference "ActionMailer::Base.deliveries.size" do get :confirm_resend, :display_name => "No Such User" end @@ -496,6 +547,42 @@ class UserControllerTest < ActionController::TestCase assert_match /confirmation code has expired or does not exist/, flash[:error] end + ## + # test if testing for a gravatar works + # this happens when the email is actually changed + # which is triggered by the confirmation mail + def test_gravatar_auto_enable + with_http_stubs "gravatar" do + # switch to email that has a gravatar + user = users(:first_gravatar_user) + confirm_string = user.tokens.create.token + # precondition gravatar should be turned off + assert !user.image_use_gravatar + post :confirm_email, :confirm_string => confirm_string + assert_response :redirect + 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 enabled + assert User.find(users(:first_gravatar_user).id).image_use_gravatar + end + end + + def test_gravatar_auto_disable + with_http_stubs "gravatar" do + # switch to email without a gravatar + user = users(:second_gravatar_user) + confirm_string = user.tokens.create.token + # precondition gravatar should be turned on + assert user.image_use_gravatar + post :confirm_email, :confirm_string => confirm_string + assert_response :redirect + 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(users(:second_gravatar_user).id).image_use_gravatar + end + end + def test_terms_new_user get :terms, {}, { :new_user => User.new } assert_response :success @@ -505,17 +592,53 @@ class UserControllerTest < ActionController::TestCase def test_terms_seen user = users(:normal_user) - get :terms, {}, { :user => user } + session[:user] = user.id + + get :terms assert_response :redirect assert_redirected_to :action => :account, :display_name => user.display_name end - def test_terms_not_seen + def test_terms_not_seen_without_referer user = users(:terms_not_seen_user) - get :terms, {}, { :user => user } + session[:user] = user.id + + get :terms assert_response :success assert_template :terms + + post :save, :user => { :consider_pd => true } + assert_response :redirect + assert_redirected_to :action => :account, :display_name => user.display_name + assert_equal "Thanks for accepting the new contributor terms!", flash[:notice] + + user.reload + + assert_equal true, user.consider_pd + assert_not_nil user.terms_agreed + assert_equal true, user.terms_seen + end + + def test_terms_not_seen_with_referer + user = users(:terms_not_seen_user) + + session[:user] = user.id + + get :terms, :referer => "/test" + assert_response :success + assert_template :terms + + post :save, :user => { :consider_pd => true }, :referer => "/test" + assert_response :redirect + assert_redirected_to "/test" + assert_equal "Thanks for accepting the new contributor terms!", flash[:notice] + + user.reload + + assert_equal true, user.consider_pd + assert_not_nil user.terms_agreed + assert_equal true, user.terms_seen end def test_go_public @@ -615,7 +738,8 @@ class UserControllerTest < ActionController::TestCase # Test setting a new password post :reset_password, :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" } assert_response :redirect - assert_redirected_to :action => :login + assert_redirected_to root_path + assert_equal users(:inactive_user).id, session[:user] user = User.find(users(:inactive_user).id) assert_equal "active", user.status assert_equal true, user.email_valid @@ -705,6 +829,11 @@ class UserControllerTest < ActionController::TestCase assert_select ".notice", /^User information updated successfully/ assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked]", false + # Adding external authentication should redirect to the auth provider + post :account, { :display_name => user.display_name, :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }, { :user => user.id } + assert_response :redirect + assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{user.display_name}/account") + # Changing name to one that exists should fail new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name) post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id } @@ -868,7 +997,7 @@ class UserControllerTest < ActionController::TestCase assert_select "contributor-terms", :count => 1 do assert_select "[agreed='true']" end - assert_select "img", :count => 1 + assert_select "img", :count => 0 assert_select "roles", :count => 1 do assert_select "role", :count => 0 end @@ -920,7 +1049,7 @@ class UserControllerTest < ActionController::TestCase assert_select "contributor-terms", :count => 1 do assert_select "[agreed='true'][pd='false']" end - assert_select "img", :count => 1 + assert_select "img", :count => 0 assert_select "roles", :count => 1 do assert_select "role", :count => 0 end @@ -1241,7 +1370,7 @@ class UserControllerTest < ActionController::TestCase get :list, :page => 3 assert_response :success assert_template :list - assert_select "table#user_list tr", :count => 19 + assert_select "table#user_list tr", :count => 25 end def test_list_post_confirm