Rails 2.2 compatibility fixes with more version check hackery (yuck, will fix later)

This commit is contained in:
Adam Meehan 2008-10-28 22:05:25 +11:00
parent 2f162ca500
commit 604a792e25
3 changed files with 19 additions and 5 deletions

View File

@ -1,5 +1,6 @@
[2008-10-28] [2008-10-28]
- fixed bug when dirty attributes not reflecting change when attribute changed from time value to nil [reported by Brad (pvjq)] - 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] [2008-09-24]
- refactored attribute write method definitions - refactored attribute write method definitions

View File

@ -7,15 +7,25 @@ module ValidatesTimeliness
module InstanceTag module InstanceTag
def self.included(base) def self.included(base)
base.alias_method_chain :date_or_time_select, :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 base.alias_method_chain :value, :timeliness
end end
TimelinessDateTime = Struct.new(:year, :month, :day, :hour, :min, :sec) 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 @timeliness_date_or_time_tag = true
date_or_time_select_without_timeliness(*args) datetime_selector_without_timeliness(*args)
end end
def value_with_timeliness(object) def value_with_timeliness(object)

View File

@ -32,7 +32,10 @@ puts "Using #{vendored ? 'vendored' : 'gem'} Rails version #{RAILS_VER} (ActiveR
ActiveRecord::Base.default_timezone = :utc 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'] Time.zone_default = TimeZone['UTC']
ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.time_zone_aware_attributes = true
end end