From 8219d7d259245103316a18316e12587b36ad9a0b Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Tue, 2 May 2017 11:12:01 -0700 Subject: [PATCH] Rename more /profile URLs to /account **Why**: More consistency --- .../concerns/two_factor_authenticatable.rb | 2 +- .../sign_up/personal_keys_controller.rb | 2 +- .../users/personal_keys_controller.rb | 2 +- .../users/reactivate_account_controller.rb | 25 +++++++++++++++++++ .../users/reactivate_profile_controller.rb | 25 ------------------- ...roller.rb => verify_account_controller.rb} | 14 +++++------ ...ile_form.rb => reactivate_account_form.rb} | 2 +- ...profile_form.rb => verify_account_form.rb} | 2 +- app/views/accounts/_password_reset.html.slim | 2 +- app/views/accounts/_pending_profile.html.slim | 2 +- .../index.html.slim | 2 +- .../index.html.slim | 2 +- config/routes.rb | 10 +++++--- .../users/personal_keys_controller_spec.rb | 2 +- ... => reactivate_account_controller_spec.rb} | 10 ++++---- ...c.rb => verify_account_controller_spec.rb} | 10 ++++---- ...assword_recovery_via_recovery_code_spec.rb | 8 +++--- spec/features/users/verify_profile_spec.rb | 4 +-- ...pec.rb => reactivate_account_form_spec.rb} | 6 ++--- ...rm_spec.rb => verify_account_form_spec.rb} | 4 +-- spec/requests/redirects_spec.rb | 16 ++++++++++++ spec/views/accounts/show.html.slim_spec.rb | 4 +-- 22 files changed, 87 insertions(+), 69 deletions(-) create mode 100644 app/controllers/users/reactivate_account_controller.rb delete mode 100644 app/controllers/users/reactivate_profile_controller.rb rename app/controllers/users/{verify_profile_controller.rb => verify_account_controller.rb} (66%) rename app/forms/{reactivate_profile_form.rb => reactivate_account_form.rb} (98%) rename app/forms/{verify_profile_form.rb => verify_account_form.rb} (97%) rename app/views/users/{reactivate_profile => reactivate_account}/index.html.slim (85%) rename app/views/users/{verify_profile => verify_account}/index.html.slim (84%) rename spec/controllers/users/{reactivate_profile_controller_spec.rb => reactivate_account_controller_spec.rb} (69%) rename spec/controllers/users/{verify_profile_controller_spec.rb => verify_account_controller_spec.rb} (68%) rename spec/forms/{reactivate_profile_form_spec.rb => reactivate_account_form_spec.rb} (96%) rename spec/forms/{verify_profile_form_spec.rb => verify_account_form_spec.rb} (95%) diff --git a/app/controllers/concerns/two_factor_authenticatable.rb b/app/controllers/concerns/two_factor_authenticatable.rb index 19c8c354815..ff2e74021f4 100644 --- a/app/controllers/concerns/two_factor_authenticatable.rb +++ b/app/controllers/concerns/two_factor_authenticatable.rb @@ -197,7 +197,7 @@ def after_otp_action_path elsif @updating_existing_number account_path elsif decorated_user.password_reset_profile.present? - reactivate_profile_path + reactivate_account_path else account_path end diff --git a/app/controllers/sign_up/personal_keys_controller.rb b/app/controllers/sign_up/personal_keys_controller.rb index e932c29e472..f9a90e50eb8 100644 --- a/app/controllers/sign_up/personal_keys_controller.rb +++ b/app/controllers/sign_up/personal_keys_controller.rb @@ -34,7 +34,7 @@ def next_step if session[:sp] sign_up_completed_path elsif current_user.decorate.password_reset_profile.present? - reactivate_profile_path + reactivate_account_path else after_sign_in_path_for(current_user) end diff --git a/app/controllers/users/personal_keys_controller.rb b/app/controllers/users/personal_keys_controller.rb index 7a05ed874a6..0316b74c412 100644 --- a/app/controllers/users/personal_keys_controller.rb +++ b/app/controllers/users/personal_keys_controller.rb @@ -19,7 +19,7 @@ def update def next_step if current_user.decorate.password_reset_profile.present? - reactivate_profile_url + reactivate_account_url else account_url end diff --git a/app/controllers/users/reactivate_account_controller.rb b/app/controllers/users/reactivate_account_controller.rb new file mode 100644 index 00000000000..b7b4d9d492e --- /dev/null +++ b/app/controllers/users/reactivate_account_controller.rb @@ -0,0 +1,25 @@ +module Users + class ReactivateAccountController < ApplicationController + def index + @reactivate_account_form = ReactivateAccountForm.new(current_user) + end + + def create + @reactivate_account_form = build_reactivate_account_form + if @reactivate_account_form.submit(flash) + redirect_to account_path + else + render :index + end + end + + protected + + def build_reactivate_account_form + ReactivateAccountForm.new( + current_user, + params[:reactivate_account_form].permit(:password, :personal_key) + ) + end + end +end diff --git a/app/controllers/users/reactivate_profile_controller.rb b/app/controllers/users/reactivate_profile_controller.rb deleted file mode 100644 index b4239e84d01..00000000000 --- a/app/controllers/users/reactivate_profile_controller.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Users - class ReactivateProfileController < ApplicationController - def index - @reactivate_profile_form = ReactivateProfileForm.new(current_user) - end - - def create - @reactivate_profile_form = build_reactivate_profile_form - if @reactivate_profile_form.submit(flash) - redirect_to account_path - else - render :index - end - end - - protected - - def build_reactivate_profile_form - ReactivateProfileForm.new( - current_user, - params[:reactivate_profile_form].permit(:password, :personal_key) - ) - end - end -end diff --git a/app/controllers/users/verify_profile_controller.rb b/app/controllers/users/verify_account_controller.rb similarity index 66% rename from app/controllers/users/verify_profile_controller.rb rename to app/controllers/users/verify_account_controller.rb index d9e7ec7bfab..9b03b6f0157 100644 --- a/app/controllers/users/verify_profile_controller.rb +++ b/app/controllers/users/verify_account_controller.rb @@ -1,14 +1,14 @@ module Users - class VerifyProfileController < ApplicationController + class VerifyAccountController < ApplicationController before_action :confirm_verification_needed def index - @verify_profile_form = VerifyProfileForm.new(user: current_user) + @verify_account_form = VerifyAccountForm.new(user: current_user) end def create - @verify_profile_form = build_verify_profile_form - if @verify_profile_form.submit + @verify_account_form = build_verify_account_form + if @verify_account_form.submit flash[:success] = t('account.index.verification.success') redirect_to account_path else @@ -18,8 +18,8 @@ def create private - def build_verify_profile_form - VerifyProfileForm.new( + def build_verify_account_form + VerifyAccountForm.new( user: current_user, otp: params_otp, pii_attributes: decrypted_pii @@ -27,7 +27,7 @@ def build_verify_profile_form end def params_otp - params[:verify_profile_form].permit(:otp)[:otp] + params[:verify_account_form].permit(:otp)[:otp] end def confirm_verification_needed diff --git a/app/forms/reactivate_profile_form.rb b/app/forms/reactivate_account_form.rb similarity index 98% rename from app/forms/reactivate_profile_form.rb rename to app/forms/reactivate_account_form.rb index 31e301408c8..dbf8cd42c61 100644 --- a/app/forms/reactivate_profile_form.rb +++ b/app/forms/reactivate_account_form.rb @@ -1,4 +1,4 @@ -class ReactivateProfileForm +class ReactivateAccountForm include ActiveModel::Model include PersonalKeyValidator diff --git a/app/forms/verify_profile_form.rb b/app/forms/verify_account_form.rb similarity index 97% rename from app/forms/verify_profile_form.rb rename to app/forms/verify_account_form.rb index 6882bdaa2b0..ceacfdb1562 100644 --- a/app/forms/verify_profile_form.rb +++ b/app/forms/verify_account_form.rb @@ -1,4 +1,4 @@ -class VerifyProfileForm +class VerifyAccountForm include ActiveModel::Model validates :otp, presence: true diff --git a/app/views/accounts/_password_reset.html.slim b/app/views/accounts/_password_reset.html.slim index b9667265108..7e5599ab7b7 100644 --- a/app/views/accounts/_password_reset.html.slim +++ b/app/views/accounts/_password_reset.html.slim @@ -1,3 +1,3 @@ .mb4.alert.alert-warning p = t('account.index.reactivation.instructions') - p.mb0 = link_to t('account.index.reactivation.reactivate_button'), reactivate_profile_path + p.mb0 = link_to t('account.index.reactivation.reactivate_button'), reactivate_account_path diff --git a/app/views/accounts/_pending_profile.html.slim b/app/views/accounts/_pending_profile.html.slim index 3c1cda7f968..6f34823400f 100644 --- a/app/views/accounts/_pending_profile.html.slim +++ b/app/views/accounts/_pending_profile.html.slim @@ -1,3 +1,3 @@ .mb4.alert.alert-warning p = t('account.index.verification.instructions') - p.mb0 = link_to t('account.index.verification.reactivate_button'), verify_profile_path + p.mb0 = link_to t('account.index.verification.reactivate_button'), verify_account_path diff --git a/app/views/users/reactivate_profile/index.html.slim b/app/views/users/reactivate_account/index.html.slim similarity index 85% rename from app/views/users/reactivate_profile/index.html.slim rename to app/views/users/reactivate_account/index.html.slim index d95fe4b0767..2cb5ec95c94 100644 --- a/app/views/users/reactivate_profile/index.html.slim +++ b/app/views/users/reactivate_account/index.html.slim @@ -2,7 +2,7 @@ h1.h3.my0 = t('forms.reactivate_profile.title') p.mt-tiny.mb0 = t('forms.reactivate_profile.instructions') -= simple_form_for(@reactivate_profile_form, url: reactivate_profile_path, += simple_form_for(@reactivate_account_form, url: reactivate_account_path, html: { autocomplete: 'off', method: :post, role: 'form' }) do |f| = f.error :base = render 'partials/personal_key/entry_fields', f: f, attribute_name: :personal_key diff --git a/app/views/users/verify_profile/index.html.slim b/app/views/users/verify_account/index.html.slim similarity index 84% rename from app/views/users/verify_profile/index.html.slim rename to app/views/users/verify_account/index.html.slim index 16dbbf8044c..75204f1b40a 100644 --- a/app/views/users/verify_profile/index.html.slim +++ b/app/views/users/verify_account/index.html.slim @@ -2,7 +2,7 @@ h1.h3.my0 = t('forms.verify_profile.title') p.mt-tiny.mb0 = t('forms.verify_profile.instructions') -= simple_form_for(@verify_profile_form, url: verify_profile_path, += simple_form_for(@verify_account_form, url: verify_account_path, html: { autocomplete: 'off', method: :post, role: 'form' }) do |f| = f.error :base = f.input :otp, required: true, label: 'Secret code' diff --git a/config/routes.rb b/config/routes.rb index 2637acde969..9b25f174201 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,6 +45,10 @@ as: :openid_connect_configuration get '/account' => 'accounts#show' + get '/account/reactivate' => 'users/reactivate_account#index', as: :reactivate_account + post '/account/reactivate' => 'users/reactivate_account#create' + get '/account/verify' => 'users/verify_account#index', as: :verify_account + post '/account/verify' => 'users/verify_account#create' get '/api/health/workers' => 'health/workers#index' get '/api/openid_connect/certs' => 'openid_connect/certs#index' @@ -88,10 +92,8 @@ as: :user_two_factor_authentication # route name is used by two_factor_authentication gem get '/profile', to: redirect('/account') - get '/profile/reactivate' => 'users/reactivate_profile#index', as: :reactivate_profile - post '/profile/reactivate' => 'users/reactivate_profile#create' - get '/profile/verify' => 'users/verify_profile#index', as: :verify_profile - post '/profile/verify' => 'users/verify_profile#create' + get '/profile/reactivate', to: redirect('/account/reactivate') + get '/profile/verify', to: redirect('/account/verify') post '/sign_up/create_password' => 'sign_up/passwords#create', as: :sign_up_create_password get '/sign_up/email/confirm' => 'sign_up/email_confirmations#create', diff --git a/spec/controllers/users/personal_keys_controller_spec.rb b/spec/controllers/users/personal_keys_controller_spec.rb index 28c492f2b79..909b55297d5 100644 --- a/spec/controllers/users/personal_keys_controller_spec.rb +++ b/spec/controllers/users/personal_keys_controller_spec.rb @@ -64,7 +64,7 @@ patch :update - expect(response).to redirect_to reactivate_profile_url + expect(response).to redirect_to reactivate_account_url end end end diff --git a/spec/controllers/users/reactivate_profile_controller_spec.rb b/spec/controllers/users/reactivate_account_controller_spec.rb similarity index 69% rename from spec/controllers/users/reactivate_profile_controller_spec.rb rename to spec/controllers/users/reactivate_account_controller_spec.rb index 1028ebb36b3..38337b04a9c 100644 --- a/spec/controllers/users/reactivate_profile_controller_spec.rb +++ b/spec/controllers/users/reactivate_account_controller_spec.rb @@ -1,13 +1,13 @@ require 'rails_helper' -RSpec.describe Users::ReactivateProfileController do +RSpec.describe Users::ReactivateAccountController do include Features::LocalizationHelper describe '#create' do subject(:action) do post( :create, - reactivate_profile_form: { + reactivate_account_form: { password: 'password', personal_key: 'personal_key', } @@ -17,8 +17,8 @@ before do stub_sign_in - form = instance_double('ReactivateProfileForm', submit: success) - expect(controller).to receive(:build_reactivate_profile_form).and_return(form) + form = instance_double('ReactivateAccountForm', submit: success) + expect(controller).to receive(:build_reactivate_account_form).and_return(form) end context 'with a valid form' do @@ -37,7 +37,7 @@ it 'renders the index page to show errors' do action - expect(response).to render_template('users/reactivate_profile/index') + expect(response).to render_template('users/reactivate_account/index') end end end diff --git a/spec/controllers/users/verify_profile_controller_spec.rb b/spec/controllers/users/verify_account_controller_spec.rb similarity index 68% rename from spec/controllers/users/verify_profile_controller_spec.rb rename to spec/controllers/users/verify_account_controller_spec.rb index db5843382dd..05fe1c0ae36 100644 --- a/spec/controllers/users/verify_profile_controller_spec.rb +++ b/spec/controllers/users/verify_account_controller_spec.rb @@ -1,13 +1,13 @@ require 'rails_helper' -RSpec.describe Users::VerifyProfileController do +RSpec.describe Users::VerifyAccountController do include Features::LocalizationHelper describe '#create' do subject(:action) do post( :create, - verify_profile_form: { + verify_account_form: { otp: 'abc123', } ) @@ -16,8 +16,8 @@ before do stub_sign_in - form = instance_double('VerifyProfileForm', submit: success) - expect(controller).to receive(:build_verify_profile_form).and_return(form) + form = instance_double('VerifyAccountForm', submit: success) + expect(controller).to receive(:build_verify_account_form).and_return(form) end context 'with a valid form' do @@ -36,7 +36,7 @@ it 'renders the index page to show errors' do action - expect(response).to render_template('users/verify_profile/index') + expect(response).to render_template('users/verify_account/index') end end end diff --git a/spec/features/users/password_recovery_via_recovery_code_spec.rb b/spec/features/users/password_recovery_via_recovery_code_spec.rb index eeaece47a3f..c4113a93c68 100644 --- a/spec/features/users/password_recovery_via_recovery_code_spec.rb +++ b/spec/features/users/password_recovery_via_recovery_code_spec.rb @@ -16,7 +16,7 @@ click_submit_default enter_correct_otp_code_for_user(user) - expect(current_path).to eq reactivate_profile_path + expect(current_path).to eq reactivate_account_path reactivate_profile(new_password, personal_key) @@ -32,14 +32,14 @@ click_submit_default enter_correct_otp_code_for_user(user) - expect(current_path).to eq reactivate_profile_path + expect(current_path).to eq reactivate_account_path visit manage_personal_key_path new_personal_key = scrape_personal_key click_acknowledge_personal_key - expect(current_path).to eq reactivate_profile_path + expect(current_path).to eq reactivate_account_path reactivate_profile(new_password, new_personal_key) @@ -65,7 +65,7 @@ new_personal_key = scrape_personal_key click_acknowledge_personal_key - expect(current_path).to eq reactivate_profile_path + expect(current_path).to eq reactivate_account_path reactivate_profile(new_password, new_personal_key) diff --git a/spec/features/users/verify_profile_spec.rb b/spec/features/users/verify_profile_spec.rb index b47cc7c4eab..afecc0e6b66 100644 --- a/spec/features/users/verify_profile_spec.rb +++ b/spec/features/users/verify_profile_spec.rb @@ -20,7 +20,7 @@ click_on t('account.index.verification.reactivate_button') - expect(current_path).to eq verify_profile_path + expect(current_path).to eq verify_account_path fill_in 'Secret code', with: otp click_button t('forms.verify_profile.submit') @@ -41,7 +41,7 @@ fill_in 'Secret code', with: 'the wrong code' click_button t('forms.verify_profile.submit') - expect(current_path).to eq verify_profile_path + expect(current_path).to eq verify_account_path expect(page).to have_content(t('errors.messages.otp_incorrect')) expect(page.body).to_not match('the wrong code') end diff --git a/spec/forms/reactivate_profile_form_spec.rb b/spec/forms/reactivate_account_form_spec.rb similarity index 96% rename from spec/forms/reactivate_profile_form_spec.rb rename to spec/forms/reactivate_account_form_spec.rb index 4e05651244a..2745f9b1c28 100644 --- a/spec/forms/reactivate_profile_form_spec.rb +++ b/spec/forms/reactivate_account_form_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' -describe ReactivateProfileForm do +describe ReactivateAccountForm do subject(:form) do - ReactivateProfileForm.new(user, + ReactivateAccountForm.new(user, password: password) end @@ -45,7 +45,7 @@ context 'when personal key does not match' do subject(:form) do - ReactivateProfileForm.new(user, + ReactivateAccountForm.new(user, personal_key: personal_key, password: password) end diff --git a/spec/forms/verify_profile_form_spec.rb b/spec/forms/verify_account_form_spec.rb similarity index 95% rename from spec/forms/verify_profile_form_spec.rb rename to spec/forms/verify_account_form_spec.rb index 65bd7c4d50f..6149207a127 100644 --- a/spec/forms/verify_profile_form_spec.rb +++ b/spec/forms/verify_account_form_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' -describe VerifyProfileForm do +describe VerifyAccountForm do subject(:form) do - VerifyProfileForm.new(user: user, otp: otp, pii_attributes: pii_attributes) + VerifyAccountForm.new(user: user, otp: otp, pii_attributes: pii_attributes) end let(:user) { pending_profile.user } diff --git a/spec/requests/redirects_spec.rb b/spec/requests/redirects_spec.rb index 41d75f95acf..7f0c11a47d0 100644 --- a/spec/requests/redirects_spec.rb +++ b/spec/requests/redirects_spec.rb @@ -8,4 +8,20 @@ expect(response).to redirect_to('/account') end end + + describe '/profile/reactivate' do + it 'redirects to /account/reactivate' do + get '/profile/reactivate' + + expect(response).to redirect_to('/account/reactivate') + end + end + + describe '/profile/verify' do + it 'redirects to /account/verify' do + get '/profile/verify' + + expect(response).to redirect_to('/account/verify') + end + end end diff --git a/spec/views/accounts/show.html.slim_spec.rb b/spec/views/accounts/show.html.slim_spec.rb index 36bd5e12d77..93a82073916 100644 --- a/spec/views/accounts/show.html.slim_spec.rb +++ b/spec/views/accounts/show.html.slim_spec.rb @@ -93,7 +93,7 @@ render expect(rendered).to_not have_link( - t('account.index.verification.reactivate_button'), href: verify_profile_path + t('account.index.verification.reactivate_button'), href: verify_account_path ) end end @@ -107,7 +107,7 @@ render expect(rendered). - to have_link(t('account.index.verification.reactivate_button'), href: verify_profile_path) + to have_link(t('account.index.verification.reactivate_button'), href: verify_account_path) end end