reload to clear cached value. Fixes mongoid.

This commit is contained in:
Adam Meehan 2010-09-23 21:34:01 +10:00
parent d5b0fe0526
commit 00f01402e0
3 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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")

View File

@ -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")