1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #28157 from robin850/hwia-soft-deprecation

Soft-deprecate the `HashWithIndifferentAccess` constant
This commit is contained in:
Matthew Draper 2017-02-25 10:53:03 +10:30
commit 9099cf064f
5 changed files with 57 additions and 3 deletions

View file

@ -50,7 +50,7 @@ module ActiveRecord
super.tap do super.tap do
@previous_mutation_tracker = nil @previous_mutation_tracker = nil
clear_mutation_trackers clear_mutation_trackers
@changed_attributes = HashWithIndifferentAccess.new @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end end
end end
@ -70,13 +70,13 @@ module ActiveRecord
def changes_applied def changes_applied
@previous_mutation_tracker = mutation_tracker @previous_mutation_tracker = mutation_tracker
@changed_attributes = HashWithIndifferentAccess.new @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
clear_mutation_trackers clear_mutation_trackers
end end
def clear_changes_information def clear_changes_information
@previous_mutation_tracker = nil @previous_mutation_tracker = nil
@changed_attributes = HashWithIndifferentAccess.new @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
forget_attribute_assignments forget_attribute_assignments
clear_mutation_trackers clear_mutation_trackers
end end

View file

@ -1,3 +1,8 @@
* Soft-deprecated the top-level `HashWithIndifferentAcces` constant.
`ActiveSupport::HashWithIndifferentAccess` should be used instead.
*Robin Dupret* (#28157)
* In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional * In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
argument for `Marshal#load( source [, proc] )`. This way we don't have to do argument for `Marshal#load( source [, proc] )`. This way we don't have to do
`Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc. `Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.

View file

@ -316,4 +316,6 @@ module ActiveSupport
end end
end end
# :stopdoc:
HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess

View file

@ -8,6 +8,8 @@ require "active_support/core_ext/object/deep_dup"
require "active_support/inflections" require "active_support/inflections"
class HashExtTest < ActiveSupport::TestCase class HashExtTest < ActiveSupport::TestCase
HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess
class IndifferentHash < ActiveSupport::HashWithIndifferentAccess class IndifferentHash < ActiveSupport::HashWithIndifferentAccess
end end
@ -1088,6 +1090,30 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal 1, hash[:a] assert_equal 1, hash[:a]
assert_equal 3, hash[:b] assert_equal 3, hash[:b]
end end
def test_inheriting_from_top_level_hash_with_indifferent_access_preserves_ancestors_chain
klass = Class.new(::HashWithIndifferentAccess)
assert_equal ActiveSupport::HashWithIndifferentAccess, klass.ancestors[1]
end
def test_inheriting_from_hash_with_indifferent_access_properly_dumps_ivars
klass = Class.new(::HashWithIndifferentAccess) do
def initialize(*)
@foo = "bar"
super
end
end
yaml_output = klass.new.to_yaml
# `hash-with-ivars` was introduced in 2.0.9 (https://git.io/vyUQW)
if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("2.0.9")
assert_includes yaml_output, "hash-with-ivars"
assert_includes yaml_output, "@foo: bar"
else
assert_includes yaml_output, "hash"
end
end
end end
class IWriteMyOwnXML class IWriteMyOwnXML
@ -1133,6 +1159,8 @@ class HashExtToParamTests < ActiveSupport::TestCase
end end
class HashToXmlTest < ActiveSupport::TestCase class HashToXmlTest < ActiveSupport::TestCase
HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess
def setup def setup
@xml_options = { root: :person, skip_instruct: true, indent: 0 } @xml_options = { root: :person, skip_instruct: true, indent: 0 }
end end

View file

@ -65,6 +65,25 @@ Overwrite /myapp/config/application.rb? (enter "h" for help) [Ynaqdh]
Don't forget to review the difference, to see if there were any unexpected changes. Don't forget to review the difference, to see if there were any unexpected changes.
Upgrading from Rails 5.0 to Rails 5.1
-------------------------------------
For more information on changes made to Rails 5.1 please see the [release notes](5_1_release_notes.html).
### Top-level `HashWithIndifferentAccess` is soft-deprecated
If your application uses the the top-level `HashWithIndifferentAccess` class, you
should slowly move your code to use the `ActiveSupport::HashWithIndifferentAccess`
one.
It is only soft-deprecated, which means that your code will not break at the
moment and no deprecation warning will be displayed but this constant will be
removed in the future.
Also, if you have pretty old YAML documents containg dumps of such objects,
you may need to load and dump them again to make sure that they reference
the right constant and that loading them won't break in the future.
Upgrading from Rails 4.2 to Rails 5.0 Upgrading from Rails 4.2 to Rails 5.0
------------------------------------- -------------------------------------