Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readded email uniqueness validation #1796

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class User < ApplicationRecord
validates :email,
presence: { message: "Enter an email address" },
uniqueness: { message: "Email address must be unique" },
notify_email: true,
on: :npq_separation
notify_email: true
# rubocop:enable Rails/UniqueValidationWithoutIndex

validates :uid, uniqueness: { allow_blank: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@
})
end

context "when the new email is already in use" do
before do
create(:user, email: new_email)
end

it "marks the webhook_message as failed" do
expect {
described_class.call(webhook_message:)
}.to change {
webhook_message.reload.slice(:status, :status_comment)
}.from(
"status" => "pending",
"status_comment" => nil,
).to({
"status" => "failed",
"status_comment" => "Email Email address must be unique",
})
end
end

context "when the trn is not present" do
let(:new_trn) { nil }
let(:new_trn_status) { "not_found" }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
describe "validations" do
it { is_expected.to validate_presence_of(:full_name).with_message("Enter a full name") }
it { is_expected.to validate_presence_of(:email).on(:npq_separation).with_message("Enter an email address") }
it { is_expected.to validate_uniqueness_of(:email).on(:npq_separation).case_insensitive.with_message("Email address must be unique") }
it { is_expected.to validate_uniqueness_of(:email).case_insensitive.with_message("Email address must be unique") }
it { is_expected.not_to allow_value("invalid-email").for(:email).on(:npq_separation) }
it { is_expected.to validate_uniqueness_of(:uid).allow_blank }

Expand Down
Loading