validates_timeliness 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c730e7683c67e1fce0a8a2e0b6dcba331b812e36
4
- data.tar.gz: 904f0cfe44ca9d764e051d1d656cf34cbb6a5dba
3
+ metadata.gz: 1b41249d4d91e9e82bff67e62f186c1c8700588b
4
+ data.tar.gz: 50295e4945b7395cfd05292cb5f89f8f1b203325
5
5
  SHA512:
6
- metadata.gz: fd5326ac226351463fab7d317fadfb96bab6858b0231cfa1ee2b3fb49b974e6aeacf9cff498a22088132cd675d823054db6f0b622ea6db034d0884f0cdfab1e1
7
- data.tar.gz: fe62be44d7d398c17d5762f91335e11187afdd8e2cb3f15e69de95feb8b764b03773f038c009ca72e299a793378ee680e8ea7ebcb62aaec341ef17b02fa1f747
6
+ metadata.gz: 063513f81606e352d5d005600c7a9ca53097cb89ed5ea4359d26e1a58f23049e7223c5f59b9249b7539b11b4742f2b70233b4f5bb2d2d27c9906507542ca0ad5
7
+ data.tar.gz: eba9fbab500ce8ae2b3340f8fa9c461b02e17b68ed3c42405508756e81a07b0360d55292dab2746e9483b8e5295f5d6c3aa108cb88733a604fe443136cf0c937
@@ -7,8 +7,7 @@ gemfile:
7
7
  - gemfiles/rails_4_2.gemfile
8
8
 
9
9
  rvm:
10
- - "2.0.0"
11
- - "2.2.0"
10
+ - "2.2.3"
12
11
  - "2.3.0"
13
12
 
14
13
  script: 'bundle exec rake'
@@ -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.synchronize do
42
- generated_timeliness_methods.module_eval do
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, self.class.timeliness_attribute_type(attr_name), :zone => timezone)
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 |attr_name|
20
- validation_type = _validators[attr_name.to_sym].find {|v| v.kind == :timeliness }.type.to_s
21
- ::ActiveRecord::ConnectionAdapters::Column.new(attr_name, nil, lookup_cast_type(validation_type), validation_type)
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 |attr_name|
35
- validation_type = _validators[attr_name.to_sym].find {|v| v.kind == :timeliness }.type.to_s
36
- ::ActiveRecord::ConnectionAdapters::Column.new(attr_name, nil, validation_type)
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
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '4.0.0'
2
+ VERSION = '4.0.1'
3
3
  end
@@ -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
- require 'spec_helper'
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
- require 'spec_helper'
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.zone.local(2010,1,1,12,0,0))
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
- require 'spec_helper'
2
-
3
- describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
1
+ RSpec.describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
4
2
  include ActionView::Helpers::DateHelper
5
3
  attr_reader :person, :params
6
4
 
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe 'ValidatesTimeliness::Extensions::MultiparameterHandler' do
1
+ RSpec.describe 'ValidatesTimeliness::Extensions::MultiparameterHandler' do
4
2
 
5
3
  context "time column" do
6
4
  it 'should assign a string value for invalid date portion' do
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe ValidatesTimeliness, 'HelperMethods' do
1
+ RSpec.describe ValidatesTimeliness, 'HelperMethods' do
4
2
  let(:record) { Person.new }
5
3
 
6
4
  it 'should define class validation methods' do
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
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
- require 'spec_helper'
2
-
3
- describe ValidatesTimeliness::Validator, ":after option" do
1
+ RSpec.describe ValidatesTimeliness::Validator, ":after option" do
4
2
  describe "for date type" do
5
3
  before do
6
4
  Person.validates_date :birth_date, :after => Date.new(2010, 1, 1)
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe ValidatesTimeliness::Validator, ":before option" do
1
+ RSpec.describe ValidatesTimeliness::Validator, ":before option" do
4
2
  describe "for date type" do
5
3
  before do
6
4
  Person.validates_date :birth_date, :before => Date.new(2010, 1, 1)
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe ValidatesTimeliness::Validator, ":is_at option" do
1
+ RSpec.describe ValidatesTimeliness::Validator, ":is_at option" do
4
2
  before do
5
3
  Timecop.freeze(Time.local(2010, 1, 1, 0, 0, 0))
6
4
  end
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
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
- require 'spec_helper'
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)
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe ValidatesTimeliness::Validator do
1
+ RSpec.describe ValidatesTimeliness::Validator do
4
2
  before do
5
3
  Timecop.freeze(Time.local(2010, 1, 1, 0, 0, 0))
6
4
  end
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe ValidatesTimeliness do
1
+ RSpec.describe ValidatesTimeliness do
4
2
 
5
3
  it 'should alias use_euro_formats to remove_us_formats on Timeliness gem' do
6
4
  expect(Timeliness).to respond_to(:remove_us_formats)
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.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: 2015-12-29 00:00:00.000000000 Z
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