diff --git a/CHANGELOG b/CHANGELOG index 3f42c3f..ad9afbf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ [2008-10-28] - fixed bug when dirty attributes not reflecting change when attribute changed from time value to nil [reported by Brad (pvjq)] + - fixes for Rails 2.2 compatibility. Will refactor in to Rails version specific branches in the future. [2008-09-24] - refactored attribute write method definitions diff --git a/lib/validates_timeliness/instance_tag.rb b/lib/validates_timeliness/instance_tag.rb index e20427a..43a1af6 100644 --- a/lib/validates_timeliness/instance_tag.rb +++ b/lib/validates_timeliness/instance_tag.rb @@ -7,15 +7,25 @@ module ValidatesTimeliness module InstanceTag def self.included(base) - base.alias_method_chain :date_or_time_select, :timeliness - base.alias_method_chain :value, :timeliness + if Rails::VERSION::STRING >= '2.2' + base.class_eval do + alias_method :datetime_selector_without_timeliness, :datetime_selector + alias_method :datetime_selector, :datetime_selector_with_timeliness + end + else + base.class_eval do + alias_method :datetime_selector_without_timeliness, :date_or_time_select + alias_method :date_or_time_select, :datetime_selector_with_timeliness + end + end + base.alias_method_chain :value, :timeliness end TimelinessDateTime = Struct.new(:year, :month, :day, :hour, :min, :sec) - def date_or_time_select_with_timeliness(*args) + def datetime_selector_with_timeliness(*args) @timeliness_date_or_time_tag = true - date_or_time_select_without_timeliness(*args) + datetime_selector_without_timeliness(*args) end def value_with_timeliness(object) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3bbf82e..c9745da 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,7 +32,10 @@ puts "Using #{vendored ? 'vendored' : 'gem'} Rails version #{RAILS_VER} (ActiveR ActiveRecord::Base.default_timezone = :utc -if RAILS_VER >= '2.1' +if RAILS_VER >= '2.2' + Time.zone_default = ActiveSupport::TimeZone['UTC'] + ActiveRecord::Base.time_zone_aware_attributes = true +elsif RAILS_VER >= '2.1' Time.zone_default = TimeZone['UTC'] ActiveRecord::Base.time_zone_aware_attributes = true end