Fix before_type_cast for non-dirty attributes (issue #52).

Only use before_type_cast implementation if earlier than 3.1.0 which has
it's own working version for date/time fields now.
This commit is contained in:
Adam Meehan
2011-09-21 21:28:53 +10:00
parent 34824bbbab
commit 86b7bc4829
4 changed files with 16 additions and 7 deletions

View File

@@ -46,7 +46,7 @@ module ValidatesTimeliness
def define_timeliness_before_type_cast_method(attr_name)
method_body, line = <<-EOV, __LINE__ + 1
def #{attr_name}_before_type_cast
_timeliness_raw_value_for('#{attr_name}')
_timeliness_raw_value_for('#{attr_name}') || @attributes['#{attr_name}']
end
EOV
generated_timeliness_methods.module_eval(method_body, __FILE__, line)

View File

@@ -7,7 +7,8 @@ module ValidatesTimeliness
def define_attribute_methods
super
# Define write method and before_type_cast method
define_timeliness_methods(true)
use_before_type_cast = ::ActiveRecord::VERSION::STRING < '3.1.0'
define_timeliness_methods(use_before_type_cast)
end
def timeliness_attribute_timezone_aware?(attr_name)