spec/support/test_model.rb in validates_timeliness-4.1.1 vs spec/support/test_model.rb in validates_timeliness-5.0.0.alpha1
- old
+ new
@@ -23,11 +23,13 @@
generated_attribute_methods.module_eval("def #{attr_name}; @attributes['#{attr_name}']; end", __FILE__, __LINE__)
end
def type_cast(attr_name, value)
return value unless value.is_a?(String)
- value.send("to_#{model_attributes[attr_name.to_sym]}") rescue nil
+ type_name = model_attributes[attr_name.to_sym]
+ type = ActiveModel::Type.lookup(type_name)
+ type.cast(value)
end
end
def initialize(attributes = nil)
@attributes = self.class.model_attributes.keys.inject({}) do |hash, column|
@@ -46,10 +48,10 @@
send "#{key}=", value
end
end
def method_missing(method_id, *args, &block)
- if match_attribute_method?(method_id.to_s)
+ if !matched_attribute_method(method_id.to_s).nil?
self.class.define_attribute_methods self.class.model_attributes.keys
send(method_id, *args, &block)
else
super
end