Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ==(other) method of AttributeSet safe #49670 #49677

Merged
merged 1 commit into from Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/attribute_set.rb
Expand Up @@ -104,7 +104,7 @@ def reverse_merge!(target_attributes)
end

def ==(other)
attributes == other.attributes
other.is_a?(AttributeSet) && attributes == other.send(:attributes)
end

protected
Expand Down
8 changes: 8 additions & 0 deletions activemodel/test/cases/attribute_set_test.rb
Expand Up @@ -279,6 +279,14 @@ def builder.build_from_database(values = {}, additional_types = {})
assert_not_equal attributes2, attributes3
end

test "==(other) is safe to use with any instance" do
attribute_set = AttributeSet.new({})

assert_equal false, attribute_set == nil
assert_equal false, attribute_set == 1
assert_equal true, attribute_set == attribute_set
end

private
def attributes_with_uninitialized_key
builder = AttributeSet::Builder.new(foo: Type::Integer.new, bar: Type::Float.new)
Expand Down