Compare commits

...

21 Commits

Author SHA1 Message Date
Adam Meehan
16221ac092
Merge pull request #190 from AleBL/patch-1
Update README.rdoc
2020-08-19 10:18:45 +10:00
Alessandro Barros
c0c42edd3f
Update README.rdoc
change to new syntax for keys
2020-08-18 17:56:15 -03:00
Adam Meehan
f8b91e9cea v5.0.0.beta2 2020-07-12 16:26:54 +10:00
Adam Meehan
7fa4d85ee3 Change load_config_initializers to sym in Railtie 2020-07-04 17:07:28 +10:00
Adam Meehan
70307293c6 defaults Rails to 5.2.x 2020-07-04 17:06:39 +10:00
Adam Meehan
f42e905cd1
Merge pull request #189 from VSPPedro/update-readme
readme version bump
2020-06-30 09:33:37 +10:00
Pedro Paiva
35eb50aa40 readme version bump 2020-06-29 19:44:40 -03:00
Adam Meehan
3134072f01 v5.0.0.beta1 2020-01-06 15:48:51 +11:00
Adam Meehan
797ba48036 default rails to 5.1.x 2020-01-06 15:47:34 +11:00
Adam Meehan
f8e6480f58 use ActiveSupport Array.wrap 2019-08-20 10:38:38 -10:00
Adam Meehan
3835b2b161 v5.0.0.alpha5 2019-08-08 10:34:27 +10:00
Adam Meehan
00d038bc6f Merge branch 'master' of github.com:adzap/validates_timeliness 2019-08-06 15:17:34 +10:00
Adam Meehan
a3d0182b5e
Merge pull request #186 from timdiggins/patch-1
Add in v4.1.0 details into Changelog
2019-08-06 14:55:45 +10:00
Adam Meehan
46296f914f ensure timeliness initializer is after initializer files 2019-08-03 12:56:08 +10:00
Adam Meehan
4447361743 hash syntax 2019-08-03 12:38:47 +10:00
Adam Meehan
4523138c3c Add Rails initializer to set Timeliness.ambiguous_date_format for Timeliness v0.4+ 2019-08-03 12:38:39 +10:00
Tim Diggins
72807b87a7
Add in v4.1.0 details into Changelog
v4.1.0 details were only available on the v4.1.0 tag. this brings those back in.
2019-08-01 15:30:42 +01:00
Adam Meehan
9daf12c4a1 README typo of Rails version support 2019-06-14 09:59:39 +10:00
Adam Meehan
2a80683683
Merge pull request #183 from kamille-gz/use_AS_on_load_hook
use ActiveSupport.on_load hook for extend ActiveRecord
2019-03-09 17:16:11 +11:00
kamille-321
3a2882be75 use ActiveSupport on_load hook for extend ActiveRecord 2019-03-09 01:14:08 +09:00
Adam Meehan
bf1c808846 fix appraisals 2019-02-09 12:23:57 +11:00
14 changed files with 67 additions and 41 deletions

View File

@ -8,4 +8,4 @@ end
appraise "rails_5_2" do
gem "rails", "~> 5.2.0"
end
end

View File

@ -3,12 +3,19 @@
* 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
* 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
* 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]
* Fix undefine_generated_methods ivar guard setting to false

View File

@ -2,7 +2,7 @@ source 'http://rubygems.org'
gemspec
gem 'rails', '~> 5.0.0'
gem 'rails', '~> 5.2.4'
gem 'rspec'
gem 'rspec-rails', '~> 3.7'
gem 'timecop'

View File

@ -5,7 +5,7 @@
== 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].
@ -30,7 +30,7 @@ If you a looking for the old version for Rails 4.x go here [https://github.com/a
== Installation
# in Gemfile
gem 'validates_timeliness', '~> 5.0.0.alpha3'
gem 'validates_timeliness', '~> 5.0.0.beta1'
# Run bundler
$ 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_date :date_of_birth, :before => lambda { 18.years.ago },
:before_message => "must be at least 18 years old"
validates_date :date_of_birth, before: lambda { 18.years.ago },
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' # 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 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' # On or after 9:00AM and strictly before 5:00PM
validates_time :breakfast_time, :on_or_after => '6:00am',
:on_or_after_message => 'must be after opening time',
:before => :lunchtime,
:before_message => 'must be before lunch time'
validates_time :breakfast_time, on_or_after: '6:00am',
on_or_after_message: 'must be after opening time',
before: :lunchtime,
before_message: 'must be before lunch time'
== Usage
@ -72,14 +72,14 @@ To validate a model with a date, time or datetime attribute you just use the
validation method
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
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
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:
@ -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:
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
symbols are pre-configured. Configure your own like so:
# in the setup block
config.restriction_shorthand_symbols.update(
:yesterday => lambda { 1.day.ago }
yesterday: lambda { 1.day.ago }
)

View File

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

View File

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

View File

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

View File

@ -36,8 +36,8 @@ module ValidatesTimeliness
# Shorthand time and date symbols for restrictions
self.restriction_shorthand_symbols = {
:now => lambda { Time.current },
:today => lambda { Date.current }
now: proc { Time.current },
today: proc { Date.current }
}
# Use the plugin date/time parser which is stricter and extensible

View File

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

View File

@ -11,5 +11,13 @@ module ValidatesTimeliness
initializer "validates_timeliness.initialize_restriction_errors" do
ValidatesTimeliness.ignore_restriction_errors = !Rails.env.test?
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

View File

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

View File

@ -10,6 +10,8 @@ require 'timecop'
require 'validates_timeliness'
require 'validates_timeliness/orm/active_model'
require 'rails/railtie'
require 'support/test_model'
require 'support/model_helpers'
require 'support/config_helper'

View File

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

View 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