mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
Compare commits
27 Commits
v5.0.0.alp
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16221ac092 | ||
|
|
c0c42edd3f | ||
|
|
f8b91e9cea | ||
|
|
7fa4d85ee3 | ||
|
|
70307293c6 | ||
|
|
f42e905cd1 | ||
|
|
35eb50aa40 | ||
|
|
3134072f01 | ||
|
|
797ba48036 | ||
|
|
f8e6480f58 | ||
|
|
3835b2b161 | ||
|
|
00d038bc6f | ||
|
|
a3d0182b5e | ||
|
|
46296f914f | ||
|
|
4447361743 | ||
|
|
4523138c3c | ||
|
|
72807b87a7 | ||
|
|
9daf12c4a1 | ||
|
|
2a80683683 | ||
|
|
3a2882be75 | ||
|
|
bf1c808846 | ||
|
|
d0fcf754ec | ||
|
|
7233ff66dd | ||
|
|
f0ba09f278 | ||
|
|
80ee285b3a | ||
|
|
cf20576253 | ||
|
|
f39fbb0ad2 |
@ -8,7 +8,7 @@ gemfile:
|
|||||||
- gemfiles/rails_5_2.gemfile
|
- gemfiles/rails_5_2.gemfile
|
||||||
|
|
||||||
rvm:
|
rvm:
|
||||||
- "2.5.1"
|
- "2.5.3"
|
||||||
|
|
||||||
script: 'bundle exec rspec'
|
script: 'bundle exec rspec'
|
||||||
|
|
||||||
|
|||||||
@ -8,4 +8,4 @@ end
|
|||||||
|
|
||||||
appraise "rails_5_2" do
|
appraise "rails_5_2" do
|
||||||
gem "rails", "~> 5.2.0"
|
gem "rails", "~> 5.2.0"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,11 +1,21 @@
|
|||||||
= [UNRELEASED]
|
= [UNRELEASED]
|
||||||
* Fix DateTimeSelect extension support (AquisTech)
|
* Fix DateTimeSelect extension support (AquisTech)
|
||||||
|
* Relaxed Timeliness dependency version which allows for >= 0.4.0 with
|
||||||
|
threadsafety fix for use_us_formats and use_euro_formats for hot switching
|
||||||
|
in a request.
|
||||||
|
* Add initializer to ensure Timeliness v0.4+ ambiguous date config is set
|
||||||
|
correctly when using `use_euro_formats` or `remove_use_formats'.
|
||||||
|
|
||||||
Breaking Changes
|
Breaking Changes
|
||||||
* Update Multiparameter extension to use ActiveRecord type classes with multiparameter handling
|
* Update Multiparameter extension to use ActiveRecord type classes with multiparameter handling
|
||||||
which stores a hash of multiparamter values as the value before type cast, no longer a mushed datetime string
|
which stores a hash of multiparamter values as the value before type cast, no longer a mushed datetime string
|
||||||
* Removed all custom plugin attribute methods and method overrides in favour using ActiveModel type system
|
* Removed all custom plugin attribute methods and method overrides in favour using ActiveModel type system
|
||||||
|
|
||||||
|
= 4.1.0 [2019-06-11]
|
||||||
|
* Relaxed Timeliness dependency version to >= 0.3.10 and < 1, which allows
|
||||||
|
version 0.4 with threadsafety fix for use_us_formats and use_euro_formats
|
||||||
|
hot switching in a request.
|
||||||
|
|
||||||
= 4.0.2 [2016-01-07]
|
= 4.0.2 [2016-01-07]
|
||||||
* Fix undefine_generated_methods ivar guard setting to false
|
* Fix undefine_generated_methods ivar guard setting to false
|
||||||
|
|
||||||
|
|||||||
4
Gemfile
4
Gemfile
@ -2,11 +2,11 @@ source 'http://rubygems.org'
|
|||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
gem 'rails', '~> 5.0.0'
|
gem 'rails', '~> 5.2.4'
|
||||||
gem 'rspec'
|
gem 'rspec'
|
||||||
gem 'rspec-rails', '~> 3.7'
|
gem 'rspec-rails', '~> 3.7'
|
||||||
gem 'timecop'
|
gem 'timecop'
|
||||||
gem 'byebug'
|
gem 'byebug'
|
||||||
gem 'appraisal'
|
gem 'appraisal'
|
||||||
gem 'sqlite3'
|
gem 'sqlite3', '~> 1.3.6'
|
||||||
gem 'nokogiri', '~> 1.8'
|
gem 'nokogiri', '~> 1.8'
|
||||||
|
|||||||
36
README.rdoc
36
README.rdoc
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
== Description
|
== Description
|
||||||
|
|
||||||
Complete validation of dates, times and datetimes for Rails 5.0.x and ActiveModel.
|
Complete validation of dates, times and datetimes for Rails 5.x and ActiveModel.
|
||||||
|
|
||||||
If you a looking for the old version for Rails 4.x go here [https://github.com/adzap/validates_timeliness/tree/4-0-stable].
|
If you a looking for the old version for Rails 4.x go here [https://github.com/adzap/validates_timeliness/tree/4-0-stable].
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ If you a looking for the old version for Rails 4.x go here [https://github.com/a
|
|||||||
== Installation
|
== Installation
|
||||||
|
|
||||||
# in Gemfile
|
# in Gemfile
|
||||||
gem 'validates_timeliness', '~> 5.0.0.alpha2'
|
gem 'validates_timeliness', '~> 5.0.0.beta1'
|
||||||
|
|
||||||
# Run bundler
|
# Run bundler
|
||||||
$ bundle install
|
$ bundle install
|
||||||
@ -49,21 +49,21 @@ NOTE: You may wish to enable the plugin parser and the extensions to start. Plea
|
|||||||
|
|
||||||
validates_datetime :occurred_at
|
validates_datetime :occurred_at
|
||||||
|
|
||||||
validates_date :date_of_birth, :before => lambda { 18.years.ago },
|
validates_date :date_of_birth, before: lambda { 18.years.ago },
|
||||||
:before_message => "must be at least 18 years old"
|
before_message: "must be at least 18 years old"
|
||||||
|
|
||||||
validates_datetime :finish_time, :after => :start_time # Method symbol
|
validates_datetime :finish_time, after: :start_time # Method symbol
|
||||||
|
|
||||||
validates_date :booked_at, :on => :create, :on_or_after => :today # See Restriction Shorthand.
|
validates_date :booked_at, on: :create, on_or_after: :today # See Restriction Shorthand.
|
||||||
|
|
||||||
validates_time :booked_at, :between => ['9:00am', '5:00pm'] # On or after 9:00AM and on or before 5:00PM
|
validates_time :booked_at, between: ['9:00am', '5:00pm'] # On or after 9:00AM and on or before 5:00PM
|
||||||
validates_time :booked_at, :between => '9:00am'..'5:00pm' # The same as previous example
|
validates_time :booked_at, between: '9:00am'..'5:00pm' # The same as previous example
|
||||||
validates_time :booked_at, :between => '9:00am'...'5:00pm' # On or after 9:00AM and strictly before 5:00PM
|
validates_time :booked_at, between: '9:00am'...'5:00pm' # On or after 9:00AM and strictly before 5:00PM
|
||||||
|
|
||||||
validates_time :breakfast_time, :on_or_after => '6:00am',
|
validates_time :breakfast_time, on_or_after: '6:00am',
|
||||||
:on_or_after_message => 'must be after opening time',
|
on_or_after_message: 'must be after opening time',
|
||||||
:before => :lunchtime,
|
before: :lunchtime,
|
||||||
:before_message => 'must be before lunch time'
|
before_message: 'must be before lunch time'
|
||||||
|
|
||||||
|
|
||||||
== Usage
|
== Usage
|
||||||
@ -72,14 +72,14 @@ To validate a model with a date, time or datetime attribute you just use the
|
|||||||
validation method
|
validation method
|
||||||
|
|
||||||
class Person < ActiveRecord::Base
|
class Person < ActiveRecord::Base
|
||||||
validates_date :date_of_birth, :on_or_before => lambda { Date.current }
|
validates_date :date_of_birth, on_or_before: lambda { Date.current }
|
||||||
# or
|
# or
|
||||||
validates :date_of_birth, :timeliness => {:on_or_before => lambda { Date.current }, :type => :date}
|
validates :date_of_birth, timeliness: {on_or_before: lambda { Date.current }, type: :date}
|
||||||
end
|
end
|
||||||
|
|
||||||
or even on a specific record, per ActiveModel API.
|
or even on a specific record, per ActiveModel API.
|
||||||
|
|
||||||
@person.validates_date :date_of_birth, :on_or_before => lambda { Date.current }
|
@person.validates_date :date_of_birth, on_or_before: lambda { Date.current }
|
||||||
|
|
||||||
|
|
||||||
The list of validation methods available are as follows:
|
The list of validation methods available are as follows:
|
||||||
@ -206,14 +206,14 @@ plugin allows you to use shorthand symbols for often used relative times or date
|
|||||||
|
|
||||||
Just provide the symbol as the option value like so:
|
Just provide the symbol as the option value like so:
|
||||||
|
|
||||||
validates_date :birth_date, :on_or_before => :today
|
validates_date :birth_date, on_or_before: :today
|
||||||
|
|
||||||
The :today symbol is evaluated as <tt>lambda { Date.today }</tt>. The :now and :today
|
The :today symbol is evaluated as <tt>lambda { Date.today }</tt>. The :now and :today
|
||||||
symbols are pre-configured. Configure your own like so:
|
symbols are pre-configured. Configure your own like so:
|
||||||
|
|
||||||
# in the setup block
|
# in the setup block
|
||||||
config.restriction_shorthand_symbols.update(
|
config.restriction_shorthand_symbols.update(
|
||||||
:yesterday => lambda { 1.day.ago }
|
yesterday: lambda { 1.day.ago }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,11 +8,7 @@ gem "rspec-rails", "~> 3.7"
|
|||||||
gem "timecop"
|
gem "timecop"
|
||||||
gem "byebug"
|
gem "byebug"
|
||||||
gem "appraisal"
|
gem "appraisal"
|
||||||
gem "sqlite3"
|
gem "sqlite3", "~> 1.3.6"
|
||||||
gem "nokogiri", "~> 1.8"
|
gem "nokogiri", "~> 1.8"
|
||||||
|
|
||||||
group :active_record do
|
|
||||||
gem "sqlite3-ruby", require: "sqlite3"
|
|
||||||
end
|
|
||||||
|
|
||||||
gemspec path: "../"
|
gemspec path: "../"
|
||||||
|
|||||||
@ -8,11 +8,7 @@ gem "rspec-rails", "~> 3.7"
|
|||||||
gem "timecop"
|
gem "timecop"
|
||||||
gem "byebug"
|
gem "byebug"
|
||||||
gem "appraisal"
|
gem "appraisal"
|
||||||
gem "sqlite3"
|
gem "sqlite3", "~> 1.3.6"
|
||||||
gem "nokogiri", "~> 1.8"
|
gem "nokogiri", "~> 1.8"
|
||||||
|
|
||||||
group :active_record do
|
|
||||||
gem "sqlite3-ruby", require: "sqlite3"
|
|
||||||
end
|
|
||||||
|
|
||||||
gemspec path: "../"
|
gemspec path: "../"
|
||||||
|
|||||||
@ -8,11 +8,7 @@ gem "rspec-rails", "~> 3.7"
|
|||||||
gem "timecop"
|
gem "timecop"
|
||||||
gem "byebug"
|
gem "byebug"
|
||||||
gem "appraisal"
|
gem "appraisal"
|
||||||
gem "sqlite3"
|
gem "sqlite3", "~> 1.3.6"
|
||||||
gem "nokogiri", "~> 1.8"
|
gem "nokogiri", "~> 1.8"
|
||||||
|
|
||||||
group :active_record do
|
|
||||||
gem "sqlite3-ruby", require: "sqlite3"
|
|
||||||
end
|
|
||||||
|
|
||||||
gemspec path: "../"
|
gemspec path: "../"
|
||||||
|
|||||||
@ -36,8 +36,8 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
# Shorthand time and date symbols for restrictions
|
# Shorthand time and date symbols for restrictions
|
||||||
self.restriction_shorthand_symbols = {
|
self.restriction_shorthand_symbols = {
|
||||||
:now => lambda { Time.current },
|
now: proc { Time.current },
|
||||||
:today => lambda { Date.current }
|
today: proc { Date.current }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use the plugin date/time parser which is stricter and extensible
|
# Use the plugin date/time parser which is stricter and extensible
|
||||||
|
|||||||
@ -11,7 +11,7 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ActiveRecord::Base
|
ActiveSupport.on_load(:active_record) do
|
||||||
include ValidatesTimeliness::AttributeMethods
|
include ValidatesTimeliness::AttributeMethods
|
||||||
include ValidatesTimeliness::ORM::ActiveRecord
|
include ValidatesTimeliness::ORM::ActiveRecord
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,5 +11,13 @@ module ValidatesTimeliness
|
|||||||
initializer "validates_timeliness.initialize_restriction_errors" do
|
initializer "validates_timeliness.initialize_restriction_errors" do
|
||||||
ValidatesTimeliness.ignore_restriction_errors = !Rails.env.test?
|
ValidatesTimeliness.ignore_restriction_errors = !Rails.env.test?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
initializer "validates_timeliness.initialize_timeliness_ambiguous_date_format", :after => :load_config_initializers do
|
||||||
|
if Timeliness.respond_to?(:ambiguous_date_format) # i.e. v0.4+
|
||||||
|
# Set default for each new thread if you have changed the default using
|
||||||
|
# the format switching methods.
|
||||||
|
Timeliness.configuration.ambiguous_date_format = Timeliness::Definitions.current_date_format
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
module ValidatesTimeliness
|
module ValidatesTimeliness
|
||||||
VERSION = '5.0.0.alpha2'
|
VERSION = '5.0.0.beta2'
|
||||||
end
|
end
|
||||||
|
|||||||
@ -10,6 +10,8 @@ require 'timecop'
|
|||||||
require 'validates_timeliness'
|
require 'validates_timeliness'
|
||||||
require 'validates_timeliness/orm/active_model'
|
require 'validates_timeliness/orm/active_model'
|
||||||
|
|
||||||
|
require 'rails/railtie'
|
||||||
|
|
||||||
require 'support/test_model'
|
require 'support/test_model'
|
||||||
require 'support/model_helpers'
|
require 'support/model_helpers'
|
||||||
require 'support/config_helper'
|
require 'support/config_helper'
|
||||||
|
|||||||
@ -17,8 +17,7 @@ module ModelHelpers
|
|||||||
|
|
||||||
def with_each_person_value(attr_name, values)
|
def with_each_person_value(attr_name, values)
|
||||||
record = Person.new
|
record = Person.new
|
||||||
values = [values] unless values.is_a?(Array)
|
Array.wrap(values).each do |value|
|
||||||
values.each do |value|
|
|
||||||
record.send("#{attr_name}=", value)
|
record.send("#{attr_name}=", value)
|
||||||
yield record, value
|
yield record, value
|
||||||
end
|
end
|
||||||
|
|||||||
22
spec/validates_timeliness/railtie_spec.rb
Normal file
22
spec/validates_timeliness/railtie_spec.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require 'validates_timeliness/railtie'
|
||||||
|
|
||||||
|
RSpec.describe ValidatesTimeliness::Railtie do
|
||||||
|
context "intializers" do
|
||||||
|
context "validates_timeliness.initialize_timeliness_ambiguous_date_format" do
|
||||||
|
it 'should set the timeliness default ambiguous date format from the current format' do
|
||||||
|
expect(Timeliness.configuration.ambiguous_date_format).to eq :us
|
||||||
|
ValidatesTimeliness.parser.use_euro_formats
|
||||||
|
|
||||||
|
initializer("validates_timeliness.initialize_timeliness_ambiguous_date_format").run
|
||||||
|
|
||||||
|
expect(Timeliness.configuration.ambiguous_date_format).to eq :euro
|
||||||
|
end
|
||||||
|
end if Timeliness.respond_to?(:ambiguous_date_format)
|
||||||
|
|
||||||
|
def initializer(name)
|
||||||
|
ValidatesTimeliness::Railtie.initializers.find { |i|
|
||||||
|
i.name == name
|
||||||
|
} || raise("Initializer #{name} not found")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -17,5 +17,5 @@ Gem::Specification.new do |s|
|
|||||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||||
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
||||||
|
|
||||||
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.8"])
|
s.add_runtime_dependency(%q<timeliness>, [">= 0.3.10", "< 1"])
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user