Validate AccountRole#deleted_at
This commit is contained in:
parent
3881972965
commit
3fac766bef
2 changed files with 29 additions and 0 deletions
|
@ -5,4 +5,14 @@ class AccountRole < ApplicationRecord
|
||||||
belongs_to :role
|
belongs_to :role
|
||||||
|
|
||||||
scope :active, -> { where(deleted_at: nil) }
|
scope :active, -> { where(deleted_at: nil) }
|
||||||
|
|
||||||
|
validate :deleted_at_is_not_in_future
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def deleted_at_is_not_in_future
|
||||||
|
return if deleted_at.nil?
|
||||||
|
|
||||||
|
errors.add :deleted_at unless deleted_at <= Time.zone.now + 10
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,4 +7,23 @@ RSpec.describe AccountRole do
|
||||||
it { is_expected.to belong_to :role }
|
it { is_expected.to belong_to :role }
|
||||||
|
|
||||||
pending '.active'
|
pending '.active'
|
||||||
|
|
||||||
|
describe '#deleted_at' do
|
||||||
|
def allow_value(*)
|
||||||
|
super.for :deleted_at
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to allow_value nil }
|
||||||
|
|
||||||
|
it { is_expected.to allow_value Faker::Time.backward.utc }
|
||||||
|
it { is_expected.to allow_value Time.zone.now }
|
||||||
|
it { is_expected.to allow_value 1.minute.ago }
|
||||||
|
it { is_expected.to allow_value 1.hour.ago }
|
||||||
|
it { is_expected.to allow_value 1.day.ago }
|
||||||
|
|
||||||
|
it { is_expected.not_to allow_value Faker::Time.forward.utc + 1.minute }
|
||||||
|
it { is_expected.not_to allow_value 1.minute.from_now }
|
||||||
|
it { is_expected.not_to allow_value 1.hour.from_now }
|
||||||
|
it { is_expected.not_to allow_value 1.day.from_now }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue