mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
some docs tweaks and spec value changes
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user