mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user