moved restriction value evaluation into own method with recursive calls for Symbol and Proc in case they return string

This commit is contained in:
Adam Meehan
2008-08-03 12:53:59 +10:00
parent 3347a91856
commit a666c35ccd
2 changed files with 46 additions and 10 deletions

View File

@@ -45,6 +45,38 @@ describe ValidatesTimeliness::Validations do
ActiveRecord::Base.parse_date_time(*args)
end
end
describe "timeliness_restriction_value" do
it "should return Time object when restriction is Time object" do
restriction_value(Time.now, person, :datetime).should be_kind_of(Time)
end
it "should return Time object when restriction is string" do
restriction_value("2007-01-01 12:00", person, :datetime).should be_kind_of(Time)
end
it "should return Time object when restriction is method symbol which returns Time object" do
person.stub!(:datetime_attr).and_return(Time.now)
restriction_value(:datetime_attr, person, :datetime).should be_kind_of(Time)
end
it "should return Time object when restriction is method symbol which returns string" do
person.stub!(:datetime_attr).and_return("2007-01-01 12:00")
restriction_value(:datetime_attr, person, :datetime).should be_kind_of(Time)
end
it "should return Time object when restriction is proc which returns Time object" do
restriction_value(lambda { Time.now }, person, :datetime).should be_kind_of(Time)
end
it "should return Time object when restriction is proc which returns string" do
restriction_value(lambda {"2007-01-01 12:00"}, person, :datetime).should be_kind_of(Time)
end
def restriction_value(*args)
ActiveRecord::Base.send(:timeliness_restriction_value, *args)
end
end
describe "with no restrictions" do
before :all do