validates_timeliness 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/CHANGELOG.rdoc +12 -0
- data/lib/validates_timeliness/attribute_methods.rb +5 -9
- data/lib/validates_timeliness/conversion.rb +2 -0
- data/lib/validates_timeliness/orm/active_model.rb +20 -0
- data/lib/validates_timeliness/orm/active_record.rb +10 -10
- data/lib/validates_timeliness/version.rb +1 -1
- data/spec/spec_helper.rb +2 -6
- data/spec/validates_timeliness/attribute_methods_spec.rb +1 -3
- data/spec/validates_timeliness/conversion_spec.rb +2 -4
- data/spec/validates_timeliness/extensions/date_time_select_spec.rb +1 -3
- data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +1 -3
- data/spec/validates_timeliness/helper_methods_spec.rb +1 -3
- data/spec/validates_timeliness/orm/active_record_spec.rb +7 -3
- data/spec/validates_timeliness/validator/after_spec.rb +1 -3
- data/spec/validates_timeliness/validator/before_spec.rb +1 -3
- data/spec/validates_timeliness/validator/is_at_spec.rb +1 -3
- data/spec/validates_timeliness/validator/on_or_after_spec.rb +1 -3
- data/spec/validates_timeliness/validator/on_or_before_spec.rb +1 -3
- data/spec/validates_timeliness/validator_spec.rb +1 -3
- data/spec/validates_timeliness_spec.rb +1 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b41249d4d91e9e82bff67e62f186c1c8700588b
|
4
|
+
data.tar.gz: 50295e4945b7395cfd05292cb5f89f8f1b203325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063513f81606e352d5d005600c7a9ca53097cb89ed5ea4359d26e1a58f23049e7223c5f59b9249b7539b11b4742f2b70233b4f5bb2d2d27c9906507542ca0ad5
|
7
|
+
data.tar.gz: eba9fbab500ce8ae2b3340f8fa9c461b02e17b68ed3c42405508756e81a07b0360d55292dab2746e9483b8e5295f5d6c3aa108cb88733a604fe443136cf0c937
|
data/.travis.yml
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
= 4.0.0 [2015-12-29]
|
2
|
+
* Extracted mongoid support into https://github.com/adzap/validates_timeliness-mongoid which is broken (not supported anymore).
|
3
|
+
* Fixed Rails 4.0, 4.1 and 4.2 compatability issues
|
4
|
+
* Upgrade specs to RSpec 3
|
5
|
+
* Added travis config
|
6
|
+
* Huge thanks to @johncarney for keeping it alive with his fork (https://github.com/johncarney/validates_timeliness)
|
7
|
+
|
8
|
+
= 3.0.15 [2015-12-29]
|
9
|
+
* Fixes mongoid 3 support and removes mongoid 2 support(johnnyshields)
|
10
|
+
* Some documentation/comments tidying
|
11
|
+
* Some general tidying up
|
12
|
+
|
1
13
|
= 3.0.14 [2012-08-23]
|
2
14
|
* Fix for using validates :timeliness => {} form to correctly add attributes to timeliness validated attributes.
|
3
15
|
|
@@ -33,15 +33,9 @@ module ValidatesTimeliness
|
|
33
33
|
}.tap { |mod| include mod }
|
34
34
|
end
|
35
35
|
|
36
|
-
def undefine_attribute_methods
|
37
|
-
super.tap { undefine_timeliness_attribute_methods }
|
38
|
-
end
|
39
|
-
|
40
36
|
def undefine_timeliness_attribute_methods
|
41
|
-
generated_timeliness_methods.
|
42
|
-
|
43
|
-
instance_methods.each { |m| undef_method(m) }
|
44
|
-
end
|
37
|
+
generated_timeliness_methods.module_eval do
|
38
|
+
instance_methods.each { |m| undef_method(m) }
|
45
39
|
end
|
46
40
|
end
|
47
41
|
|
@@ -74,8 +68,10 @@ module ValidatesTimeliness
|
|
74
68
|
@timeliness_cache[attr_name] = value
|
75
69
|
|
76
70
|
if ValidatesTimeliness.use_plugin_parser
|
71
|
+
type = self.class.timeliness_attribute_type(attr_name)
|
77
72
|
timezone = :current if self.class.timeliness_attribute_timezone_aware?(attr_name)
|
78
|
-
value = Timeliness::Parser.parse(value,
|
73
|
+
value = Timeliness::Parser.parse(value, type, :zone => timezone)
|
74
|
+
value = value.to_date if value && type == :date
|
79
75
|
end
|
80
76
|
|
81
77
|
@attributes[attr_name] = value
|
@@ -12,6 +12,8 @@ module ValidatesTimeliness
|
|
12
12
|
value.to_date
|
13
13
|
when :datetime
|
14
14
|
value.is_a?(Time) ? value : value.to_time
|
15
|
+
else
|
16
|
+
value
|
15
17
|
end
|
16
18
|
if options[:ignore_usec] && value.is_a?(Time)
|
17
19
|
Timeliness::Parser.make_time(Array(value).reverse[4..9], (:current if @timezone_aware))
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ValidatesTimeliness
|
2
|
+
module ORM
|
3
|
+
module ActiveModel
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
public
|
8
|
+
|
9
|
+
def define_attribute_methods(*attr_names)
|
10
|
+
super.tap { define_timeliness_methods}
|
11
|
+
end
|
12
|
+
|
13
|
+
def undefine_attribute_methods
|
14
|
+
super.tap { undefine_timeliness_attribute_methods }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -14,26 +14,26 @@ module ValidatesTimeliness
|
|
14
14
|
timeliness_column_for_attribute(attr_name).type
|
15
15
|
end
|
16
16
|
|
17
|
-
if ActiveModel.version >= Gem::Version.new('4.2')
|
17
|
+
if ::ActiveModel.version >= Gem::Version.new('4.2')
|
18
18
|
def timeliness_column_for_attribute(attr_name)
|
19
|
-
columns_hash.fetch(attr_name.to_s) do |
|
20
|
-
validation_type = _validators[
|
21
|
-
::ActiveRecord::ConnectionAdapters::Column.new(
|
19
|
+
columns_hash.fetch(attr_name.to_s) do |key|
|
20
|
+
validation_type = _validators[key.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
21
|
+
::ActiveRecord::ConnectionAdapters::Column.new(key, nil, lookup_cast_type(validation_type), validation_type)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def lookup_cast_type(sql_type)
|
26
26
|
case sql_type
|
27
|
-
when 'datetime' then ::ActiveRecord::Type::DateTime.new
|
28
|
-
when 'date' then ::ActiveRecord::Type::Date.new
|
29
|
-
when 'time' then ::ActiveRecord::Type::Time.new
|
27
|
+
when 'datetime' then ::ActiveRecord::Type::DateTime.new
|
28
|
+
when 'date' then ::ActiveRecord::Type::Date.new
|
29
|
+
when 'time' then ::ActiveRecord::Type::Time.new
|
30
30
|
end
|
31
31
|
end
|
32
32
|
else
|
33
33
|
def timeliness_column_for_attribute(attr_name)
|
34
|
-
columns_hash.fetch(attr_name.to_s) do |
|
35
|
-
validation_type = _validators[
|
36
|
-
::ActiveRecord::ConnectionAdapters::Column.new(
|
34
|
+
columns_hash.fetch(attr_name.to_s) do |key|
|
35
|
+
validation_type = _validators[key.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
36
|
+
::ActiveRecord::ConnectionAdapters::Column.new(key, nil, validation_type)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,7 @@ require 'action_view'
|
|
7
7
|
require 'timecop'
|
8
8
|
|
9
9
|
require 'validates_timeliness'
|
10
|
+
require 'validates_timeliness/orm/active_model'
|
10
11
|
|
11
12
|
require 'support/test_model'
|
12
13
|
require 'support/model_helpers'
|
@@ -30,14 +31,9 @@ I18n.available_locales = ['en', 'es']
|
|
30
31
|
module TestModelShim
|
31
32
|
extend ActiveSupport::Concern
|
32
33
|
include ValidatesTimeliness::AttributeMethods
|
34
|
+
include ValidatesTimeliness::ORM::ActiveModel
|
33
35
|
|
34
36
|
module ClassMethods
|
35
|
-
# Hook method for attribute method generation
|
36
|
-
def define_attribute_methods(attr_names)
|
37
|
-
super
|
38
|
-
define_timeliness_methods
|
39
|
-
end
|
40
|
-
|
41
37
|
# Hook into native time zone handling check, if any
|
42
38
|
def timeliness_attribute_timezone_aware?(attr_name)
|
43
39
|
false
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe ValidatesTimeliness::AttributeMethods do
|
1
|
+
RSpec.describe ValidatesTimeliness::AttributeMethods do
|
4
2
|
it 'should define read_timeliness_attribute_before_type_cast instance method' do
|
5
3
|
expect(PersonWithShim.new).to respond_to(:read_timeliness_attribute_before_type_cast)
|
6
4
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe ValidatesTimeliness::Conversion do
|
1
|
+
RSpec.describe ValidatesTimeliness::Conversion do
|
4
2
|
include ValidatesTimeliness::Conversion
|
5
3
|
|
6
4
|
let(:options) { Hash.new }
|
@@ -176,7 +174,7 @@ describe ValidatesTimeliness::Conversion do
|
|
176
174
|
it 'should return Time value for attribute method symbol which returns string time value' do
|
177
175
|
value = '2010-01-01 12:00:00'
|
178
176
|
person.birth_time = value
|
179
|
-
expect(evaluate_option_value(:birth_time, person)).to eq(Time.
|
177
|
+
expect(evaluate_option_value(:birth_time, person)).to eq(Time.local(2010,1,1,12,0,0))
|
180
178
|
end
|
181
179
|
|
182
180
|
context "restriction shorthand" do
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe ValidatesTimeliness, 'ActiveRecord' do
|
1
|
+
RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
4
2
|
|
5
3
|
context "validation methods" do
|
6
4
|
let(:record) { Employee.new }
|
@@ -241,4 +239,10 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
|
241
239
|
expect(Employee.define_attribute_methods).to be_falsey
|
242
240
|
end
|
243
241
|
end
|
242
|
+
|
243
|
+
context "undefine_attribute_methods" do
|
244
|
+
it "returns a falsy value if the attribute methods have already been generated" do
|
245
|
+
expect { Employee.undefine_attribute_methods }.to_not raise_error
|
246
|
+
end
|
247
|
+
end
|
244
248
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe ValidatesTimeliness::Validator, ":on_or_after option" do
|
1
|
+
RSpec.describe ValidatesTimeliness::Validator, ":on_or_after option" do
|
4
2
|
describe "for date type" do
|
5
3
|
before do
|
6
4
|
Person.validates_date :birth_date, :on_or_after => Date.new(2010, 1, 1)
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe ValidatesTimeliness::Validator, ":on_or_before option" do
|
1
|
+
RSpec.describe ValidatesTimeliness::Validator, ":on_or_before option" do
|
4
2
|
describe "for date type" do
|
5
3
|
before do
|
6
4
|
Person.validates_date :birth_date, :on_or_before => Date.new(2010, 1, 1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_timeliness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: timeliness
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/validates_timeliness/extensions/date_time_select.rb
|
54
54
|
- lib/validates_timeliness/extensions/multiparameter_handler.rb
|
55
55
|
- lib/validates_timeliness/helper_methods.rb
|
56
|
+
- lib/validates_timeliness/orm/active_model.rb
|
56
57
|
- lib/validates_timeliness/orm/active_record.rb
|
57
58
|
- lib/validates_timeliness/railtie.rb
|
58
59
|
- lib/validates_timeliness/validator.rb
|