mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 14:56:43 +00:00
fix read attribute bug for frozen record (reported by Les Nightingill)
This commit is contained in:
parent
88fce1d679
commit
b197d537f1
@ -76,7 +76,7 @@ module ValidatesTimeliness
|
|||||||
time = self.class.parse_date_time(time, type)
|
time = self.class.parse_date_time(time, type)
|
||||||
else
|
else
|
||||||
time = read_attribute(attr_name)
|
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
|
end
|
||||||
@attributes_cache[attr_name] = time && time_zone_aware ? time.in_time_zone : time
|
@attributes_cache[attr_name] = time && time_zone_aware ? time.in_time_zone : time
|
||||||
end
|
end
|
||||||
|
|||||||
@ -221,4 +221,14 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
|||||||
@person.birth_date.should == tomorrow
|
@person.birth_date.should == tomorrow
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user