From b9f11a1f7b003768a0f53a72d4d7d6de22754b3b Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Fri, 22 Aug 2008 14:06:08 +1000 Subject: [PATCH] fixed bug with attribute cache not clearing on write for date and time columns --- CHANGELOG | 3 +++ lib/validates_timeliness/attribute_methods.rb | 2 +- spec/attribute_methods_spec.rb | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 43f6a1e..0485886 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +[2008-08-22] + - fixed bug with attribute cache not clearing on write for date and time columns + [2008-08-07] - modified matcher option value parsing to allow same value types as validation method - fixed matcher message diff --git a/lib/validates_timeliness/attribute_methods.rb b/lib/validates_timeliness/attribute_methods.rb index 96a52b4..ecd7ae2 100644 --- a/lib/validates_timeliness/attribute_methods.rb +++ b/lib/validates_timeliness/attribute_methods.rb @@ -146,7 +146,7 @@ module ValidatesTimeliness def define_write_method_for_dates_and_times(attr_name, type) method_body = <<-EOV def #{attr_name}=(value) - @attributes_cache['#{attr_name}'] ||= self.class.parse_date_time(value, :#{type}) + @attributes_cache['#{attr_name}'] = self.class.parse_date_time(value, :#{type}) @attributes['#{attr_name}'] = value end EOV diff --git a/spec/attribute_methods_spec.rb b/spec/attribute_methods_spec.rb index 91f8c48..2efc579 100644 --- a/spec/attribute_methods_spec.rb +++ b/spec/attribute_methods_spec.rb @@ -108,5 +108,15 @@ describe ValidatesTimeliness::AttributeMethods do time = @person.birth_date_and_time @person.birth_date_and_time.should == time end + + it "should return correct value after new value assigned" do + today = Date.today + tomorrow = Date.today + 1.day + @person = Person.new + @person.birth_date = today + @person.birth_date.should == today + @person.birth_date = tomorrow + @person.birth_date.should == tomorrow + end end