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