Merge pull request #51713 from Shopify/stale-state-casting

Don't cast `stale_state` to String
This commit is contained in:
Jean Boussier 2024-05-02 16:59:02 +02:00 committed by GitHub
commit 087260d0fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 6 deletions

View File

@ -148,8 +148,7 @@ module ActiveRecord
end
def stale_state
result = owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) }
result && result.to_s
owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) }
end
end
end

View File

@ -41,8 +41,9 @@ module ActiveRecord
end
def stale_state
foreign_key = super
foreign_key && [foreign_key.to_s, owner[reflection.foreign_type].to_s]
if foreign_key = super
[foreign_key, owner[reflection.foreign_type]]
end
end
end
end

View File

@ -82,7 +82,7 @@ module ActiveRecord
def stale_state
if through_reflection.belongs_to?
Array(through_reflection.foreign_key).filter_map do |foreign_key_column|
owner[foreign_key_column] && owner[foreign_key_column].to_s
owner[foreign_key_column]
end.presence
end
end

View File

@ -33,7 +33,6 @@ class MarshalSerializationTest < ActiveRecord::TestCase
assert_equal "Have a nice day", topic.content
assert_predicate topic.association(:replies), :loaded?
assert_predicate topic.replies.first.association(:topic), :loaded?
assert_same topic, topic.replies.first.topic
end
def test_deserializing_rails_7_1_marshal_basic