parent
c5fef621e4
commit
8dc966feb4
4 changed files with 46 additions and 0 deletions
|
@ -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) }
|
||||
|
|
9
config/locales/models/dossier_transfer/en.yml
Normal file
9
config/locales/models/dossier_transfer/en.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
en:
|
||||
activerecord:
|
||||
errors:
|
||||
models:
|
||||
dossier_transfer:
|
||||
attributes:
|
||||
email:
|
||||
format: "Email address %{message}"
|
||||
invalid: "is invalid"
|
9
config/locales/models/dossier_transfer/fr.yml
Normal file
9
config/locales/models/dossier_transfer/fr.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
fr:
|
||||
activerecord:
|
||||
errors:
|
||||
models:
|
||||
dossier_transfer:
|
||||
attributes:
|
||||
email:
|
||||
format: "L'adresse email %{message}"
|
||||
invalid: "est invalide"
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue