From b197d537f14575a10a96fa5887895742fb274d1f Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Mon, 6 Apr 2009 13:52:07 +1000 Subject: [PATCH] fix read attribute bug for frozen record (reported by Les Nightingill) --- .../active_record/attribute_methods.rb | 2 +- spec/active_record/attribute_methods_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/validates_timeliness/active_record/attribute_methods.rb b/lib/validates_timeliness/active_record/attribute_methods.rb index 6ee1905..1f770ac 100644 --- a/lib/validates_timeliness/active_record/attribute_methods.rb +++ b/lib/validates_timeliness/active_record/attribute_methods.rb @@ -76,7 +76,7 @@ module ValidatesTimeliness time = self.class.parse_date_time(time, type) else time = read_attribute(attr_name) - @attributes[attr_name] = time && time_zone_aware ? time.in_time_zone : time + @attributes[attr_name] = (time && time_zone_aware ? time.in_time_zone : time) unless frozen? end @attributes_cache[attr_name] = time && time_zone_aware ? time.in_time_zone : time end diff --git a/spec/active_record/attribute_methods_spec.rb b/spec/active_record/attribute_methods_spec.rb index 5aba593..1a0077f 100644 --- a/spec/active_record/attribute_methods_spec.rb +++ b/spec/active_record/attribute_methods_spec.rb @@ -221,4 +221,14 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do @person.birth_date.should == tomorrow end + it "should skip storing value in attributes hash on read if record frozen" do + @person = Person.new + @person.birth_date = Date.today + @person.save! + @person.reload + @person.freeze + @person.frozen?.should be_true + lambda { @person.birth_date }.should_not raise_error + @person.birth_date.should == Date.today + end end