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

Merge pull request #31475 from shioyama/reset_column_information_redefine_child_attribute_methods

Undefine attribute methods of descendants when resetting column information
This commit is contained in:
Matthew Draper 2017-12-19 11:54:38 +10:30 committed by GitHub
commit d9e4bffb60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View file

@ -1,3 +1,8 @@
* Undefine attribute methods on descendants when resetting column
information.
*Chris Salzberg*
* Log database query callers
Add `verbose_query_logs` configuration option to display the caller

View file

@ -425,7 +425,7 @@ module ActiveRecord
# end
def reset_column_information
connection.clear_cache!
undefine_attribute_methods
([self] + descendants).each(&:undefine_attribute_methods)
connection.schema_cache.clear_data_source_cache!(table_name)
reload_schema_from_cache

View file

@ -1106,13 +1106,18 @@ class PersistenceTest < ActiveRecord::TestCase
end
def test_reset_column_information_resets_children
child = Class.new(Topic)
child.new # force schema to load
child_class = Class.new(Topic)
child_class.new # force schema to load
ActiveRecord::Base.connection.add_column(:topics, :foo, :string)
Topic.reset_column_information
assert_equal "bar", child.new(foo: :bar).foo
# this should redefine attribute methods
child_class.new
assert child_class.instance_methods.include?(:foo)
assert child_class.instance_methods.include?(:foo_changed?)
assert_equal "bar", child_class.new(foo: :bar).foo
ensure
ActiveRecord::Base.connection.remove_column(:topics, :foo)
Topic.reset_column_information