aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-08-15 13:37:53 -0600
committerSean Griffin <sean@thoughtbot.com>2014-08-15 13:37:53 -0600
commitbc153cff9156e7e19b3587f0bb8062d238644b1d (patch)
tree3aa2987f67d98d86b05346c090cd180821346cd9 /activerecord/test/cases/attribute_test.rb
parenta59b9e2284353dcf8cf6d77b97aaa4255563c807 (diff)
downloadrails-bc153cff9156e7e19b3587f0bb8062d238644b1d.tar.gz
rails-bc153cff9156e7e19b3587f0bb8062d238644b1d.tar.bz2
rails-bc153cff9156e7e19b3587f0bb8062d238644b1d.zip
Implement `==` on `Type::Value` and `Attribute`
This was a small self contained piece of the refactoring that I am working on, which required these objects to be comparable.
Diffstat (limited to 'activerecord/test/cases/attribute_test.rb')
-rw-r--r--activerecord/test/cases/attribute_test.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_test.rb b/activerecord/test/cases/attribute_test.rb
index 91f6aee931..7b325abf1d 100644
--- a/activerecord/test/cases/attribute_test.rb
+++ b/activerecord/test/cases/attribute_test.rb
@@ -138,5 +138,35 @@ module ActiveRecord
test "uninitialized attributes have no value" do
assert_nil Attribute.uninitialized(:foo, nil).value
end
+
+ test "attributes equal other attributes with the same constructor arguments" do
+ first = Attribute.from_database(:foo, 1, Type::Integer.new)
+ second = Attribute.from_database(:foo, 1, Type::Integer.new)
+ assert_equal first, second
+ end
+
+ test "attributes do not equal attributes with different names" do
+ first = Attribute.from_database(:foo, 1, Type::Integer.new)
+ second = Attribute.from_database(:bar, 1, Type::Integer.new)
+ assert_not_equal first, second
+ end
+
+ test "attributes do not equal attributes with different types" do
+ first = Attribute.from_database(:foo, 1, Type::Integer.new)
+ second = Attribute.from_database(:foo, 1, Type::Float.new)
+ assert_not_equal first, second
+ end
+
+ test "attributes do not equal attributes with different values" do
+ first = Attribute.from_database(:foo, 1, Type::Integer.new)
+ second = Attribute.from_database(:foo, 2, Type::Integer.new)
+ assert_not_equal first, second
+ end
+
+ test "attributes do not equal attributes of other classes" do
+ first = Attribute.from_database(:foo, 1, Type::Integer.new)
+ second = Attribute.from_user(:foo, 1, Type::Integer.new)
+ assert_not_equal first, second
+ end
end
end