Browse Source

Check name exists (#634)

pull/635/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
2819d58a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/controllers/users_controller.rb
  2. 26
      spec/requests/users_controller_spec.rb

5
app/controllers/users_controller.rb

@ -41,13 +41,14 @@ class UsersController < ApplicationController
flash[:notice] = I18n.t("devise.passwords.updated") if user_params.key?("password")
redirect_to account_path
else
user_name = @user.name&.possessive || @user.email.possessive
case user_params[:active]
when "false"
@user.update!(confirmed_at: nil, sign_in_count: 0)
flash[:notice] = I18n.t("devise.activation.deactivated", user_name: @user.name.possessive)
flash[:notice] = I18n.t("devise.activation.deactivated", user_name:)
when "true"
@user.send_confirmation_instructions
flash[:notice] = I18n.t("devise.activation.reactivated", user_name: @user.name.possessive)
flash[:notice] = I18n.t("devise.activation.reactivated", user_name:)
end
redirect_to user_path(@user)
end

26
spec/requests/users_controller_spec.rb

@ -792,6 +792,19 @@ RSpec.describe UsersController, type: :request do
expect { patch "/users/#{other_user.id}", headers:, params: }
.to change { other_user.reload.active }.from(true).to(false)
end
context "when the user name is missing" do
let(:other_user) { FactoryBot.create(:user, name: nil, organisation: user.organisation) }
before do
patch "/users/#{other_user.id}", headers:, params:
end
it "uses the user's email" do
follow_redirect!
expect(page).to have_content(other_user.email)
end
end
end
context "and tries to activate deactivated user" do
@ -805,6 +818,19 @@ RSpec.describe UsersController, type: :request do
expect { patch "/users/#{other_user.id}", headers:, params: }
.to change { other_user.reload.active }.from(false).to(true)
end
context "when the user name is missing" do
let(:other_user) { FactoryBot.create(:user, name: nil, organisation: user.organisation) }
before do
patch "/users/#{other_user.id}", headers:, params:
end
it "uses the user's email" do
follow_redirect!
expect(page).to have_content(other_user.email)
end
end
end
end
end

Loading…
Cancel
Save