change equal_to to is_at to fix overlap with default rails message

This commit is contained in:
Adam Meehan 2009-12-11 15:20:34 +11:00
parent 3bfc7b748f
commit f3c119e191
7 changed files with 109 additions and 108 deletions

View File

@ -317,6 +317,7 @@ For Rails 2.0/2.1:
:invalid_date => "is not a valid date",
:invalid_time => "is not a valid time",
:invalid_datetime => "is not a valid datetime",
:is_at => "must be at %s",
:before => "must be before %s",
:on_or_before => "must be on or before %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_time: "is not a valid time"
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}}"
on_or_before: "must be on or before {{restriction}}"
after: "must be after {{restriction}}"

View File

@ -5,7 +5,7 @@ en:
invalid_date: "is not a valid date"
invalid_time: "is not a valid time"
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}}"
on_or_before: "must be on or before {{restriction}}"
after: "must be after {{restriction}}"

View File

@ -10,7 +10,7 @@ module Spec
}
OPTION_TEST_SETTINGS = {
:equal_to => { :method => :+, :modify_on => :invalid },
:is_at => { :method => :+, :modify_on => :invalid },
:before => { :method => :-, :modify_on => :valid },
:after => { :method => :+, :modify_on => :valid },
:on_or_before => { :method => :+, :modify_on => :invalid },
@ -28,7 +28,7 @@ module Spec
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(:after) if valid && @options[:after]
valid = test_option(:on_or_before) if valid && @options[:on_or_before]

View File

@ -6,7 +6,7 @@ module ValidatesTimeliness
self.ignore_restriction_errors = false
RESTRICTION_METHODS = {
:equal_to => :==,
:is_at => :==,
:before => :<,
:after => :>,
:on_or_before => :<=,

View File

@ -6,7 +6,7 @@ end
class WithValidation < Person
validates_date :birth_date,
:equal_to => '2000-01-01',
:is_at => '2000-01-01',
:before => '2000-01-10',
:after => '2000-01-01',
:on_or_before => '2000-01-09',
@ -14,7 +14,7 @@ class WithValidation < Person
:between => ['2000-01-01', '2000-01-03']
validates_time :birth_time,
:equal_to => '09:00',
:is_at => '09:00',
:before => '23:00',
:after => '09:00',
:on_or_before => '22:00',
@ -22,7 +22,7 @@ class WithValidation < Person
:between => ['09:00', '17:00']
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',
:after => '2000-01-01 09:00',
:on_or_before => '2000-01-09 23:00',
@ -65,7 +65,7 @@ describe "ValidateTimeliness matcher" do
end
end
describe "with equal_to option" do
describe "with is_at option" do
test_values = {
:date => ['2000-01-01', '2000-01-02'],
:time => ['09:00', '09:01'],
@ -75,15 +75,15 @@ describe "ValidateTimeliness matcher" do
[:date, :time, :datetime].each do |type|
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
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
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

View File

@ -346,53 +346,53 @@ describe ValidatesTimeliness::Validator do
end
end
describe "instance with :equal_to restriction" do
describe "instance with :is_at restriction" do
describe "for datetime type" do
before do
configure_validator(:equal_to => Time.now)
configure_validator(:is_at => Time.now)
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)
should_have_error(:birth_date_and_time, :equal_to)
should_have_error(:birth_date_and_time, :is_at)
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)
should_have_no_error(:birth_date_and_time, :equal_to)
should_have_no_error(:birth_date_and_time, :is_at)
end
end
describe "for date type" do
before do
configure_validator(:type => :date, :equal_to => Date.today)
configure_validator(:type => :date, :is_at => Date.today)
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)
should_have_error(:birth_date, :equal_to)
should_have_error(:birth_date, :is_at)
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)
should_have_no_error(:birth_date, :equal_to)
should_have_no_error(:birth_date, :is_at)
end
end
describe "for time type" do
before do
configure_validator(:type => :time, :equal_to => "09:00:00")
configure_validator(:type => :time, :is_at => "09:00:00")
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")
should_have_error(:birth_time, :equal_to)
should_have_error(:birth_time, :is_at)
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")
should_have_no_error(:birth_time, :equal_to)
should_have_no_error(:birth_time, :is_at)
end
end
end
@ -400,9 +400,9 @@ describe ValidatesTimeliness::Validator do
describe "instance with :ignore_usec option" 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))
should_have_no_error(:birth_date_and_time, :equal_to)
should_have_no_error(:birth_date_and_time, :is_at)
end
end
@ -422,9 +422,9 @@ describe ValidatesTimeliness::Validator do
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), :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")
should_have_no_error(:birth_date, :equal_to)
should_have_no_error(:birth_date, :is_at)
end
end