mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
reload to clear cached value. Fixes mongoid.
This commit is contained in:
parent
d5b0fe0526
commit
00f01402e0
@ -32,4 +32,10 @@ module Mongoid::Document
|
||||
include ValidatesTimeliness::HelperMethods
|
||||
include ValidatesTimeliness::AttributeMethods
|
||||
include ValidatesTimeliness::ORM::Mongoid
|
||||
|
||||
def reload_with_timeliness
|
||||
@attributes_cache = {}
|
||||
reload_without_timeliness
|
||||
end
|
||||
alias_method_chain :reload, :timeliness
|
||||
end
|
||||
|
||||
@ -58,6 +58,15 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
||||
end
|
||||
end
|
||||
|
||||
context "cached value" do
|
||||
it 'should be cleared on reload' do
|
||||
r = Employee.create!
|
||||
r.birth_date = '2010-01-01'
|
||||
r.reload
|
||||
r._timeliness_raw_value_for(:birth_date).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "before_type_cast method" do
|
||||
it 'should be defined on class if ORM supports it' do
|
||||
Employee.instance_methods(false).should include("birth_datetime_before_type_cast")
|
||||
|
||||
@ -70,6 +70,15 @@ describe ValidatesTimeliness, 'Mongoid' do
|
||||
end
|
||||
end
|
||||
|
||||
context "cached value" do
|
||||
it 'should be cleared on reload' do
|
||||
r = Article.create!
|
||||
r.publish_date = '2010-01-01'
|
||||
r.reload
|
||||
r._timeliness_raw_value_for(:publish_date).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "before_type_cast method" do
|
||||
it 'should not be defined if ORM does not support it' do
|
||||
Article.instance_methods(false).should_not include("birth_datetime_before_type_cast")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user