Browse Source

Actually work

pull/448/head
baarkerlounger 3 years ago
parent
commit
ecd9740cce
  1. 2
      app/views/users/show.html.erb
  2. 9
      config/routes.rb
  3. 15
      spec/requests/users_controller_spec.rb

2
app/views/users/show.html.erb

@ -35,7 +35,7 @@
row.key { 'Password' } row.key { 'Password' }
row.value { '••••••••' } row.value { '••••••••' }
if current_user == @user if current_user == @user
row.action(visually_hidden_text: 'password', href: password_edit_account_path, html_attributes: { 'data-qa': 'change-password' }) row.action(visually_hidden_text: 'password', href: edit_password_account_path, html_attributes: { 'data-qa': 'change-password' })
else else
row.action() row.action()
end end

9
config/routes.rb

@ -22,10 +22,6 @@ Rails.application.routes.draw do
get "admin/two-factor-authentication/resend", to: "auth/two_factor_authentication#show_resend" get "admin/two-factor-authentication/resend", to: "auth/two_factor_authentication#show_resend"
end end
resource :account, only: %i[show edit], controller: "users" do
get "password/edit", to: "users#edit_password"
end
devise_for :users, { devise_for :users, {
path: :account, path: :account,
controllers: { controllers: {
@ -40,6 +36,7 @@ Rails.application.routes.draw do
devise_scope :user do devise_scope :user do
get "account/password/reset-confirmation", to: "auth/passwords#reset_confirmation" get "account/password/reset-confirmation", to: "auth/passwords#reset_confirmation"
put "account", to: "users#update"
end end
get "/health", to: ->(_) { [204, {}, [nil]] } get "/health", to: ->(_) { [204, {}, [nil]] }
@ -52,6 +49,10 @@ Rails.application.routes.draw do
get "/privacy-notice", to: "content#privacy_notice" get "/privacy-notice", to: "content#privacy_notice"
get "/data-sharing-agreement", to: "content#data_sharing_agreement" get "/data-sharing-agreement", to: "content#data_sharing_agreement"
resource :account, only: %i[show edit], controller: "users" do
get "edit/password", to: "users#edit_password"
end
resources :users resources :users
resources :organisations do resources :organisations do

15
spec/requests/users_controller_spec.rb

@ -34,7 +34,7 @@ RSpec.describe UsersController, type: :request do
describe "#password" do describe "#password" do
it "does not let you edit user passwords" do it "does not let you edit user passwords" do
get "/users/#{user.id}/password/edit", headers: headers, params: {} get "/account/edit/password", headers: headers, params: {}
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
end end
@ -63,7 +63,7 @@ RSpec.describe UsersController, type: :request do
before do before do
sign_in user sign_in user
put "/users/#{user.id}", headers: headers, params: params put "/account", headers: headers, params: params
end end
it "shows an error if passwords don't match" do it "shows an error if passwords don't match" do
@ -204,7 +204,7 @@ RSpec.describe UsersController, type: :request do
context "when the current user matches the user ID" do context "when the current user matches the user ID" do
before do before do
sign_in user sign_in user
get "/users/#{user.id}/password/edit", headers: headers, params: {} get "/account/edit/password", headers: headers, params: {}
end end
it "shows the edit password page" do it "shows the edit password page" do
@ -453,7 +453,7 @@ RSpec.describe UsersController, type: :request do
context "when the current user matches the user ID" do context "when the current user matches the user ID" do
before do before do
sign_in user sign_in user
get "/users/#{user.id}/password/edit", headers: headers, params: {} get "/account/edit/password", headers: headers, params: {}
end end
it "shows the edit password page" do it "shows the edit password page" do
@ -468,11 +468,12 @@ RSpec.describe UsersController, type: :request do
context "when the current user does not matches the user ID" do context "when the current user does not matches the user ID" do
before do before do
sign_in user sign_in user
get "/users/#{other_user.id}/password/edit", headers: headers, params: {}
end end
it "returns not found 404" do it "there is no route" do
expect(response).to have_http_status(:not_found) expect {
get "/users/#{other_user.id}/password/edit", headers: headers, params: {}
}.to raise_error(ActionController::RoutingError)
end end
end end
end end

Loading…
Cancel
Save