added option key validation to prevent silly validation problems due to bad key name

This commit is contained in:
Adam Meehan
2009-02-01 20:08:07 +11:00
parent b3e235a8a1
commit a1ae5f9313
3 changed files with 30 additions and 1 deletions

View File

@@ -16,6 +16,23 @@ describe ValidatesTimeliness::Validator do
@person = Person.new
end
describe "option keys validation" do
before do
@valid_options = ValidatesTimeliness::Validator::VALID_OPTIONS.inject({}) {|hash, opt| hash[opt] = nil; hash }
@valid_options.delete(:invalid_date_message)
@valid_options.delete(:invalid_time_message)
end
it "should raise error if invalid option key passed" do
@valid_options.update(:invalid_key => 'will not open lock')
lambda { Person.validates_datetime(@valid_options) }.should raise_error(ArgumentError)
end
it "should not raise error if option keys are valid" do
lambda { Person.validates_datetime(@valid_options) }.should_not raise_error(ArgumentError)
end
end
describe "restriction_value" do
it "should return Time object when restriction is Time object" do
restriction_value(Time.now, :datetime).should be_kind_of(Time)