mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20c0aaa793 | ||
|
|
a756b66f75 | ||
|
|
889b5a9b07 | ||
|
|
0e3f56e26d | ||
|
|
7ca662ada8 | ||
|
|
03effb9e52 |
@@ -1,3 +1,6 @@
|
|||||||
|
= 3.0.1 [2010-11-02]
|
||||||
|
* Generate timeliness write methods in an included module to allow overriding in model class (josevalim)
|
||||||
|
|
||||||
= 3.0.0 [2010-10-18]
|
= 3.0.0 [2010-10-18]
|
||||||
* Rails 3 and ActiveModel compatibility
|
* Rails 3 and ActiveModel compatibility
|
||||||
* Uses ActiveModel::EachValidator as validator base class.
|
* Uses ActiveModel::EachValidator as validator base class.
|
||||||
|
|||||||
24
Gemfile
24
Gemfile
@@ -1,16 +1,20 @@
|
|||||||
source 'http://rubygems.org'
|
source 'http://rubygems.org'
|
||||||
|
|
||||||
gem 'timeliness', '~> 0.1.1'
|
gemspec
|
||||||
|
|
||||||
group :test do
|
gem 'ZenTest'
|
||||||
gem 'ZenTest'
|
gem 'rails', '3.0.0'
|
||||||
gem 'rails', '3.0.0'
|
gem 'rspec', '>= 2.0.0.beta.17'
|
||||||
gem 'sqlite3-ruby', :require => 'sqlite3'
|
gem 'rspec-rails', '>= 2.0.0.beta.17'
|
||||||
|
gem 'timecop'
|
||||||
|
gem 'rspec_tag_matchers'
|
||||||
|
gem 'ruby-debug'
|
||||||
|
|
||||||
|
group :mongoid do
|
||||||
gem 'mongoid', '2.0.0.beta.17'
|
gem 'mongoid', '2.0.0.beta.17'
|
||||||
gem 'bson_ext', '1.0.4'
|
gem 'bson_ext', '1.0.4'
|
||||||
gem 'rspec', '>= 2.0.0.beta.17'
|
|
||||||
gem 'rspec-rails', '>= 2.0.0.beta.17'
|
|
||||||
gem 'timecop'
|
|
||||||
gem 'rspec_tag_matchers'
|
|
||||||
gem 'ruby-debug'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
group :active_record do
|
||||||
|
gem 'sqlite3-ruby', :require => 'sqlite3'
|
||||||
|
end
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
PATH
|
||||||
|
remote: .
|
||||||
|
specs:
|
||||||
|
validates_timeliness (3.0.0)
|
||||||
|
timeliness (~> 0.1.0)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
@@ -117,4 +123,5 @@ DEPENDENCIES
|
|||||||
ruby-debug
|
ruby-debug
|
||||||
sqlite3-ruby
|
sqlite3-ruby
|
||||||
timecop
|
timecop
|
||||||
timeliness (~> 0.1.1)
|
timeliness (~> 0.1.0)
|
||||||
|
validates_timeliness!
|
||||||
|
|||||||
53
README.rdoc
53
README.rdoc
@@ -18,9 +18,9 @@ If you a looking for the old version for Rails 2.x go here[http://github.com/adz
|
|||||||
|
|
||||||
* Only Rails date/time validation plugin offering complete validation (See ORM/ODM support)
|
* Only Rails date/time validation plugin offering complete validation (See ORM/ODM support)
|
||||||
|
|
||||||
* Adds extensions to fix Rails date/time select issues
|
* Adds extensions to fix Rails date/time select issues (See Extensions)
|
||||||
|
|
||||||
* Uses extensible date/time parser ({timeliness gem}[http://github.com/adzap/timeliness])
|
* Uses extensible date/time parser (Using {timeliness gem}[http://github.com/adzap/timeliness]. See Plugin Parser)
|
||||||
|
|
||||||
* Supports I18n for the error messages
|
* Supports I18n for the error messages
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ As plugin (from master)
|
|||||||
|
|
||||||
rails plugin install git://github.com/adzap/validates_timeliness.git
|
rails plugin install git://github.com/adzap/validates_timeliness.git
|
||||||
|
|
||||||
As gem (in beta)
|
As gem
|
||||||
|
|
||||||
# in Gemfile
|
# in Gemfile
|
||||||
gem 'validates_timeliness', '~> 3.0.0'
|
gem 'validates_timeliness', '~> 3.0.0'
|
||||||
@@ -46,6 +46,8 @@ Then run
|
|||||||
This creates configuration initializer and locale files. In the initializer, you there are a number of config
|
This creates configuration initializer and locale files. In the initializer, you there are a number of config
|
||||||
options to customize the plugin.
|
options to customize the plugin.
|
||||||
|
|
||||||
|
NOTE: You may wish to enable the plugin parser and the extensions to start. Please read those sections first.
|
||||||
|
|
||||||
|
|
||||||
== Examples
|
== Examples
|
||||||
|
|
||||||
@@ -175,7 +177,8 @@ You can also use validation options for custom error messages. The following opt
|
|||||||
:after_message
|
:after_message
|
||||||
:on_or_after_message
|
:on_or_after_message
|
||||||
|
|
||||||
Note: There is no :between_message option. The between error message should be defined using the :on_or_before and :on_or_after messages.
|
Note: There is no :between_message option. The between error message should be defined using the
|
||||||
|
:on_or_before and :on_or_after messages.
|
||||||
|
|
||||||
It is highly recommended you use the I18n system for error messages.
|
It is highly recommended you use the I18n system for error messages.
|
||||||
|
|
||||||
@@ -254,36 +257,42 @@ To turn them on/off:
|
|||||||
config.ignore_restriction_errors = true
|
config.ignore_restriction_errors = true
|
||||||
|
|
||||||
|
|
||||||
=== Display Invalid Values in Select Helpers
|
== Extensions
|
||||||
|
|
||||||
The plugin offers an extension for ActionView to allowing invalid
|
|
||||||
date and time values to be redisplayed to the user as feedback, instead of
|
|
||||||
a blank field which happens by default in Rails. Though the date helpers make this a
|
|
||||||
pretty rare occurrence, given the select dropdowns for each date/time component, but
|
|
||||||
it may be something of interest.
|
|
||||||
|
|
||||||
To activate it, put this in an initializer:
|
|
||||||
|
|
||||||
# in the setup block
|
|
||||||
config.enable_date_time_select_extension!
|
|
||||||
|
|
||||||
|
|
||||||
=== Strict Parsing for Select Helpers
|
=== Strict Parsing for Select Helpers
|
||||||
|
|
||||||
When using date/time select helpers, the component values are handled by ActiveRecord using
|
When using date/time select helpers, the component values are handled by ActiveRecord using
|
||||||
the Time class to instantiate them into a time value. But this mean that some invalid dates,
|
the Time class to instantiate them into a time value. This means that some invalid dates,
|
||||||
such as 31st June, are shifted forward and treated as valid. To handle these cases in a strict
|
such as 31st June, are shifted forward and treated as valid. To handle these cases in a strict
|
||||||
way you can enable the plugin handler to treat them as invalid dates.
|
way, you can enable the plugin extension to treat them as invalid dates.
|
||||||
|
|
||||||
To activate it, put this in an initializer:
|
To activate it, uncomment this line in the initializer:
|
||||||
|
|
||||||
# in the setup block
|
# in the setup block
|
||||||
config.enable_multiparameter_extension!
|
config.enable_multiparameter_extension!
|
||||||
|
|
||||||
|
|
||||||
== Credits
|
=== Display Invalid Values in Select Helpers
|
||||||
|
|
||||||
* Adam Meehan (adam.meehan@gmail.com, http://github.com/adzap)
|
The plugin offers an extension for ActionView to allowing invalid date and time values to be
|
||||||
|
redisplayed to the user as feedback, instead of a blank field which happens by default in
|
||||||
|
Rails. Though the date helpers make this a pretty rare occurrence, given the select dropdowns
|
||||||
|
for each date/time component, but it may be something of interest.
|
||||||
|
|
||||||
|
To activate it, uncomment this line in the initializer:
|
||||||
|
|
||||||
|
# in the setup block
|
||||||
|
config.enable_date_time_select_extension!
|
||||||
|
|
||||||
|
|
||||||
|
== Contributors
|
||||||
|
|
||||||
|
To see the generous people who have contributed code, take a look at the {contributors list}[http://github.com/adzap/validates_timeliness/contributors].
|
||||||
|
|
||||||
|
|
||||||
|
== Maintainers
|
||||||
|
|
||||||
|
* {Adam Meehan}[http://github.com/adzap]
|
||||||
|
|
||||||
|
|
||||||
== License
|
== License
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ module ValidatesTimeliness
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
EOV
|
EOV
|
||||||
class_eval(method_body, __FILE__, line)
|
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
||||||
end
|
end
|
||||||
|
|
||||||
def define_timeliness_before_type_cast_method(attr_name)
|
def define_timeliness_before_type_cast_method(attr_name)
|
||||||
@@ -51,7 +51,11 @@ module ValidatesTimeliness
|
|||||||
_timeliness_raw_value_for('#{attr_name}')
|
_timeliness_raw_value_for('#{attr_name}')
|
||||||
end
|
end
|
||||||
EOV
|
EOV
|
||||||
class_eval(method_body, __FILE__, line)
|
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
||||||
|
end
|
||||||
|
|
||||||
|
def generated_timeliness_methods
|
||||||
|
@generated_timeliness_methods ||= Module.new.tap { |m| include(m) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module ValidatesTimeliness
|
module ValidatesTimeliness
|
||||||
VERSION = '3.0.0'
|
VERSION = '3.0.1'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ class Employee < ActiveRecord::Base
|
|||||||
validates_time :birth_time
|
validates_time :birth_time
|
||||||
validates_datetime :birth_datetime
|
validates_datetime :birth_datetime
|
||||||
define_attribute_methods
|
define_attribute_methods
|
||||||
|
|
||||||
|
attr_accessor :redefined_birth_date_called
|
||||||
|
|
||||||
|
def birth_date=(value)
|
||||||
|
self.redefined_birth_date_called = true
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Rspec.configure do |c|
|
Rspec.configure do |c|
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
r._timeliness_raw_value_for(:birth_datetime).should == date_string
|
r._timeliness_raw_value_for(:birth_datetime).should == date_string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not overwrite user defined methods' do
|
||||||
|
e = Employee.new
|
||||||
|
e.birth_date = '2010-01-01'
|
||||||
|
e.redefined_birth_date_called.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
context "with plugin parser" do
|
context "with plugin parser" do
|
||||||
class PersonWithParser
|
class PersonWithParser
|
||||||
include TestModel
|
include TestModel
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{validates_timeliness}
|
s.name = %q{validates_timeliness}
|
||||||
s.version = "3.0.0"
|
s.version = "3.0.1"
|
||||||
|
|
||||||
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.date = %q{2010-10-18}
|
s.date = %q{2010-11-02}
|
||||||
s.description = %q{Date and time validation plugin for Rails which allows custom formats}
|
s.description = %q{Date and time validation plugin for Rails which allows custom formats}
|
||||||
s.email = %q{adam.meehan@gmail.com}
|
s.email = %q{adam.meehan@gmail.com}
|
||||||
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
||||||
|
|||||||
Reference in New Issue
Block a user