Skip to content
This repository
Browse code

Base.skip_time_zone_conversion_for_attributes uses class_inheritable_…

…accessor, so that subclasses don't overwrite Base [#346 state:resolved]
  • Loading branch information...
commit 9c4730d01e892df8d5c5493a08e0cddf0de5d575 1 parent d28c724
Emilio Tagua miloops authored gbuesing committed
2  activerecord/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *Edge*
2 2
  3 +* Base.skip_time_zone_conversion_for_attributes uses class_inheritable_accessor, so that subclasses don't overwrite Base [#346 state:resolved] [miloops]
  4 +
3 5 * Added find_last_by dynamic finder #762 [miloops]
4 6
5 7 * Internal API: configurable association options and build_association method for reflections so plugins may extend and override. #985 [Hongli Lai]
2  activerecord/lib/active_record/attribute_methods.rb
@@ -10,7 +10,7 @@ def self.included(base)
10 10 base.attribute_types_cached_by_default = ATTRIBUTE_TYPES_CACHED_BY_DEFAULT
11 11 base.cattr_accessor :time_zone_aware_attributes, :instance_writer => false
12 12 base.time_zone_aware_attributes = false
13   - base.cattr_accessor :skip_time_zone_conversion_for_attributes, :instance_writer => false
  13 + base.class_inheritable_accessor :skip_time_zone_conversion_for_attributes, :instance_writer => false
14 14 base.skip_time_zone_conversion_for_attributes = []
15 15 end
16 16
9 activerecord/test/cases/attribute_methods_test.rb
... ... @@ -1,5 +1,6 @@
1 1 require "cases/helper"
2 2 require 'models/topic'
  3 +require 'models/minimalistic'
3 4
4 5 class AttributeMethodsTest < ActiveRecord::TestCase
5 6 fixtures :topics
@@ -219,6 +220,14 @@ def test_setting_time_zone_aware_attribute_in_current_time_zone
219 220 end
220 221 end
221 222
  223 + def test_setting_time_zone_conversion_for_attributes_should_write_value_on_class_variable
  224 + Topic.skip_time_zone_conversion_for_attributes = [:field_a]
  225 + Minimalistic.skip_time_zone_conversion_for_attributes = [:field_b]
  226 +
  227 + assert_equal [:field_a], Topic.skip_time_zone_conversion_for_attributes
  228 + assert_equal [:field_b], Minimalistic.skip_time_zone_conversion_for_attributes
  229 + end
  230 +
222 231 private
223 232 def time_related_columns_on_topic
224 233 Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name)

0 comments on commit 9c4730d

Please sign in to comment.
Something went wrong with that request. Please try again.