Compare commits

..

No commits in common. "master" and "v5.0.0.alpha2" have entirely different histories.

16 changed files with 44 additions and 73 deletions

View File

@ -8,7 +8,7 @@ gemfile:
- gemfiles/rails_5_2.gemfile - gemfiles/rails_5_2.gemfile
rvm: rvm:
- "2.5.3" - "2.5.1"
script: 'bundle exec rspec' script: 'bundle exec rspec'

View File

@ -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

View File

@ -1,21 +1,11 @@
= [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

View File

@ -2,11 +2,11 @@ source 'http://rubygems.org'
gemspec gemspec
gem 'rails', '~> 5.2.4' gem 'rails', '~> 5.0.0'
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', '~> 1.3.6' gem 'sqlite3'
gem 'nokogiri', '~> 1.8' gem 'nokogiri', '~> 1.8'

View File

@ -5,7 +5,7 @@
== Description == Description
Complete validation of dates, times and datetimes for Rails 5.x and ActiveModel. Complete validation of dates, times and datetimes for Rails 5.0.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.beta1' gem 'validates_timeliness', '~> 5.0.0.alpha2'
# 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 }
) )

View File

@ -8,7 +8,11 @@ gem "rspec-rails", "~> 3.7"
gem "timecop" gem "timecop"
gem "byebug" gem "byebug"
gem "appraisal" gem "appraisal"
gem "sqlite3", "~> 1.3.6" gem "sqlite3"
gem "nokogiri", "~> 1.8" gem "nokogiri", "~> 1.8"
group :active_record do
gem "sqlite3-ruby", require: "sqlite3"
end
gemspec path: "../" gemspec path: "../"

View File

@ -8,7 +8,11 @@ gem "rspec-rails", "~> 3.7"
gem "timecop" gem "timecop"
gem "byebug" gem "byebug"
gem "appraisal" gem "appraisal"
gem "sqlite3", "~> 1.3.6" gem "sqlite3"
gem "nokogiri", "~> 1.8" gem "nokogiri", "~> 1.8"
group :active_record do
gem "sqlite3-ruby", require: "sqlite3"
end
gemspec path: "../" gemspec path: "../"

View File

@ -8,7 +8,11 @@ gem "rspec-rails", "~> 3.7"
gem "timecop" gem "timecop"
gem "byebug" gem "byebug"
gem "appraisal" gem "appraisal"
gem "sqlite3", "~> 1.3.6" gem "sqlite3"
gem "nokogiri", "~> 1.8" gem "nokogiri", "~> 1.8"
group :active_record do
gem "sqlite3-ruby", require: "sqlite3"
end
gemspec path: "../" gemspec path: "../"

View File

@ -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: proc { Time.current }, :now => lambda { Time.current },
today: proc { Date.current } :today => lambda { Date.current }
} }
# Use the plugin date/time parser which is stricter and extensible # Use the plugin date/time parser which is stricter and extensible

View File

@ -11,7 +11,7 @@ module ValidatesTimeliness
end end
end end
ActiveSupport.on_load(:active_record) do class ActiveRecord::Base
include ValidatesTimeliness::AttributeMethods include ValidatesTimeliness::AttributeMethods
include ValidatesTimeliness::ORM::ActiveRecord include ValidatesTimeliness::ORM::ActiveRecord
end end

View File

@ -11,13 +11,5 @@ 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

View File

@ -1,3 +1,3 @@
module ValidatesTimeliness module ValidatesTimeliness
VERSION = '5.0.0.beta2' VERSION = '5.0.0.alpha2'
end end

View File

@ -10,8 +10,6 @@ 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'

View File

@ -17,7 +17,8 @@ module ModelHelpers
def with_each_person_value(attr_name, values) def with_each_person_value(attr_name, values)
record = Person.new record = Person.new
Array.wrap(values).each do |value| values = [values] unless values.is_a?(Array)
values.each do |value|
record.send("#{attr_name}=", value) record.send("#{attr_name}=", value)
yield record, value yield record, value
end end

View File

@ -1,22 +0,0 @@
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

View File

@ -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.10", "< 1"]) s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.8"])
end end