diff --git a/lib/validates_timeliness/orm/mongoid.rb b/lib/validates_timeliness/orm/mongoid.rb index 18da414..f027291 100644 --- a/lib/validates_timeliness/orm/mongoid.rb +++ b/lib/validates_timeliness/orm/mongoid.rb @@ -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 diff --git a/spec/validates_timeliness/orm/active_record_spec.rb b/spec/validates_timeliness/orm/active_record_spec.rb index 9367e6a..92b5c2f 100644 --- a/spec/validates_timeliness/orm/active_record_spec.rb +++ b/spec/validates_timeliness/orm/active_record_spec.rb @@ -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") diff --git a/spec/validates_timeliness/orm/mongoid_spec.rb b/spec/validates_timeliness/orm/mongoid_spec.rb index 4f8928b..a67e699 100644 --- a/spec/validates_timeliness/orm/mongoid_spec.rb +++ b/spec/validates_timeliness/orm/mongoid_spec.rb @@ -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")