X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f8de0c1811a21a552541acd2288d191e872ca434..37a4fc6dd14dfedc0c44a8d7bf6453df0db9e1b5:/test/controllers/user_controller_test.rb diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index 609f3fe67..37b8a7f30 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 @@ -505,17 +556,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_without_referer + user = users(:terms_not_seen_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 + def test_terms_not_seen_with_referer user = users(:terms_not_seen_user) - get :terms, {}, { :user => 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 @@ -705,6 +792,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 } @@ -1241,7 +1333,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 => 22 end def test_list_post_confirm