mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
fixed dirty attributes when old value incorrectly read and added more examples for dirty attributes
This commit is contained in:
parent
8f950d5ac6
commit
ced61929da
@ -1,3 +1,6 @@
|
||||
[2008-10-28]
|
||||
- fixed bug when dirty attributes not reflecting change when attribute changed from time value to nil [reported by Brad (pvjq)]
|
||||
|
||||
[2008-08-25]
|
||||
- fixed bug for non-timezone write method not updating changed attributes hash [reported by Sylvestre Mergulhão]
|
||||
|
||||
|
||||
@ -71,8 +71,7 @@ module ValidatesTimeliness
|
||||
def write_date_time_attribute(attr_name, value)
|
||||
attr_name = attr_name.to_s
|
||||
column = column_for_attribute(attr_name)
|
||||
|
||||
old = read_attribute('#{attr_name}') if defined?(ActiveRecord::Dirty)
|
||||
old = read_attribute(attr_name) if defined?(ActiveRecord::Dirty)
|
||||
new = self.class.parse_date_time(value, column.type)
|
||||
|
||||
if self.class.send(:create_time_zone_conversion_attribute?, attr_name, column)
|
||||
|
||||
@ -92,13 +92,45 @@ describe ValidatesTimeliness::AttributeMethods do
|
||||
@person.birth_date_and_time_changed?.should be_true
|
||||
end
|
||||
|
||||
it "should show changes for time attribute as nil to Time object" do
|
||||
time_string = "2000-01-01 02:03:04"
|
||||
@person.birth_date_and_time = time_string
|
||||
time = @person.birth_date_and_time
|
||||
@person.changes.should == {"birth_date_and_time" => [nil, time]}
|
||||
end
|
||||
describe "dirty attributes" do
|
||||
|
||||
it "should show changes when time attribute changed from nil to Time object" do
|
||||
time_string = "2000-01-01 02:03:04"
|
||||
@person.birth_date_and_time = time_string
|
||||
time = @person.birth_date_and_time
|
||||
@person.changes.should == {"birth_date_and_time" => [nil, time]}
|
||||
end
|
||||
|
||||
it "should show changes when time attribute changed from Time object to nil" do
|
||||
time_string = "2020-01-01 02:03:04"
|
||||
@person.birth_date_and_time = time_string
|
||||
@person.save false
|
||||
@person.reload
|
||||
time = @person.birth_date_and_time
|
||||
@person.birth_date_and_time = nil
|
||||
@person.changes.should == {"birth_date_and_time" => [time, nil]}
|
||||
end
|
||||
|
||||
it "should show no changes when assigned same value as Time object" do
|
||||
time_string = "2020-01-01 02:03:04"
|
||||
@person.birth_date_and_time = time_string
|
||||
@person.save false
|
||||
@person.reload
|
||||
time = @person.birth_date_and_time
|
||||
@person.birth_date_and_time = time
|
||||
@person.changes.should == {}
|
||||
end
|
||||
|
||||
it "should show no changes when assigned same value as time string" do
|
||||
time_string = "2020-01-01 02:03:04"
|
||||
@person.birth_date_and_time = time_string
|
||||
@person.save false
|
||||
@person.reload
|
||||
@person.birth_date_and_time = time_string
|
||||
@person.changes.should == {}
|
||||
end
|
||||
|
||||
end
|
||||
else
|
||||
|
||||
it "should return time object from database in default timezone" do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user