X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/53aa7259bb0612eb48a17d0b954ad71ea37d87a4..507c395f51c20c3c0d5375313ea1ca0ed4156c75:/test/controllers/accounts_controller_test.rb?ds=inline diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb index 173bcf22c..18ad34f66 100644 --- a/test/controllers/accounts_controller_test.rb +++ b/test/controllers/accounts_controller_test.rb @@ -25,7 +25,6 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest # Make sure that you are redirected to the login page when # you are not logged in get edit_account_path - assert_response :redirect assert_redirected_to login_path(:referer => "/account/edit") # Make sure we get the page when we are logged in as the right user @@ -49,10 +48,8 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest # Adding external authentication should redirect to the auth provider patch account_path, :params => { :user => user.attributes.merge(:auth_provider => "google") } - assert_response :redirect assert_redirected_to auth_path(:provider => "google", :origin => "/account") follow_redirect! - assert_response :redirect assert_redirected_to %r{^https://accounts.google.com/o/oauth2/auth\?.*} # Changing name to one that exists should fail @@ -60,27 +57,26 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest patch account_path, :params => { :user => new_attributes } assert_response :success assert_template :edit - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name" + assert_select ".alert-success", false + assert_select "form#accountForm > div > input.is-invalid#user_display_name" # Changing name to one that exists should fail, regardless of case new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name.upcase) patch account_path, :params => { :user => new_attributes } assert_response :success assert_template :edit - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name" + assert_select ".alert-success", false + assert_select "form#accountForm > div > input.is-invalid#user_display_name" # Changing name to one that doesn't exist should work new_attributes = user.attributes.dup.merge(:display_name => "new tester") patch account_path, :params => { :user => new_attributes } - assert_response :redirect assert_redirected_to edit_account_url get edit_account_path assert_response :success assert_template :edit - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > div.form-group > input#user_display_name[value=?]", "new tester" + assert_select ".alert-success", /^User information updated successfully/ + assert_select "form#accountForm > div > input#user_display_name[value=?]", "new tester" # Record the change of name user.display_name = "new tester" @@ -94,8 +90,8 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest end assert_response :success assert_template :edit - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email" + assert_select ".alert-success", false + assert_select "form#accountForm > div > input.is-invalid#user_new_email" # Changing email to one that exists should fail, regardless of case user.new_email = create(:user).email.upcase @@ -106,8 +102,8 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest end assert_response :success assert_template :edit - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email" + assert_select ".alert-success", false + assert_select "form#accountForm > div > input.is-invalid#user_new_email" # Changing email to one that doesn't exist should work user.new_email = "new_tester@example.com" @@ -116,13 +112,12 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest patch account_path, :params => { :user => user.attributes } end end - assert_response :redirect assert_redirected_to edit_account_url get edit_account_path assert_response :success assert_template :edit - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > div.form-group > input#user_new_email[value=?]", user.new_email + assert_select ".alert-success", /^User information updated successfully/ + assert_select "form#accountForm > div > input#user_new_email[value=?]", user.new_email email = ActionMailer::Base.deliveries.first assert_equal 1, email.to.count assert_equal user.new_email, email.to.first @@ -135,7 +130,6 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest # Make sure that you are redirected to the login page when # you are not logged in get edit_account_path - assert_response :redirect assert_redirected_to login_path(:referer => "/account/edit") # Make sure we get the page when we are logged in as the right user @@ -152,4 +146,23 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest # Make sure we have a button to "go public" assert_select "form.button_to[action='/user/go_public']", true end + + def test_destroy_allowed + user = create(:user) + session_for(user) + + delete account_path + assert_response :redirect + end + + def test_destroy_not_allowed + with_user_account_deletion_delay(24) do + user = create(:user) + create(:changeset, :user => user, :created_at => Time.now.utc) + session_for(user) + + delete account_path + assert_response :bad_request + end + end end