From 4a904c0bf642df2e4b8d35df8e58bed78ed9b486 Mon Sep 17 00:00:00 2001 From: Jonathan Geisler Date: Thu, 15 Jan 2015 21:16:48 -0500 Subject: [PATCH 1/3] Update validator for Rails 4.2 The validators in Rails 4.1 deprecated the Validator#setup method and suggested putting it as part of the initializer. In Rails 4.2, the method is fully removed. This commit simply follows the instructions given by the deprecation text. --- lib/validates_timeliness/validator.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/validates_timeliness/validator.rb b/lib/validates_timeliness/validator.rb index 806dbe2b..5fc25788 100644 --- a/lib/validates_timeliness/validator.rb +++ b/lib/validates_timeliness/validator.rb @@ -43,9 +43,7 @@ def initialize(options) @restrictions_to_check = RESTRICTIONS.keys & options.keys super - end - def setup(model) if model.respond_to?(:timeliness_validated_attributes) model.timeliness_validated_attributes ||= [] model.timeliness_validated_attributes |= @attributes From c386e3daec051e27766ec097c9405309f63edab8 Mon Sep 17 00:00:00 2001 From: Jonathan Geisler Date: Thu, 15 Jan 2015 21:35:34 -0500 Subject: [PATCH 2/3] Fix syntax error with previous fix. The previous fix wasn't tested because I was pulling from github and so didn't realize that the model parameter from the old method was being used. This is based on the code in github.com/johncarney/validates_timeliness and is just as tested as the last commit. Will keep updating until it works properly. --- lib/validates_timeliness/validator.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/validates_timeliness/validator.rb b/lib/validates_timeliness/validator.rb index 5fc25788..289f86ec 100644 --- a/lib/validates_timeliness/validator.rb +++ b/lib/validates_timeliness/validator.rb @@ -43,7 +43,10 @@ def initialize(options) @restrictions_to_check = RESTRICTIONS.keys & options.keys super + setup_timeliness_validated_attributes(options[:class]) if options[:class] + end + def setup_timeliness_validated_attributes(model) if model.respond_to?(:timeliness_validated_attributes) model.timeliness_validated_attributes ||= [] model.timeliness_validated_attributes |= @attributes From 6a07ef6d47ac99dd13a3d5a1669747ca5049d41a Mon Sep 17 00:00:00 2001 From: Jonathan Geisler Date: Mon, 19 Jan 2015 22:21:38 -0500 Subject: [PATCH 3/3] Update MultiparameterAttribute for Rails 4.2 The implementation of AttributeAssignment::MultiparameterAttribute in Rails 4.2 was changed, and so the extension from this library was no longer valid. This simple fix lets it more closely match the implementation from the Rails implementation by changing the code in the library to match. --- .../extensions/multiparameter_attribute.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/validates_timeliness/extensions/multiparameter_attribute.rb b/lib/validates_timeliness/extensions/multiparameter_attribute.rb index b1278521..23160354 100644 --- a/lib/validates_timeliness/extensions/multiparameter_attribute.rb +++ b/lib/validates_timeliness/extensions/multiparameter_attribute.rb @@ -42,8 +42,8 @@ def validate_multiparameter_date_values(set_values) end def read_value_with_timeliness - @column = object.class.reflect_on_aggregation(name.to_sym) || object.column_for_attribute(name) - klass = column.klass + @cast_type = object.type_for_attribute(name) + klass = cast_type.klass set_values = values.is_a?(Hash) ? values.to_a.sort_by(&:first).map(&:last) : values if set_values.empty? || set_values.all?{ |v| v.nil? }