diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-06 08:51:14 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-06 08:52:28 -0600 |
commit | 9e25e0e1735f2ccca69679243aa8cf0885104164 (patch) | |
tree | c3759c6e1b0ca18a1d88df98a4e67dc621554457 /activerecord/test | |
parent | 7a96e629efdd91865309e334d89bdca7c63093df (diff) | |
download | rails-9e25e0e1735f2ccca69679243aa8cf0885104164.tar.gz rails-9e25e0e1735f2ccca69679243aa8cf0885104164.tar.bz2 rails-9e25e0e1735f2ccca69679243aa8cf0885104164.zip |
Implement equality comparison on `AttributeSet` and friends
Any gems or libraries which do work with serialization or YAML will
ultimately need to compare these objects (albeit indirectly) to ensure
correctness. These will likely never get used internally (as they're
slow), but we should still expose them for others.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/attribute_set_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_set_test.rb b/activerecord/test/cases/attribute_set_test.rb index 5a0e463a48..7a24b85a36 100644 --- a/activerecord/test/cases/attribute_set_test.rb +++ b/activerecord/test/cases/attribute_set_test.rb @@ -239,5 +239,15 @@ module ActiveRecord assert_equal 2, new_attributes.fetch_value(:foo) assert_equal 3, new_attributes.fetch_value(:bar) end + + test "comparison for equality is correctly implemented" do + builder = AttributeSet::Builder.new(foo: Type::Integer.new, bar: Type::Integer.new) + attributes = builder.build_from_database(foo: "1", bar: "2") + attributes2 = builder.build_from_database(foo: "1", bar: "2") + attributes3 = builder.build_from_database(foo: "2", bar: "2") + + assert_equal attributes, attributes2 + assert_not_equal attributes2, attributes3 + end end end |