mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
merging attribute method refactor branch
This commit is contained in:
commit
49cd69e565
@ -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]
|
[2008-09-24]
|
||||||
- refactored attribute write method definitions
|
- refactored attribute write method definitions
|
||||||
|
|
||||||
|
|||||||
@ -71,8 +71,7 @@ module ValidatesTimeliness
|
|||||||
def write_date_time_attribute(attr_name, value)
|
def write_date_time_attribute(attr_name, value)
|
||||||
attr_name = attr_name.to_s
|
attr_name = attr_name.to_s
|
||||||
column = column_for_attribute(attr_name)
|
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)
|
new = self.class.parse_date_time(value, column.type)
|
||||||
|
|
||||||
if self.class.send(:create_time_zone_conversion_attribute?, attr_name, column)
|
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
|
@person.birth_date_and_time_changed?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should show changes for time attribute as nil to Time object" do
|
describe "dirty attributes" 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 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
|
else
|
||||||
|
|
||||||
it "should return time object from database in default timezone" do
|
it "should return time object from database in default timezone" do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user