mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 23:06:42 +00:00
some docs tweaks and spec value changes
This commit is contained in:
parent
727f3dc8e3
commit
28b44b4ca6
@ -16,8 +16,8 @@ module ValidatesTimeliness
|
|||||||
# for any subsequent differentiation.
|
# for any subsequent differentiation.
|
||||||
#
|
#
|
||||||
# The wholesale replacement of the Rails time type casting is not done to
|
# 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
|
# preserve the quickest conversion for timestamp columns and also any value
|
||||||
# is never changed during the life of the record object.
|
# which is never changed during the life of the record object.
|
||||||
#
|
#
|
||||||
# Dates are also handled but only write to cache value converted by plugin
|
# Dates are also handled but only write to cache value converted by plugin
|
||||||
# parser. Default read method will retrieve from cache or do default
|
# 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
|
# 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
|
# 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)
|
def read_attribute(attr_name)
|
||||||
attr_name = attr_name.to_s
|
attr_name = attr_name.to_s
|
||||||
if !(value = @attributes[attr_name]).nil?
|
if !(value = @attributes[attr_name]).nil?
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|||||||
describe ValidatesTimeliness::Validations do
|
describe ValidatesTimeliness::Validations do
|
||||||
before :all do
|
before :all do
|
||||||
# freezes time using time_travel plugin
|
# 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
|
end
|
||||||
|
|
||||||
after :all do
|
after :all do
|
||||||
@ -35,10 +35,6 @@ describe ValidatesTimeliness::Validations do
|
|||||||
end
|
end
|
||||||
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
|
it "should return nil for invalid date string" do
|
||||||
parse_method("2000-02-30", :date).should be_nil
|
parse_method("2000-02-30", :date).should be_nil
|
||||||
end
|
end
|
||||||
@ -62,19 +58,19 @@ describe ValidatesTimeliness::Validations do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should have error for invalid date component for datetime column" do
|
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.should_not be_valid
|
||||||
@person.errors.on(:birth_date_and_time).should == "is not a valid datetime"
|
@person.errors.on(:birth_date_and_time).should == "is not a valid datetime"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have error for invalid time component for datetime column" do
|
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.should_not be_valid
|
||||||
@person.errors.on(:birth_date_and_time).should == "is not a valid datetime"
|
@person.errors.on(:birth_date_and_time).should == "is not a valid datetime"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have error for invalid date value for date column" do
|
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.should_not be_valid
|
||||||
@person.errors.on(:birth_date).should == "is not a valid date"
|
@person.errors.on(:birth_date).should == "is not a valid date"
|
||||||
end
|
end
|
||||||
@ -86,8 +82,8 @@ describe ValidatesTimeliness::Validations do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should be valid with valid values" do
|
it "should be valid with valid values" do
|
||||||
@person.birth_date_and_time = "1980-01-31 12:12:12"
|
@person.birth_date_and_time = "2000-01-31 12:12:12"
|
||||||
@person.birth_date = "1980-01-31"
|
@person.birth_date = "2000-01-31"
|
||||||
@person.should be_valid
|
@person.should be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -337,12 +333,13 @@ describe ValidatesTimeliness::Validations do
|
|||||||
|
|
||||||
describe "with mixed value and restriction types" do
|
describe "with mixed value and restriction types" do
|
||||||
before :all do
|
before :all do
|
||||||
|
|
||||||
class MixedBeforeAndAfter < Person
|
class MixedBeforeAndAfter < Person
|
||||||
validates_timeliness_of :birth_date_and_time,
|
validates_timeliness_of :birth_date_and_time,
|
||||||
:before => Date.new(2008,1,2),
|
: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,
|
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
|
:on_or_after => :birth_date_and_time
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -379,7 +376,7 @@ describe ValidatesTimeliness::Validations do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "ignoring rstriction errors" do
|
describe "ignoring restriction errors" do
|
||||||
before :all do
|
before :all do
|
||||||
class BadRestriction < Person
|
class BadRestriction < Person
|
||||||
validates_date :birth_date, :before => Proc.new { raise }
|
validates_date :birth_date, :before => Proc.new { raise }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user