mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6af61917dd | ||
|
|
43e6748cd2 | ||
|
|
760a52a2a4 | ||
|
|
9f1642c730 | ||
|
|
011ea070db | ||
|
|
b632093ce2 | ||
|
|
525b3b9941 |
@@ -1,3 +1,8 @@
|
||||
= 1.1.2 [2009-01-12]
|
||||
- Fixed bugs
|
||||
- matcher failing for custom error message without interpolation keys using I18n
|
||||
- validator custom error messages not being extracted
|
||||
|
||||
= 1.1.1 [2009-01-03]
|
||||
- Fixed bug in matcher for options local variable
|
||||
|
||||
|
||||
2
Rakefile
2
Rakefile
@@ -5,7 +5,7 @@ require 'date'
|
||||
require 'spec/rake/spectask'
|
||||
|
||||
GEM = "validates_timeliness"
|
||||
GEM_VERSION = "1.1.1"
|
||||
GEM_VERSION = "1.1.2"
|
||||
AUTHOR = "Adam Meehan"
|
||||
EMAIL = "adam.meehan@gmail.com"
|
||||
HOMEPAGE = "http://github.com/adzap/validates_timeliness"
|
||||
|
||||
6
TODO
6
TODO
@@ -1,7 +1,5 @@
|
||||
- :format option
|
||||
- :with_date and :with_time options
|
||||
- Merb and Data Mapper support
|
||||
- does it have before_type_cast
|
||||
- timezone handling
|
||||
- view helper support
|
||||
- valid formats could come from locale file
|
||||
- formats to use month and day names from i18n
|
||||
- add replace_formats instead add_formats :before
|
||||
|
||||
@@ -123,7 +123,8 @@ module Spec
|
||||
restriction = [restriction] unless restriction.is_a?(Array)
|
||||
restriction.map! {|r| @validator.send(:type_cast_value, r) }
|
||||
interpolate = @validator.send(:interpolation_values, option, restriction )
|
||||
if defined?(I18n)
|
||||
# get I18n message if defined and has interpolation keys in msg
|
||||
if defined?(I18n) && !@validator.send(:custom_error_messages).include?(option)
|
||||
msg = @record.errors.generate_message(@expected, option, interpolate)
|
||||
else
|
||||
msg = msg % interpolate
|
||||
|
||||
@@ -115,7 +115,7 @@ module ValidatesTimeliness
|
||||
return @custom_error_messages if defined?(@custom_error_messages)
|
||||
@custom_error_messages = configuration.inject({}) {|msgs, (k, v)|
|
||||
if md = /(.*)_message$/.match(k.to_s)
|
||||
msgs[md[0].to_sym] = v
|
||||
msgs[md[1].to_sym] = v
|
||||
end
|
||||
msgs
|
||||
}
|
||||
|
||||
@@ -5,27 +5,39 @@ end
|
||||
|
||||
class WithValidation < Person
|
||||
validates_date :birth_date,
|
||||
:before => '2000-01-10', :after => '2000-01-01',
|
||||
:on_or_before => '2000-01-09', :on_or_after => '2000-01-02',
|
||||
:before => '2000-01-10',
|
||||
:after => '2000-01-01',
|
||||
:on_or_before => '2000-01-09',
|
||||
:on_or_after => '2000-01-02',
|
||||
:between => ['2000-01-01', '2000-01-03']
|
||||
|
||||
validates_time :birth_time,
|
||||
:before => '23:00', :after => '09:00',
|
||||
:on_or_before => '22:00', :on_or_after => '10:00',
|
||||
:before => '23:00',
|
||||
:after => '09:00',
|
||||
:on_or_before => '22:00',
|
||||
:on_or_after => '10:00',
|
||||
:between => ['09:00', '17:00']
|
||||
|
||||
validates_datetime :birth_date_and_time,
|
||||
:before => '2000-01-10 23:00', :after => '2000-01-01 09:00',
|
||||
:on_or_before => '2000-01-09 23:00', :on_or_after => '2000-01-02 09:00',
|
||||
:before => '2000-01-10 23:00',
|
||||
:after => '2000-01-01 09:00',
|
||||
:on_or_before => '2000-01-09 23:00',
|
||||
:on_or_after => '2000-01-02 09:00',
|
||||
:between => ['2000-01-01 09:00', '2000-01-01 17:00']
|
||||
|
||||
end
|
||||
|
||||
class CustomMessages < Person
|
||||
validates_date :birth_date, :invalid_date_message => 'is not really a date',
|
||||
:before => '2000-01-10', :before_message => 'is too late',
|
||||
:after => '2000-01-01', :after_message => 'is too early',
|
||||
:on_or_before=> '2000-01-09', :on_or_before_message => 'is just too late',
|
||||
:on_or_after => '2000-01-02', :on_or_after_message => 'is just too early'
|
||||
validates_date :birth_date,
|
||||
:invalid_date_message => 'is not really a date',
|
||||
:before => '2000-01-10',
|
||||
:before_message => 'is too late',
|
||||
:after => '2000-01-01',
|
||||
:after_message => 'is too early',
|
||||
:on_or_before => '2000-01-09',
|
||||
:on_or_before_message => 'is just too late',
|
||||
:on_or_after => '2000-01-02',
|
||||
:on_or_after_message => 'is just too early'
|
||||
end
|
||||
|
||||
describe "ValidateTimeliness matcher" do
|
||||
|
||||
@@ -363,6 +363,40 @@ describe ValidatesTimeliness::Validator do
|
||||
end
|
||||
end
|
||||
|
||||
describe "custom_error_messages" do
|
||||
it "should return hash of custom error messages from configuration with _message truncated from keys" do
|
||||
configure_validator(:type => :date, :invalid_date_message => 'thats no date')
|
||||
validator.send(:custom_error_messages)[:invalid_date].should == 'thats no date'
|
||||
end
|
||||
|
||||
it "should return empty hash if no custom error messages in configuration" do
|
||||
configure_validator(:type => :date)
|
||||
validator.send(:custom_error_messages).should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "interpolation_values" do
|
||||
if defined?(I18n)
|
||||
it "should return hash of interpolation keys with restriction values" do
|
||||
before = '1900-01-01'
|
||||
configure_validator(:type => :date, :before => before)
|
||||
validator.send(:interpolation_values, :before, before.to_date).should == {:restriction => before}
|
||||
end
|
||||
|
||||
it "should return empty hash if no interpolation keys are in message" do
|
||||
before = '1900-01-01'
|
||||
configure_validator(:type => :date, :before => before, :before_message => 'too late')
|
||||
validator.send(:interpolation_values, :before, before.to_date).should be_empty
|
||||
end
|
||||
else
|
||||
it "should return array of interpolation values" do
|
||||
before = '1900-01-01'
|
||||
configure_validator(:type => :date, :before => before)
|
||||
validator.send(:interpolation_values, :before, before.to_date).should == [before]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "restriction errors" do
|
||||
before :each do
|
||||
configure_validator(:type => :date, :before => lambda { raise })
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{validates_timeliness}
|
||||
s.version = "1.1.1"
|
||||
s.version = "1.1.2"
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Adam Meehan"]
|
||||
s.autorequire = %q{validates_timeliness}
|
||||
s.date = %q{2009-01-03}
|
||||
s.date = %q{2009-01-12}
|
||||
s.description = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
||||
s.email = %q{adam.meehan@gmail.com}
|
||||
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
|
||||
|
||||
Reference in New Issue
Block a user