mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 07:16:41 +00:00
moved type cast conversion specs from attribute_methods to validations
This commit is contained in:
@@ -8,32 +8,6 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
@person = Person.new
|
@person = Person.new
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "strict_time_type_cast" do
|
|
||||||
it "should return time object for valid time string" do
|
|
||||||
strict_time_type_cast("2000-01-01 12:13:14").should be_kind_of(Time)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return nil for time string with invalid date part" do
|
|
||||||
strict_time_type_cast("2000-02-30 12:13:14").should be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return nil for time string with invalid time part" do
|
|
||||||
strict_time_type_cast("2000-02-01 25:13:14").should be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return Time object when passed a Time object" do
|
|
||||||
strict_time_type_cast(Time.now).should be_kind_of(Time)
|
|
||||||
end
|
|
||||||
|
|
||||||
if RAILS_VER >= '2.1'
|
|
||||||
it "should convert time string into current timezone" do
|
|
||||||
Time.zone = 'Melbourne'
|
|
||||||
time = strict_time_type_cast("2000-01-01 12:13:14")
|
|
||||||
Time.zone.utc_offset.should == 10.hours
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return string value for attribute_before_type_cast when written as string" do
|
it "should return string value for attribute_before_type_cast when written as string" do
|
||||||
time_string = "2000-06-01 01:02:03"
|
time_string = "2000-06-01 01:02:03"
|
||||||
@person.birth_date_and_time = time_string
|
@person.birth_date_and_time = time_string
|
||||||
|
|||||||
@@ -10,6 +10,44 @@ describe ValidatesTimeliness::Validations do
|
|||||||
Time.now = nil
|
Time.now = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "timeliness_date_time_parse" do
|
||||||
|
it "should return time object for valid time string" do
|
||||||
|
parse_method("2000-01-01 12:13:14", :datetime).should be_kind_of(Time)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return nil for time string with invalid date part" do
|
||||||
|
parse_method("2000-02-30 12:13:14", :datetime).should be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return nil for time string with invalid time part" do
|
||||||
|
parse_method("2000-02-01 25:13:14", :datetime).should be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return Time object when passed a Time object" do
|
||||||
|
parse_method(Time.now, :datetime).should be_kind_of(Time)
|
||||||
|
end
|
||||||
|
|
||||||
|
if RAILS_VER >= '2.1'
|
||||||
|
it "should convert time string into current timezone" do
|
||||||
|
Time.zone = 'Melbourne'
|
||||||
|
time = parse_method("2000-01-01 12:13:14", :datetime)
|
||||||
|
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
|
||||||
|
|
||||||
|
def parse_method(*args)
|
||||||
|
ActiveRecord::Base.timeliness_date_time_parse(*args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "with no restrictions" do
|
describe "with no restrictions" do
|
||||||
before :all do
|
before :all do
|
||||||
class BasicValidation < Person
|
class BasicValidation < Person
|
||||||
|
|||||||
Reference in New Issue
Block a user