moved type cast conversion specs from attribute_methods to validations

This commit is contained in:
Adam Meehan 2008-07-22 10:12:53 +10:00
parent 800b187d08
commit 175b5c8d36
2 changed files with 39 additions and 27 deletions

View File

@ -7,33 +7,7 @@ describe ValidatesTimeliness::AttributeMethods do
before do
@person = Person.new
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
time_string = "2000-06-01 01:02:03"
@person.birth_date_and_time = time_string

View File

@ -10,6 +10,44 @@ describe ValidatesTimeliness::Validations do
Time.now = nil
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
before :all do
class BasicValidation < Person