Browse files

Fix DateTimeSelect extension for Rails 3.1.0

  • Loading branch information...
1 parent e7b503a commit 473da0fa5ea94638c27d18a167f1088f2febbb20 @adzap adzap committed Sep 18, 2011
Showing with 10 additions and 16 deletions.
  1. +6 −10 lib/validates_timeliness/extensions/date_time_select.rb
  2. +4 −6 spec/support/test_model.rb
View
16 lib/validates_timeliness/extensions/date_time_select.rb
@@ -16,16 +16,10 @@ module DateTimeSelect
module InstanceMethods
class TimelinessDateTime
-
attr_accessor :year, :month, :day, :hour, :min, :sec
def initialize(year, month, day, hour, min, sec)
- @year = year
- @month = month
- @day = day
- @hour = hour
- @min = min
- @sec = sec
+ @year, @month, @day, @hour, @min, @sec = year, month, day, hour, min, sec
end
# adapted from activesupport/lib/active_support/core_ext/date_time/calculations.rb, line 36 (3.0.7)
@@ -46,13 +40,15 @@ def datetime_selector_with_timeliness(*args)
datetime_selector_without_timeliness(*args)
end
- def value(object)
+ def value_with_timeliness(object)
unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
- return super
+ return value_without_timeliness(object)
end
+
+ @template_object.params[@object_name]
pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
- return super if pairs.empty?
+ return value_without_timeliness(object) if pairs.empty?
values = [nil] * 6
pairs.map do |(param, value)|
View
10 spec/support/test_model.rb
@@ -31,15 +31,15 @@ def type_cast(attr_name, value)
end
def initialize(attributes = nil)
- @attributes = self.class.model_attributes.inject({}) do |hash, column|
+ @attributes = self.class.model_attributes.keys.inject({}) do |hash, column|
hash[column.to_s] = nil
hash
end
self.attributes = attributes unless attributes.nil?
end
def attributes
- @attributes.keys
+ @attributes
end
def attributes=(new_attributes={})
@@ -49,14 +49,12 @@ def attributes=(new_attributes={})
end
def method_missing(method_id, *args, &block)
- if !self.class.attribute_methods_generated?
- self.class.define_attribute_methods self.class.model_attributes.keys.map(&:to_s)
- method_name = method_id.to_s
+ if match_attribute_method?(method_id.to_s)
+ self.class.define_attribute_methods self.class.model_attributes.keys
send(method_id, *args, &block)
else
super
end
end
-
end

0 comments on commit 473da0f

Please sign in to comment.