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") flash[:notice] = I18n.t("devise.passwords.updated") if user_params.key?("password")
redirect_to account_path redirect_to account_path
else else
user_name = @user.name&.possessive || @user.email.possessive
case user_params[:active] case user_params[:active]
when "false" when "false"
@user.update!(confirmed_at: nil, sign_in_count: 0) @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" when "true"
@user.send_confirmation_instructions @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 end
redirect_to user_path(@user) redirect_to user_path(@user)
end 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: } expect { patch "/users/#{other_user.id}", headers:, params: }
.to change { other_user.reload.active }.from(true).to(false) .to change { other_user.reload.active }.from(true).to(false)
end 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
context "and tries to activate deactivated user" do 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: } expect { patch "/users/#{other_user.id}", headers:, params: }
.to change { other_user.reload.active }.from(false).to(true) .to change { other_user.reload.active }.from(false).to(true)
end 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 end
end end

Loading…
Cancel
Save