merging attribute method refactor branch

This commit is contained in:
Adam Meehan 2008-10-28 19:59:31 +11:00
commit 49cd69e565
3 changed files with 42 additions and 8 deletions

View File

@ -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-09-24]
- refactored attribute write method definitions

View File

@ -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)

View File

@ -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
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