some docs tweaks and spec value changes

This commit is contained in:
Adam Meehan 2008-07-22 11:47:17 +10:00
parent 727f3dc8e3
commit 28b44b4ca6
2 changed files with 15 additions and 17 deletions

View File

@ -16,8 +16,8 @@ module ValidatesTimeliness
# for any subsequent differentiation.
#
# The wholesale replacement of the Rails time type casting is not done to
# preserve the quick conversion for timestamp columns and also any value which
# is never changed during the life of the record object.
# preserve the quickest conversion for timestamp columns and also any value
# which is never changed during the life of the record object.
#
# Dates are also handled but only write to cache value converted by plugin
# parser. Default read method will retrieve from cache or do default
@ -35,7 +35,8 @@ module ValidatesTimeliness
# Adds check for cached time attributes which have been type cast already
# and value can be used from cache. This prevents the raw time value
# from being type cast using default Rails type casting.
# from being type cast using default Rails type casting when writing values
# to the database.
def read_attribute(attr_name)
attr_name = attr_name.to_s
if !(value = @attributes[attr_name]).nil?

View File

@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
describe ValidatesTimeliness::Validations do
before :all do
# freezes time using time_travel plugin
Time.now = Time.utc(2008, 1, 1, 12, 0, 0)
Time.now = Time.utc(2000, 1, 1, 0, 0, 0)
end
after :all do
@ -34,11 +34,7 @@ describe ValidatesTimeliness::Validations do
Time.zone.utc_offset.should == 10.hours
end
end
it "should return Date object valid date string" do
parse_method("2000-02-01", :date).should be_kind_of(Date)
end
it "should return nil for invalid date string" do
parse_method("2000-02-30", :date).should be_nil
end
@ -62,19 +58,19 @@ describe ValidatesTimeliness::Validations do
end
it "should have error for invalid date component for datetime column" do
@person.birth_date_and_time = "1980-02-30 01:02:03"
@person.birth_date_and_time = "2000-02-30 01:02:03"
@person.should_not be_valid
@person.errors.on(:birth_date_and_time).should == "is not a valid datetime"
end
it "should have error for invalid time component for datetime column" do
@person.birth_date_and_time = "1980-02-30 25:02:03"
@person.birth_date_and_time = "2000-02-30 25:02:03"
@person.should_not be_valid
@person.errors.on(:birth_date_and_time).should == "is not a valid datetime"
end
it "should have error for invalid date value for date column" do
@person.birth_date = "1980-02-30"
@person.birth_date = "2000-02-30"
@person.should_not be_valid
@person.errors.on(:birth_date).should == "is not a valid date"
end
@ -86,8 +82,8 @@ describe ValidatesTimeliness::Validations do
end
it "should be valid with valid values" do
@person.birth_date_and_time = "1980-01-31 12:12:12"
@person.birth_date = "1980-01-31"
@person.birth_date_and_time = "2000-01-31 12:12:12"
@person.birth_date = "2000-01-31"
@person.should be_valid
end
@ -337,12 +333,13 @@ describe ValidatesTimeliness::Validations do
describe "with mixed value and restriction types" do
before :all do
class MixedBeforeAndAfter < Person
validates_timeliness_of :birth_date_and_time,
:before => Date.new(2008,1,2),
:after => lambda { Time.mktime(2008, 1, 1) }
:after => lambda { "2008-01-01" }
validates_timeliness_of :birth_date, :type => :date,
:on_or_before => lambda { Time.mktime(2008, 1, 2) },
:on_or_before => lambda { "2008-01-01" },
:on_or_after => :birth_date_and_time
end
end
@ -379,7 +376,7 @@ describe ValidatesTimeliness::Validations do
end
describe "ignoring rstriction errors" do
describe "ignoring restriction errors" do
before :all do
class BadRestriction < Person
validates_date :birth_date, :before => Proc.new { raise }