mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 23:06:42 +00:00
change equal_to to is_at to fix overlap with default rails message
This commit is contained in:
parent
3bfc7b748f
commit
f3c119e191
@ -317,6 +317,7 @@ For Rails 2.0/2.1:
|
|||||||
:invalid_date => "is not a valid date",
|
:invalid_date => "is not a valid date",
|
||||||
:invalid_time => "is not a valid time",
|
:invalid_time => "is not a valid time",
|
||||||
:invalid_datetime => "is not a valid datetime",
|
:invalid_datetime => "is not a valid datetime",
|
||||||
|
:is_at => "must be at %s",
|
||||||
:before => "must be before %s",
|
:before => "must be before %s",
|
||||||
:on_or_before => "must be on or before %s",
|
:on_or_before => "must be on or before %s",
|
||||||
:after => "must be after %s",
|
:after => "must be after %s",
|
||||||
@ -335,7 +336,7 @@ Rails 2.2+ using the I18n system to define new defaults:
|
|||||||
invalid_date: "is not a valid date"
|
invalid_date: "is not a valid date"
|
||||||
invalid_time: "is not a valid time"
|
invalid_time: "is not a valid time"
|
||||||
invalid_datetime: "is not a valid datetime"
|
invalid_datetime: "is not a valid datetime"
|
||||||
equal_to: "must be equal to {{restriction}}"
|
is_at: "must be at {{restriction}}"
|
||||||
before: "must be before {{restriction}}"
|
before: "must be before {{restriction}}"
|
||||||
on_or_before: "must be on or before {{restriction}}"
|
on_or_before: "must be on or before {{restriction}}"
|
||||||
after: "must be after {{restriction}}"
|
after: "must be after {{restriction}}"
|
||||||
|
|||||||
@ -5,7 +5,7 @@ en:
|
|||||||
invalid_date: "is not a valid date"
|
invalid_date: "is not a valid date"
|
||||||
invalid_time: "is not a valid time"
|
invalid_time: "is not a valid time"
|
||||||
invalid_datetime: "is not a valid datetime"
|
invalid_datetime: "is not a valid datetime"
|
||||||
equal_to: "must be equal to {{restriction}}"
|
is_at: "must be at {{restriction}}"
|
||||||
before: "must be before {{restriction}}"
|
before: "must be before {{restriction}}"
|
||||||
on_or_before: "must be on or before {{restriction}}"
|
on_or_before: "must be on or before {{restriction}}"
|
||||||
after: "must be after {{restriction}}"
|
after: "must be after {{restriction}}"
|
||||||
|
|||||||
@ -10,7 +10,7 @@ module Spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
OPTION_TEST_SETTINGS = {
|
OPTION_TEST_SETTINGS = {
|
||||||
:equal_to => { :method => :+, :modify_on => :invalid },
|
:is_at => { :method => :+, :modify_on => :invalid },
|
||||||
:before => { :method => :-, :modify_on => :valid },
|
:before => { :method => :-, :modify_on => :valid },
|
||||||
:after => { :method => :+, :modify_on => :valid },
|
:after => { :method => :+, :modify_on => :valid },
|
||||||
:on_or_before => { :method => :+, :modify_on => :invalid },
|
:on_or_before => { :method => :+, :modify_on => :invalid },
|
||||||
@ -28,7 +28,7 @@ module Spec
|
|||||||
|
|
||||||
valid = test_validity
|
valid = test_validity
|
||||||
|
|
||||||
valid = test_option(:equal_to) if valid && @options[:equal_to]
|
valid = test_option(:is_at) if valid && @options[:is_at]
|
||||||
valid = test_option(:before) if valid && @options[:before]
|
valid = test_option(:before) if valid && @options[:before]
|
||||||
valid = test_option(:after) if valid && @options[:after]
|
valid = test_option(:after) if valid && @options[:after]
|
||||||
valid = test_option(:on_or_before) if valid && @options[:on_or_before]
|
valid = test_option(:on_or_before) if valid && @options[:on_or_before]
|
||||||
|
|||||||
@ -6,7 +6,7 @@ module ValidatesTimeliness
|
|||||||
self.ignore_restriction_errors = false
|
self.ignore_restriction_errors = false
|
||||||
|
|
||||||
RESTRICTION_METHODS = {
|
RESTRICTION_METHODS = {
|
||||||
:equal_to => :==,
|
:is_at => :==,
|
||||||
:before => :<,
|
:before => :<,
|
||||||
:after => :>,
|
:after => :>,
|
||||||
:on_or_before => :<=,
|
:on_or_before => :<=,
|
||||||
|
|||||||
@ -6,7 +6,7 @@ end
|
|||||||
|
|
||||||
class WithValidation < Person
|
class WithValidation < Person
|
||||||
validates_date :birth_date,
|
validates_date :birth_date,
|
||||||
:equal_to => '2000-01-01',
|
:is_at => '2000-01-01',
|
||||||
:before => '2000-01-10',
|
:before => '2000-01-10',
|
||||||
:after => '2000-01-01',
|
:after => '2000-01-01',
|
||||||
:on_or_before => '2000-01-09',
|
:on_or_before => '2000-01-09',
|
||||||
@ -14,7 +14,7 @@ class WithValidation < Person
|
|||||||
:between => ['2000-01-01', '2000-01-03']
|
:between => ['2000-01-01', '2000-01-03']
|
||||||
|
|
||||||
validates_time :birth_time,
|
validates_time :birth_time,
|
||||||
:equal_to => '09:00',
|
:is_at => '09:00',
|
||||||
:before => '23:00',
|
:before => '23:00',
|
||||||
:after => '09:00',
|
:after => '09:00',
|
||||||
:on_or_before => '22:00',
|
:on_or_before => '22:00',
|
||||||
@ -22,7 +22,7 @@ class WithValidation < Person
|
|||||||
:between => ['09:00', '17:00']
|
:between => ['09:00', '17:00']
|
||||||
|
|
||||||
validates_datetime :birth_date_and_time,
|
validates_datetime :birth_date_and_time,
|
||||||
:equal_to => '2000-01-01 09:00',
|
:is_at => '2000-01-01 09:00',
|
||||||
:before => '2000-01-10 23:00',
|
:before => '2000-01-10 23:00',
|
||||||
:after => '2000-01-01 09:00',
|
:after => '2000-01-01 09:00',
|
||||||
:on_or_before => '2000-01-09 23:00',
|
:on_or_before => '2000-01-09 23:00',
|
||||||
@ -65,7 +65,7 @@ describe "ValidateTimeliness matcher" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with equal_to option" do
|
describe "with is_at option" do
|
||||||
test_values = {
|
test_values = {
|
||||||
:date => ['2000-01-01', '2000-01-02'],
|
:date => ['2000-01-01', '2000-01-02'],
|
||||||
:time => ['09:00', '09:01'],
|
:time => ['09:00', '09:01'],
|
||||||
@ -75,15 +75,15 @@ describe "ValidateTimeliness matcher" do
|
|||||||
[:date, :time, :datetime].each do |type|
|
[:date, :time, :datetime].each do |type|
|
||||||
|
|
||||||
it "should report that #{type} is validated" do
|
it "should report that #{type} is validated" do
|
||||||
with_validation.should self.send("validate_#{type}", attribute_for_type(type), :equal_to => test_values[type][0])
|
with_validation.should self.send("validate_#{type}", attribute_for_type(type), :is_at => test_values[type][0])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should report that #{type} is not validated when option value is incorrect" do
|
it "should report that #{type} is not validated when option value is incorrect" do
|
||||||
with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :equal_to => test_values[type][1])
|
with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :is_at => test_values[type][1])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should report that #{type} is not validated with option" do
|
it "should report that #{type} is not validated with option" do
|
||||||
no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :equal_to => test_values[type][0])
|
no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :is_at => test_values[type][0])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -346,53 +346,53 @@ describe ValidatesTimeliness::Validator do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "instance with :equal_to restriction" do
|
describe "instance with :is_at restriction" do
|
||||||
|
|
||||||
describe "for datetime type" do
|
describe "for datetime type" do
|
||||||
before do
|
before do
|
||||||
configure_validator(:equal_to => Time.now)
|
configure_validator(:is_at => Time.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have error when value not equal to :equal_to restriction" do
|
it "should have error when value not equal to :is_at restriction" do
|
||||||
validate_with(:birth_date_and_time, Time.now + 1)
|
validate_with(:birth_date_and_time, Time.now + 1)
|
||||||
should_have_error(:birth_date_and_time, :equal_to)
|
should_have_error(:birth_date_and_time, :is_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be valid when value is equal to :equal_to restriction" do
|
it "should be valid when value is equal to :is_at restriction" do
|
||||||
validate_with(:birth_date_and_time, Time.now)
|
validate_with(:birth_date_and_time, Time.now)
|
||||||
should_have_no_error(:birth_date_and_time, :equal_to)
|
should_have_no_error(:birth_date_and_time, :is_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "for date type" do
|
describe "for date type" do
|
||||||
before do
|
before do
|
||||||
configure_validator(:type => :date, :equal_to => Date.today)
|
configure_validator(:type => :date, :is_at => Date.today)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have error when value is not equal to :equal_to restriction" do
|
it "should have error when value is not equal to :is_at restriction" do
|
||||||
validate_with(:birth_date, Date.today + 1)
|
validate_with(:birth_date, Date.today + 1)
|
||||||
should_have_error(:birth_date, :equal_to)
|
should_have_error(:birth_date, :is_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be valid when value is equal to :equal_to restriction" do
|
it "should be valid when value is equal to :is_at restriction" do
|
||||||
validate_with(:birth_date, Date.today)
|
validate_with(:birth_date, Date.today)
|
||||||
should_have_no_error(:birth_date, :equal_to)
|
should_have_no_error(:birth_date, :is_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "for time type" do
|
describe "for time type" do
|
||||||
before do
|
before do
|
||||||
configure_validator(:type => :time, :equal_to => "09:00:00")
|
configure_validator(:type => :time, :is_at => "09:00:00")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have error when value is not equal to :equal_to restriction" do
|
it "should have error when value is not equal to :is_at restriction" do
|
||||||
validate_with(:birth_time, "09:00:01")
|
validate_with(:birth_time, "09:00:01")
|
||||||
should_have_error(:birth_time, :equal_to)
|
should_have_error(:birth_time, :is_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be valid when value is equal to :equal_to restriction" do
|
it "should be valid when value is equal to :is_at restriction" do
|
||||||
validate_with(:birth_time, "09:00:00")
|
validate_with(:birth_time, "09:00:00")
|
||||||
should_have_no_error(:birth_time, :equal_to)
|
should_have_no_error(:birth_time, :is_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -400,9 +400,9 @@ describe ValidatesTimeliness::Validator do
|
|||||||
describe "instance with :ignore_usec option" do
|
describe "instance with :ignore_usec option" do
|
||||||
|
|
||||||
it "should ignore usec on time values when evaluated" do
|
it "should ignore usec on time values when evaluated" do
|
||||||
configure_validator(:equal_to => Time.utc(2000, 1, 1, 0, 0, 0, 0), :ignore_usec => true)
|
configure_validator(:is_at => Time.utc(2000, 1, 1, 0, 0, 0, 0), :ignore_usec => true)
|
||||||
validate_with(:birth_date_and_time, Time.utc(2000, 1, 1, 0, 0, 0, 500))
|
validate_with(:birth_date_and_time, Time.utc(2000, 1, 1, 0, 0, 0, 500))
|
||||||
should_have_no_error(:birth_date_and_time, :equal_to)
|
should_have_no_error(:birth_date_and_time, :is_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -422,9 +422,9 @@ describe ValidatesTimeliness::Validator do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should should ignore usec value on combined value if :ignore_usec option is true" do
|
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), :equal_to => Time.mktime(2000,1,1,12,30), :ignore_usec => true)
|
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")
|
validate_with(:birth_date, "2000-01-01")
|
||||||
should_have_no_error(:birth_date, :equal_to)
|
should_have_no_error(:birth_date, :is_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user