made restriction_value instance method as it relies on validator instance attribute type

removed old type_cast_method class method
This commit is contained in:
Adam Meehan
2008-12-05 18:45:28 +11:00
parent 0c5cc1a536
commit 6cd6cd9dc0
3 changed files with 16 additions and 25 deletions

View File

@@ -18,33 +18,34 @@ describe ValidatesTimeliness::Validator do
describe "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)
restriction_value(Time.now, :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)
restriction_value("2007-01-01 12:00", :datetime).should be_kind_of(Time)
end
it "should return Time object when restriction is method symbol which returns Time object" do
it "should return Time object when restriction is method and method returns Time object" do
person.stub!(:datetime_attr).and_return(Time.now)
restriction_value(:datetime_attr, person, :datetime).should be_kind_of(Time)
restriction_value(:datetime_attr, :datetime).should be_kind_of(Time)
end
it "should return Time object when restriction is method symbol which returns string" do
it "should return Time object when restriction is method and method 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)
restriction_value(:datetime_attr, :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)
restriction_value(lambda { Time.now }, :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)
restriction_value(lambda {"2007-01-01 12:00"}, :datetime).should be_kind_of(Time)
end
def restriction_value(*args)
ValidatesTimeliness::Validator.send(:restriction_value, *args)
def restriction_value(restriction, type)
configure_validator(:type => type)
validator.send(:restriction_value, restriction, person)
end
end