mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Compare commits
64 Commits
v4.0.0
...
4-0-stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3269312ae2 | ||
|
|
d9b81b79a4 | ||
|
|
8a85da19e2 | ||
|
|
f2cd9aca17 | ||
|
|
5354f603ff | ||
|
|
6193410b55 | ||
|
|
93b8b1a70b | ||
|
|
e531c8f8ef | ||
|
|
658deca1c8 | ||
|
|
a6d617e77d | ||
|
|
101bb5d5f7 | ||
|
|
5e6e5222dc | ||
|
|
c81ec5d604 | ||
|
|
f3f3d01db7 | ||
|
|
acd9fc13e4 | ||
|
|
5743d87bc7 | ||
|
|
e0790bca9b | ||
|
|
39f698feb2 | ||
|
|
bd39aef4fb | ||
|
|
a3431bc91a | ||
|
|
fda194584a | ||
|
|
a05f091a42 | ||
|
|
faf708e3be | ||
|
|
38bb74844d | ||
|
|
e275b63203 | ||
|
|
e73e0eb30f | ||
|
|
43554d8bf0 | ||
|
|
da473b7eea | ||
|
|
fc2af73656 | ||
|
|
936c853fdd | ||
|
|
f27324a404 | ||
|
|
4221bf7709 | ||
|
|
b51a4544ff | ||
|
|
285bc769ba | ||
|
|
a0f2759c7a | ||
|
|
cc57b1b758 | ||
|
|
d30cebfc7b | ||
|
|
a96c24268d | ||
|
|
13fcc32a83 | ||
|
|
e8a96fe9b5 | ||
|
|
f9009995fc | ||
|
|
5419a1cc42 | ||
|
|
9dd2e87087 | ||
|
|
8a04deebfa | ||
|
|
e9c9914c4f | ||
|
|
0219c3850d | ||
|
|
35caf3638e | ||
|
|
153051730b | ||
|
|
5c1406e9b0 | ||
|
|
32f92cc885 | ||
|
|
cb3ac8d445 | ||
|
|
4e5f5fa695 | ||
|
|
321834b5ff | ||
|
|
ff131415f7 | ||
|
|
ad43eb31d6 | ||
|
|
0f782a4ed5 | ||
|
|
d57c64dcc2 | ||
|
|
244f398cc4 | ||
|
|
0feeb746cd | ||
|
|
6f23e40c25 | ||
|
|
773e816a4d | ||
|
|
80c9df448d | ||
|
|
54ae49b8a0 | ||
|
|
2fef0a23d6 |
1
.rspec
1
.rspec
@@ -1,3 +1,4 @@
|
||||
--format documentation
|
||||
--color
|
||||
--require spec_helper
|
||||
--require byebug
|
||||
|
||||
23
.travis.yml
23
.travis.yml
@@ -1,17 +1,20 @@
|
||||
language: ruby
|
||||
before_install:
|
||||
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
||||
- gem install bundler -v '< 2'
|
||||
before_script:
|
||||
- bundle install
|
||||
cache: bundler
|
||||
bundler_args: --verbose
|
||||
|
||||
gemfile:
|
||||
- gemfiles/rails_4_0.gemfile
|
||||
- gemfiles/rails_4_1.gemfile
|
||||
- gemfiles/rails_4_2.gemfile
|
||||
matrix:
|
||||
include:
|
||||
- rvm: "2.4.6"
|
||||
gemfile: gemfiles/rails_4_2.gemfile
|
||||
- rvm: "2.5.5"
|
||||
gemfile: gemfiles/rails_4_2.gemfile
|
||||
|
||||
rvm:
|
||||
- "2.0.0"
|
||||
- "2.2.0"
|
||||
- "2.3.0"
|
||||
|
||||
script: 'bundle exec rake'
|
||||
script: 'bundle exec rspec'
|
||||
|
||||
notifications:
|
||||
email:
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
appraise "rails_4_0" do
|
||||
gem "rails", "~> 4.0.0"
|
||||
gem "rails", "~> 4.0.13"
|
||||
end
|
||||
|
||||
appraise "rails_4_1" do
|
||||
gem "rails", "~> 4.1.0"
|
||||
gem "rails", "~> 4.1.14"
|
||||
end
|
||||
|
||||
appraise "rails_4_2" do
|
||||
gem "rails", "~> 4.2.0"
|
||||
end
|
||||
gem "rails", "~> 4.2.11"
|
||||
end
|
||||
|
||||
@@ -1,3 +1,34 @@
|
||||
= 4.1.1 [2019-08-06]
|
||||
* Add initializer to ensure Timeliness default ambigiuous date handling config
|
||||
in Timeliness v0.4.1+ is set correctly when using `use_us_formats` or
|
||||
`use_euro_formats` switcher to set default.
|
||||
* Removed build support for Ruby 2.3 and Rails 4.0 and 4.1 to EOL official
|
||||
support for those.
|
||||
|
||||
= 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
|
||||
|
||||
= 4.0.1 [2016-01-06]
|
||||
* Fix undefine_generated_methods thread locking bug
|
||||
* Created an ActiveModel ORM, for manual require if using without any full blown ORM
|
||||
|
||||
= 4.0.0 [2015-12-29]
|
||||
* Extracted mongoid support into https://github.com/adzap/validates_timeliness-mongoid which is broken (not supported anymore).
|
||||
* Fixed Rails 4.0, 4.1 and 4.2 compatability issues
|
||||
* Upgrade specs to RSpec 3
|
||||
* Added travis config
|
||||
* Huge thanks to @johncarney for keeping it alive with his fork (https://github.com/johncarney/validates_timeliness)
|
||||
|
||||
= 3.0.15 [2015-12-29]
|
||||
* Fixes mongoid 3 support and removes mongoid 2 support(johnnyshields)
|
||||
* Some documentation/comments tidying
|
||||
* Some general tidying up
|
||||
|
||||
= 3.0.14 [2012-08-23]
|
||||
* Fix for using validates :timeliness => {} form to correctly add attributes to timeliness validated attributes.
|
||||
|
||||
|
||||
17
Gemfile
17
Gemfile
@@ -1,16 +1,13 @@
|
||||
source 'http://rubygems.org'
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gemspec
|
||||
|
||||
gem 'rails', '~> 4.0.13'
|
||||
gem 'rspec', '~> 3.0.0'
|
||||
gem 'rspec-rails', '~> 3.0.0'
|
||||
gem 'rake'
|
||||
gem 'rails', '~> 4.2.11.1'
|
||||
gem 'rspec'
|
||||
gem 'rspec-rails', '~> 3.7'
|
||||
gem 'timecop'
|
||||
gem 'byebug'
|
||||
gem 'appraisal'
|
||||
gem 'sqlite3'
|
||||
gem 'nokogiri', '1.6.7'
|
||||
|
||||
group :active_record do
|
||||
gem 'sqlite3-ruby', :require => 'sqlite3'
|
||||
end
|
||||
gem 'sqlite3', '~> 1.3.13'
|
||||
gem 'nokogiri', '~> 1.8'
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
== Description
|
||||
|
||||
Complete validation of dates, times and datetimes for Rails 4.x and ActiveModel.
|
||||
Complete validation of dates, times and datetimes for Rails 4.2.x and ActiveModel. Rails 4.0.x and 4.1.x may
|
||||
still work but official support has ended.
|
||||
|
||||
If you a looking for the old version for Rails 3.x go here[http://github.com/adzap/validates_timeliness/tree/v3.x].
|
||||
|
||||
@@ -22,7 +23,7 @@ If you a looking for the old version for Rails 3.x go here[http://github.com/adz
|
||||
|
||||
* Adds extensions to fix Rails date/time select issues (See Extensions)
|
||||
|
||||
* Supports I18n for the error messages
|
||||
* Supports I18n for the error messages. For multi-language support try {timeliness-i18n gem}[https://github.com/pedrofurtado/timeliness-i18n].
|
||||
|
||||
* Supports all the Rubies (that any sane person would be using in production).
|
||||
|
||||
@@ -30,7 +31,7 @@ If you a looking for the old version for Rails 3.x go here[http://github.com/adz
|
||||
== Installation
|
||||
|
||||
# in Gemfile
|
||||
gem 'validates_timeliness', '~> 4.0'
|
||||
gem 'validates_timeliness', '~> 4.1'
|
||||
|
||||
# Run bundler
|
||||
$ bundle install
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# This file was generated by Appraisal
|
||||
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "rails", "~> 4.0.0"
|
||||
gem "rspec", "~> 3.0.0"
|
||||
gem "rspec-rails", "~> 3.0.0"
|
||||
gem "timecop"
|
||||
gem "rspec_tag_matchers"
|
||||
gem "byebug"
|
||||
gem "appraisal"
|
||||
gem "sqlite3"
|
||||
gem "nokogiri", "1.6.7"
|
||||
|
||||
group :active_record do
|
||||
gem "sqlite3-ruby", :require => "sqlite3"
|
||||
end
|
||||
|
||||
gemspec :path => "../"
|
||||
@@ -1,19 +0,0 @@
|
||||
# This file was generated by Appraisal
|
||||
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "rails", "~> 4.1.0"
|
||||
gem "rspec", "~> 3.0.0"
|
||||
gem "rspec-rails", "~> 3.0.0"
|
||||
gem "timecop"
|
||||
gem "rspec_tag_matchers"
|
||||
gem "byebug"
|
||||
gem "appraisal"
|
||||
gem "sqlite3"
|
||||
gem "nokogiri", "1.6.7"
|
||||
|
||||
group :active_record do
|
||||
gem "sqlite3-ruby", :require => "sqlite3"
|
||||
end
|
||||
|
||||
gemspec :path => "../"
|
||||
@@ -1,19 +1,14 @@
|
||||
# This file was generated by Appraisal
|
||||
|
||||
source "http://rubygems.org"
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", "~> 4.2.0"
|
||||
gem "rspec", "~> 3.0.0"
|
||||
gem "rspec-rails", "~> 3.0.0"
|
||||
gem "rails", "~> 4.2.8"
|
||||
gem "rspec", "~> 3.6.0"
|
||||
gem "rspec-rails", "~> 3.6.0"
|
||||
gem "timecop"
|
||||
gem "rspec_tag_matchers"
|
||||
gem "byebug"
|
||||
gem "appraisal"
|
||||
gem "sqlite3"
|
||||
gem "sqlite3", "~> 1.3.0"
|
||||
gem "nokogiri", "1.6.7"
|
||||
|
||||
group :active_record do
|
||||
gem "sqlite3-ruby", :require => "sqlite3"
|
||||
end
|
||||
|
||||
gemspec :path => "../"
|
||||
gemspec path: "../"
|
||||
|
||||
@@ -33,15 +33,9 @@ module ValidatesTimeliness
|
||||
}.tap { |mod| include mod }
|
||||
end
|
||||
|
||||
def undefine_attribute_methods
|
||||
super.tap { undefine_timeliness_attribute_methods }
|
||||
end
|
||||
|
||||
def undefine_timeliness_attribute_methods
|
||||
generated_timeliness_methods.synchronize do
|
||||
generated_timeliness_methods.module_eval do
|
||||
instance_methods.each { |m| undef_method(m) }
|
||||
end
|
||||
generated_timeliness_methods.module_eval do
|
||||
instance_methods.each { |m| undef_method(m) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,8 +68,10 @@ module ValidatesTimeliness
|
||||
@timeliness_cache[attr_name] = value
|
||||
|
||||
if ValidatesTimeliness.use_plugin_parser
|
||||
type = self.class.timeliness_attribute_type(attr_name)
|
||||
timezone = :current if self.class.timeliness_attribute_timezone_aware?(attr_name)
|
||||
value = Timeliness::Parser.parse(value, self.class.timeliness_attribute_type(attr_name), :zone => timezone)
|
||||
value = Timeliness::Parser.parse(value, type, :zone => timezone)
|
||||
value = value.to_date if value && type == :date
|
||||
end
|
||||
|
||||
@attributes[attr_name] = value
|
||||
|
||||
@@ -12,6 +12,8 @@ module ValidatesTimeliness
|
||||
value.to_date
|
||||
when :datetime
|
||||
value.is_a?(Time) ? value : value.to_time
|
||||
else
|
||||
value
|
||||
end
|
||||
if options[:ignore_usec] && value.is_a?(Time)
|
||||
Timeliness::Parser.make_time(Array(value).reverse[4..9], (:current if @timezone_aware))
|
||||
|
||||
20
lib/validates_timeliness/orm/active_model.rb
Normal file
20
lib/validates_timeliness/orm/active_model.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module ValidatesTimeliness
|
||||
module ORM
|
||||
module ActiveModel
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
public
|
||||
|
||||
def define_attribute_methods(*attr_names)
|
||||
super.tap { define_timeliness_methods}
|
||||
end
|
||||
|
||||
def undefine_attribute_methods
|
||||
super.tap { undefine_timeliness_attribute_methods }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -14,26 +14,26 @@ module ValidatesTimeliness
|
||||
timeliness_column_for_attribute(attr_name).type
|
||||
end
|
||||
|
||||
if ActiveModel.version >= Gem::Version.new('4.2')
|
||||
if ::ActiveModel.version >= Gem::Version.new('4.2')
|
||||
def timeliness_column_for_attribute(attr_name)
|
||||
columns_hash.fetch(attr_name.to_s) do |attr_name|
|
||||
validation_type = _validators[attr_name.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
||||
::ActiveRecord::ConnectionAdapters::Column.new(attr_name, nil, lookup_cast_type(validation_type), validation_type)
|
||||
columns_hash.fetch(attr_name.to_s) do |key|
|
||||
validation_type = _validators[key.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
||||
::ActiveRecord::ConnectionAdapters::Column.new(key, nil, lookup_cast_type(validation_type), validation_type)
|
||||
end
|
||||
end
|
||||
|
||||
def lookup_cast_type(sql_type)
|
||||
case sql_type
|
||||
when 'datetime' then ::ActiveRecord::Type::DateTime.new
|
||||
when 'date' then ::ActiveRecord::Type::Date.new
|
||||
when 'time' then ::ActiveRecord::Type::Time.new
|
||||
when 'datetime' then ::ActiveRecord::Type::DateTime.new
|
||||
when 'date' then ::ActiveRecord::Type::Date.new
|
||||
when 'time' then ::ActiveRecord::Type::Time.new
|
||||
end
|
||||
end
|
||||
else
|
||||
def timeliness_column_for_attribute(attr_name)
|
||||
columns_hash.fetch(attr_name.to_s) do |attr_name|
|
||||
validation_type = _validators[attr_name.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
||||
::ActiveRecord::ConnectionAdapters::Column.new(attr_name, nil, validation_type)
|
||||
columns_hash.fetch(attr_name.to_s) do |key|
|
||||
validation_type = _validators[key.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
||||
::ActiveRecord::ConnectionAdapters::Column.new(key, nil, validation_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -53,7 +53,7 @@ module ValidatesTimeliness
|
||||
generated_timeliness_methods.synchronize do
|
||||
return unless @timeliness_methods_generated
|
||||
undefine_timeliness_attribute_methods
|
||||
@timeliness_methods_generated = true
|
||||
@timeliness_methods_generated = false
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -56,7 +56,7 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
# Rails 4.0 compatibility for old #setup method with class as arg
|
||||
if ActiveModel.version <= Gem::Version.new('4.1')
|
||||
if Gem::Version.new(ActiveModel::VERSION::STRING) <= Gem::Version.new('4.1')
|
||||
alias_method(:setup, :setup_timeliness_validated_attributes)
|
||||
end
|
||||
|
||||
@@ -91,7 +91,7 @@ module ValidatesTimeliness
|
||||
|
||||
def add_error(record, attr_name, message, value=nil)
|
||||
value = format_error_value(value) if value
|
||||
message_options = { :message => options[:"#{message}_message"], :restriction => value }
|
||||
message_options = { :message => options.fetch(:"#{message}_message", options[:message]), :restriction => value }
|
||||
record.errors.add(attr_name, message, message_options)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module ValidatesTimeliness
|
||||
VERSION = '4.0.0'
|
||||
VERSION = '4.1.1'
|
||||
end
|
||||
|
||||
@@ -7,6 +7,9 @@ require 'action_view'
|
||||
require 'timecop'
|
||||
|
||||
require 'validates_timeliness'
|
||||
require 'validates_timeliness/orm/active_model'
|
||||
|
||||
require 'rails/railtie'
|
||||
|
||||
require 'support/test_model'
|
||||
require 'support/model_helpers'
|
||||
@@ -30,14 +33,9 @@ I18n.available_locales = ['en', 'es']
|
||||
module TestModelShim
|
||||
extend ActiveSupport::Concern
|
||||
include ValidatesTimeliness::AttributeMethods
|
||||
include ValidatesTimeliness::ORM::ActiveModel
|
||||
|
||||
module ClassMethods
|
||||
# Hook method for attribute method generation
|
||||
def define_attribute_methods(attr_names)
|
||||
super
|
||||
define_timeliness_methods
|
||||
end
|
||||
|
||||
# Hook into native time zone handling check, if any
|
||||
def timeliness_attribute_timezone_aware?(attr_name)
|
||||
false
|
||||
@@ -75,8 +73,8 @@ end
|
||||
class Employee < ActiveRecord::Base
|
||||
attr_accessor :redefined_birth_date_called
|
||||
validates_date :birth_date, :allow_nil => true
|
||||
validates_date :birth_time, :allow_nil => true
|
||||
validates_date :birth_datetime, :allow_nil => true
|
||||
validates_time :birth_time, :allow_nil => true
|
||||
validates_datetime :birth_datetime, :allow_nil => true
|
||||
|
||||
def birth_date=(value)
|
||||
self.redefined_birth_date_called = true
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::AttributeMethods do
|
||||
RSpec.describe ValidatesTimeliness::AttributeMethods do
|
||||
it 'should define read_timeliness_attribute_before_type_cast instance method' do
|
||||
expect(PersonWithShim.new).to respond_to(:read_timeliness_attribute_before_type_cast)
|
||||
end
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Conversion do
|
||||
RSpec.describe ValidatesTimeliness::Conversion do
|
||||
include ValidatesTimeliness::Conversion
|
||||
|
||||
let(:options) { Hash.new }
|
||||
@@ -176,7 +174,7 @@ describe ValidatesTimeliness::Conversion do
|
||||
it 'should return Time value for attribute method symbol which returns string time value' do
|
||||
value = '2010-01-01 12:00:00'
|
||||
person.birth_time = value
|
||||
expect(evaluate_option_value(:birth_time, person)).to eq(Time.zone.local(2010,1,1,12,0,0))
|
||||
expect(evaluate_option_value(:birth_time, person)).to eq(Time.local(2010,1,1,12,0,0))
|
||||
end
|
||||
|
||||
context "restriction shorthand" do
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
||||
RSpec.describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
||||
include ActionView::Helpers::DateHelper
|
||||
attr_reader :person, :params
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'ValidatesTimeliness::Extensions::MultiparameterHandler' do
|
||||
RSpec.describe 'ValidatesTimeliness::Extensions::MultiparameterHandler' do
|
||||
|
||||
context "time column" do
|
||||
it 'should assign a string value for invalid date portion' do
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness, 'HelperMethods' do
|
||||
RSpec.describe ValidatesTimeliness, 'HelperMethods' do
|
||||
let(:record) { Person.new }
|
||||
|
||||
it 'should define class validation methods' do
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness, 'ActiveRecord' do
|
||||
RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
||||
|
||||
context "validation methods" do
|
||||
let(:record) { Employee.new }
|
||||
@@ -241,4 +239,16 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
||||
expect(Employee.define_attribute_methods).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context "undefine_attribute_methods" do
|
||||
it "returns remove attribute methods that have already been generated" do
|
||||
Employee.define_attribute_methods
|
||||
|
||||
expect(Employee.instance_methods).to include(:birth_datetime)
|
||||
|
||||
Employee.undefine_attribute_methods
|
||||
|
||||
expect(Employee.instance_methods).to_not include(:birth_datetime)
|
||||
end
|
||||
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
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":after option" do
|
||||
RSpec.describe ValidatesTimeliness::Validator, ":after option" do
|
||||
describe "for date type" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :after => Date.new(2010, 1, 1)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":before option" do
|
||||
RSpec.describe ValidatesTimeliness::Validator, ":before option" do
|
||||
describe "for date type" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :before => Date.new(2010, 1, 1)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":is_at option" do
|
||||
RSpec.describe ValidatesTimeliness::Validator, ":is_at option" do
|
||||
before do
|
||||
Timecop.freeze(Time.local(2010, 1, 1, 0, 0, 0))
|
||||
end
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":on_or_after option" do
|
||||
RSpec.describe ValidatesTimeliness::Validator, ":on_or_after option" do
|
||||
describe "for date type" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :on_or_after => Date.new(2010, 1, 1)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":on_or_before option" do
|
||||
RSpec.describe ValidatesTimeliness::Validator, ":on_or_before option" do
|
||||
describe "for date type" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :on_or_before => Date.new(2010, 1, 1)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator do
|
||||
RSpec.describe ValidatesTimeliness::Validator do
|
||||
before do
|
||||
Timecop.freeze(Time.local(2010, 1, 1, 0, 0, 0))
|
||||
end
|
||||
@@ -89,6 +87,20 @@ describe ValidatesTimeliness::Validator do
|
||||
end
|
||||
end
|
||||
|
||||
describe ':message options' do
|
||||
it 'should allow message option too' do
|
||||
Person.validates_date :birth_date, on_or_after: :today, message: 'cannot be in past'
|
||||
invalid!(:birth_date, Date.today - 5.days, 'cannot be in past')
|
||||
valid!(:birth_date, Date.today)
|
||||
end
|
||||
|
||||
it 'should first allow the defined message' do
|
||||
Person.validates_date :birth_date, on_or_after: :today, on_or_after_message: 'cannot be in past', message: 'dummy message'
|
||||
invalid!(:birth_date, Date.today - 5.days, 'cannot be in past')
|
||||
valid!(:birth_date, Date.today)
|
||||
end
|
||||
end
|
||||
|
||||
describe ":between option" do
|
||||
describe "array value" do
|
||||
it 'should be split option into :on_or_after and :on_or_before values' do
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness do
|
||||
RSpec.describe ValidatesTimeliness do
|
||||
|
||||
it 'should alias use_euro_formats to remove_us_formats on Timeliness gem' do
|
||||
expect(Timeliness).to respond_to(:remove_us_formats)
|
||||
|
||||
@@ -10,11 +10,12 @@ Gem::Specification.new do |s|
|
||||
s.description = %q{Adds validation methods to ActiveModel for validating dates and times. Works with multiple ORMS.}
|
||||
s.email = %q{adam.meehan@gmail.com}
|
||||
s.homepage = %q{http://github.com/adzap/validates_timeliness}
|
||||
s.license = "MIT"
|
||||
|
||||
s.require_paths = ["lib"]
|
||||
s.files = `git ls-files`.split("\n") - %w{ .gitignore .rspec Gemfile Gemfile.lock autotest/discover.rb Appraisals Travis.yml } - Dir['gemsfiles/*']
|
||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
||||
|
||||
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.7"])
|
||||
s.add_runtime_dependency(%q<timeliness>, [">= 0.3.10", "< 1"])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user