mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-26 07:43:00 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6af61917dd | ||
|
|
43e6748cd2 | ||
|
|
760a52a2a4 | ||
|
|
9f1642c730 | ||
|
|
011ea070db | ||
|
|
b632093ce2 | ||
|
|
525b3b9941 | ||
|
|
db8dd9ac99 | ||
|
|
1fdfc23cb8 | ||
|
|
7d3ee4bc1b | ||
|
|
694a4bdd69 | ||
|
|
07359c6157 |
@@ -1,3 +1,11 @@
|
|||||||
|
= 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
|
||||||
|
|
||||||
= 1.1.0 [2009-01-01]
|
= 1.1.0 [2009-01-01]
|
||||||
- Added between option
|
- Added between option
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ think should be a valid date or time string.
|
|||||||
|
|
||||||
* Supports Rails 2.2 I18n for the error messages
|
* Supports Rails 2.2 I18n for the error messages
|
||||||
|
|
||||||
|
* Rspec matcher for testing model validation of dates and times
|
||||||
|
|
||||||
|
|
||||||
== INSTALLATION:
|
== INSTALLATION:
|
||||||
|
|
||||||
|
|||||||
2
Rakefile
2
Rakefile
@@ -5,7 +5,7 @@ require 'date'
|
|||||||
require 'spec/rake/spectask'
|
require 'spec/rake/spectask'
|
||||||
|
|
||||||
GEM = "validates_timeliness"
|
GEM = "validates_timeliness"
|
||||||
GEM_VERSION = "1.1.0"
|
GEM_VERSION = "1.1.2"
|
||||||
AUTHOR = "Adam Meehan"
|
AUTHOR = "Adam Meehan"
|
||||||
EMAIL = "adam.meehan@gmail.com"
|
EMAIL = "adam.meehan@gmail.com"
|
||||||
HOMEPAGE = "http://github.com/adzap/validates_timeliness"
|
HOMEPAGE = "http://github.com/adzap/validates_timeliness"
|
||||||
|
|||||||
7
TODO
7
TODO
@@ -1,8 +1,5 @@
|
|||||||
- :between option
|
|
||||||
- :format option
|
- :format option
|
||||||
- :with_date and :with_time options
|
- :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
|
- valid formats could come from locale file
|
||||||
|
- formats to use month and day names from i18n
|
||||||
|
- add replace_formats instead add_formats :before
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ module ValidatesTimeliness
|
|||||||
self.send("setup_for_rails_#{major}_#{minor}")
|
self.send("setup_for_rails_#{major}_#{minor}")
|
||||||
self.default_timezone = ::ActiveRecord::Base.default_timezone
|
self.default_timezone = ::ActiveRecord::Base.default_timezone
|
||||||
rescue
|
rescue
|
||||||
raise "Rails version #{Rails::VERSION::STRING} not yet supported by validates_timeliness plugin"
|
puts "Rails version #{Rails::VERSION::STRING} not explicitly supported by validates_timeliness plugin. You may encounter some problems."
|
||||||
|
resume
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ module Spec
|
|||||||
|
|
||||||
def matches?(record)
|
def matches?(record)
|
||||||
@record = record
|
@record = record
|
||||||
@type = options[:type]
|
@type = @options[:type]
|
||||||
|
|
||||||
valid = test_validity
|
valid = test_validity
|
||||||
|
|
||||||
@@ -123,7 +123,8 @@ module Spec
|
|||||||
restriction = [restriction] unless restriction.is_a?(Array)
|
restriction = [restriction] unless restriction.is_a?(Array)
|
||||||
restriction.map! {|r| @validator.send(:type_cast_value, r) }
|
restriction.map! {|r| @validator.send(:type_cast_value, r) }
|
||||||
interpolate = @validator.send(:interpolation_values, option, restriction )
|
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)
|
msg = @record.errors.generate_message(@expected, option, interpolate)
|
||||||
else
|
else
|
||||||
msg = msg % interpolate
|
msg = msg % interpolate
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ module ValidatesTimeliness
|
|||||||
return @custom_error_messages if defined?(@custom_error_messages)
|
return @custom_error_messages if defined?(@custom_error_messages)
|
||||||
@custom_error_messages = configuration.inject({}) {|msgs, (k, v)|
|
@custom_error_messages = configuration.inject({}) {|msgs, (k, v)|
|
||||||
if md = /(.*)_message$/.match(k.to_s)
|
if md = /(.*)_message$/.match(k.to_s)
|
||||||
msgs[md[0].to_sym] = v
|
msgs[md[1].to_sym] = v
|
||||||
end
|
end
|
||||||
msgs
|
msgs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,27 +5,39 @@ end
|
|||||||
|
|
||||||
class WithValidation < Person
|
class WithValidation < Person
|
||||||
validates_date :birth_date,
|
validates_date :birth_date,
|
||||||
:before => '2000-01-10', :after => '2000-01-01',
|
:before => '2000-01-10',
|
||||||
:on_or_before => '2000-01-09', :on_or_after => '2000-01-02',
|
:after => '2000-01-01',
|
||||||
|
:on_or_before => '2000-01-09',
|
||||||
|
:on_or_after => '2000-01-02',
|
||||||
:between => ['2000-01-01', '2000-01-03']
|
:between => ['2000-01-01', '2000-01-03']
|
||||||
|
|
||||||
validates_time :birth_time,
|
validates_time :birth_time,
|
||||||
:before => '23:00', :after => '09:00',
|
:before => '23:00',
|
||||||
:on_or_before => '22:00', :on_or_after => '10:00',
|
:after => '09:00',
|
||||||
|
:on_or_before => '22:00',
|
||||||
|
:on_or_after => '10:00',
|
||||||
:between => ['09:00', '17:00']
|
:between => ['09:00', '17:00']
|
||||||
|
|
||||||
validates_datetime :birth_date_and_time,
|
validates_datetime :birth_date_and_time,
|
||||||
:before => '2000-01-10 23:00', :after => '2000-01-01 09:00',
|
:before => '2000-01-10 23:00',
|
||||||
:on_or_before => '2000-01-09 23:00', :on_or_after => '2000-01-02 09: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']
|
:between => ['2000-01-01 09:00', '2000-01-01 17:00']
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class CustomMessages < Person
|
class CustomMessages < Person
|
||||||
validates_date :birth_date, :invalid_date_message => 'is not really a date',
|
validates_date :birth_date,
|
||||||
:before => '2000-01-10', :before_message => 'is too late',
|
:invalid_date_message => 'is not really a date',
|
||||||
:after => '2000-01-01', :after_message => 'is too early',
|
:before => '2000-01-10',
|
||||||
:on_or_before=> '2000-01-09', :on_or_before_message => 'is just too late',
|
:before_message => 'is too late',
|
||||||
:on_or_after => '2000-01-02', :on_or_after_message => 'is just too early'
|
: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
|
end
|
||||||
|
|
||||||
describe "ValidateTimeliness matcher" do
|
describe "ValidateTimeliness matcher" do
|
||||||
|
|||||||
@@ -363,6 +363,40 @@ describe ValidatesTimeliness::Validator do
|
|||||||
end
|
end
|
||||||
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
|
describe "restriction errors" do
|
||||||
before :each do
|
before :each do
|
||||||
configure_validator(:type => :date, :before => lambda { raise })
|
configure_validator(:type => :date, :before => lambda { raise })
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{validates_timeliness}
|
s.name = %q{validates_timeliness}
|
||||||
s.version = "1.1.0"
|
s.version = "1.1.2"
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Adam Meehan"]
|
s.authors = ["Adam Meehan"]
|
||||||
s.autorequire = %q{validates_timeliness}
|
s.autorequire = %q{validates_timeliness}
|
||||||
s.date = %q{2009-01-01}
|
s.date = %q{2009-01-12}
|
||||||
s.description = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
s.description = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
||||||
s.email = %q{adam.meehan@gmail.com}
|
s.email = %q{adam.meehan@gmail.com}
|
||||||
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
|
||||||
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "CHANGELOG", "lib/validates_timeliness", "lib/validates_timeliness/active_record", "lib/validates_timeliness/active_record/multiparameter_attributes.rb", "lib/validates_timeliness/active_record/attribute_methods.rb", "lib/validates_timeliness/core_ext", "lib/validates_timeliness/core_ext/date.rb", "lib/validates_timeliness/core_ext/time.rb", "lib/validates_timeliness/core_ext/date_time.rb", "lib/validates_timeliness/validator.rb", "lib/validates_timeliness/validation_methods.rb", "lib/validates_timeliness/locale", "lib/validates_timeliness/locale/en.yml", "lib/validates_timeliness/spec", "lib/validates_timeliness/spec/rails", "lib/validates_timeliness/spec/rails/matchers", "lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb", "lib/validates_timeliness/action_view", "lib/validates_timeliness/action_view/instance_tag.rb", "lib/validates_timeliness/formats.rb", "lib/validates_timeliness.rb", "spec/active_record", "spec/active_record/multiparameter_attributes_spec.rb", "spec/active_record/attribute_methods_spec.rb", "spec/validation_methods_spec.rb", "spec/formats_spec.rb", "spec/core_ext", "spec/core_ext/dummy_time_spec.rb", "spec/spec_helper.rb", "spec/ginger_scenarios.rb", "spec/time_travel", "spec/time_travel/time_extensions.rb", "spec/time_travel/time_travel.rb", "spec/time_travel/MIT-LICENSE", "spec/spec", "spec/spec/rails", "spec/spec/rails/matchers", "spec/spec/rails/matchers/validate_timeliness_spec.rb", "spec/validator_spec.rb", "spec/action_view", "spec/action_view/instance_tag_spec.rb", "spec/resources", "spec/resources/schema.rb", "spec/resources/application.rb", "spec/resources/person.rb", "spec/resources/sqlite_patch.rb"]
|
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "CHANGELOG", "lib/validates_timeliness", "lib/validates_timeliness/core_ext", "lib/validates_timeliness/core_ext/date.rb", "lib/validates_timeliness/core_ext/date_time.rb", "lib/validates_timeliness/core_ext/time.rb", "lib/validates_timeliness/action_view", "lib/validates_timeliness/action_view/instance_tag.rb", "lib/validates_timeliness/locale", "lib/validates_timeliness/locale/en.yml", "lib/validates_timeliness/validation_methods.rb", "lib/validates_timeliness/active_record", "lib/validates_timeliness/active_record/attribute_methods.rb", "lib/validates_timeliness/active_record/multiparameter_attributes.rb", "lib/validates_timeliness/formats.rb", "lib/validates_timeliness/validator.rb", "lib/validates_timeliness/spec", "lib/validates_timeliness/spec/rails", "lib/validates_timeliness/spec/rails/matchers", "lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb", "lib/validates_timeliness.rb", "spec/core_ext", "spec/core_ext/dummy_time_spec.rb", "spec/validator_spec.rb", "spec/action_view", "spec/action_view/instance_tag_spec.rb", "spec/ginger_scenarios.rb", "spec/validation_methods_spec.rb", "spec/spec_helper.rb", "spec/formats_spec.rb", "spec/active_record", "spec/active_record/attribute_methods_spec.rb", "spec/active_record/multiparameter_attributes_spec.rb", "spec/time_travel", "spec/time_travel/time_travel.rb", "spec/time_travel/time_extensions.rb", "spec/time_travel/MIT-LICENSE", "spec/spec", "spec/spec/rails", "spec/spec/rails/matchers", "spec/spec/rails/matchers/validate_timeliness_spec.rb", "spec/resources", "spec/resources/person.rb", "spec/resources/sqlite_patch.rb", "spec/resources/schema.rb", "spec/resources/application.rb"]
|
||||||
s.has_rdoc = true
|
s.has_rdoc = true
|
||||||
s.homepage = %q{http://github.com/adzap/validates_timeliness}
|
s.homepage = %q{http://github.com/adzap/validates_timeliness}
|
||||||
s.require_paths = ["lib"]
|
s.require_paths = ["lib"]
|
||||||
|
|||||||
Reference in New Issue
Block a user