fix(dossier_transfer): requires an actual email

Closes #7621
This commit is contained in:
Colin Darie 2022-08-02 12:37:29 +02:00
parent c5fef621e4
commit 8dc966feb4
4 changed files with 46 additions and 0 deletions

View file

@ -12,6 +12,8 @@ class DossierTransfer < ApplicationRecord
EXPIRATION_LIMIT = 2.weeks
validates :email, format: { with: Devise.email_regexp }
scope :pending, -> { where('created_at > ?', (Time.zone.now - EXPIRATION_LIMIT)) }
scope :stale, -> { where('created_at < ?', (Time.zone.now - EXPIRATION_LIMIT)) }
scope :with_dossiers, -> { joins(:dossiers).merge(Dossier.visible_by_user) }

View file

@ -0,0 +1,9 @@
en:
activerecord:
errors:
models:
dossier_transfer:
attributes:
email:
format: "Email address %{message}"
invalid: "is invalid"

View file

@ -0,0 +1,9 @@
fr:
activerecord:
errors:
models:
dossier_transfer:
attributes:
email:
format: "L'adresse email %{message}"
invalid: "est invalide"

View file

@ -78,4 +78,30 @@ RSpec.describe DossierTransfer, type: :model do
expect(DossierTransfer.count).to eq(0)
end
end
describe "validation" do
let(:email) { build(:dossier_transfer).email }
subject { build(:dossier_transfer, email: email) }
it "factory is valid" do
expect(subject).to be_valid
end
context "when email is blank" do
let(:email) { "" }
it "requires a valid email" do
expect(subject).to be_invalid
end
end
context "when email is not an email" do
let(:email) { "test" }
it "requires a valid email" do
expect(subject).to be_invalid
end
end
end
end