mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
014bb76622 | ||
|
|
3533ce0702 |
@@ -1,4 +1,3 @@
|
||||
#TODO remove deprecated option :equal_to
|
||||
module ValidatesTimeliness
|
||||
|
||||
class Validator
|
||||
@@ -8,7 +7,6 @@ module ValidatesTimeliness
|
||||
|
||||
RESTRICTION_METHODS = {
|
||||
:is_at => :==,
|
||||
:equal_to => :==,
|
||||
:before => :<,
|
||||
:after => :>,
|
||||
:on_or_before => :<=,
|
||||
@@ -60,6 +58,7 @@ module ValidatesTimeliness
|
||||
def validate_restrictions(record, attr_name, value)
|
||||
if configuration[:with_time] || configuration[:with_date]
|
||||
value = combine_date_and_time(value, record)
|
||||
return if value.nil?
|
||||
end
|
||||
|
||||
value = self.class.type_cast_value(value, implied_type, configuration[:ignore_usec])
|
||||
@@ -142,12 +141,6 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
def validate_options(options)
|
||||
if options.key?(:equal_to)
|
||||
::ActiveSupport::Deprecation.warn("ValidatesTimeliness :equal_to option is deprecated due to clash with a default Rails option. Use :is_at instead. You will need to fix any I18n error message references to this option date/time attributes now.")
|
||||
options[:is_at] = options.delete(:equal_to)
|
||||
options[:is_at_message] = options.delete(:equal_to_message)
|
||||
end
|
||||
|
||||
invalid_for_type = ([:time, :date, :datetime] - [type]).map {|k| "invalid_#{k}_message".to_sym }
|
||||
invalid_for_type << :with_date unless type == :time
|
||||
invalid_for_type << :with_time unless type == :date
|
||||
|
||||
@@ -25,10 +25,6 @@ describe ValidatesTimeliness::Validator do
|
||||
end
|
||||
|
||||
describe "option keys validation" do
|
||||
before(:all) do
|
||||
ActiveSupport::Deprecation.silenced = true
|
||||
end
|
||||
|
||||
before do
|
||||
keys = ValidatesTimeliness::Validator::VALID_OPTION_KEYS - [:invalid_date_message, :invalid_time_message, :with_date, :with_time]
|
||||
@valid_options = keys.inject({}) {|hash, opt| hash[opt] = nil; hash }
|
||||
@@ -42,15 +38,6 @@ describe ValidatesTimeliness::Validator do
|
||||
it "should not raise error if option keys are valid" do
|
||||
lambda { Person.validates_datetime(@valid_options) }.should_not raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "should display deprecation notice for :equal_to" do
|
||||
::ActiveSupport::Deprecation.should_receive(:warn)
|
||||
Person.validates_datetime :equal_to => Time.now
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
ActiveSupport::Deprecation.silenced = false
|
||||
end
|
||||
end
|
||||
|
||||
describe "evaluate_option_value" do
|
||||
@@ -429,7 +416,6 @@ describe ValidatesTimeliness::Validator do
|
||||
end
|
||||
|
||||
describe "instance with :with_time option" do
|
||||
|
||||
it "should validate date attribute as datetime combining value of :with_time against restrictions " do
|
||||
configure_validator(:type => :date, :with_time => '12:31', :on_or_before => Time.mktime(2000,1,1,12,30))
|
||||
validate_with(:birth_date, "2000-01-01")
|
||||
@@ -442,6 +428,12 @@ describe ValidatesTimeliness::Validator do
|
||||
should_have_no_error(:birth_date, :on_or_before)
|
||||
end
|
||||
|
||||
it "should skip restriction validation if :with_time value evaluates to nil" do
|
||||
configure_validator(:type => :date, :with_time => lambda { nil }, :on_or_before => Time.mktime(2000,1,1,12,30))
|
||||
validate_with(:birth_date, "2000-01-01")
|
||||
should_have_no_error(:birth_date, :on_or_before)
|
||||
end
|
||||
|
||||
it "should should ignore usec value on combined value if :ignore_usec option is true" do
|
||||
configure_validator(:type => :date, :with_time => Time.mktime(2000,1,1,12,30,0,500), :is_at => Time.mktime(2000,1,1,12,30), :ignore_usec => true)
|
||||
validate_with(:birth_date, "2000-01-01")
|
||||
@@ -463,6 +455,12 @@ describe ValidatesTimeliness::Validator do
|
||||
should_have_no_error(:birth_time, :on_or_before)
|
||||
end
|
||||
|
||||
it "should skip restriction validation if :with_date value is nil" do
|
||||
configure_validator(:type => :time, :with_date => lambda { nil }, :on_or_before => Time.mktime(2000,1,1,12,30))
|
||||
validate_with(:birth_time, "12:30")
|
||||
should_have_no_error(:birth_time, :on_or_before)
|
||||
end
|
||||
|
||||
it "should should ignore usec value on combined value if :ignore_usec option is true" do
|
||||
configure_validator(:type => :time, :with_date => Date.new(2000,1,1), :on_or_before => Time.mktime(2000,1,1,12,30), :ignore_usec => true)
|
||||
validate_with(:birth_time, Time.mktime(2000,1,1,12,30,0,50))
|
||||
|
||||
Reference in New Issue
Block a user