aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-08-16 14:29:16 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-08-16 14:29:16 -0300
commit88d27ae9181151f448f39298adce9d1b7401a376 (patch)
tree6a23c369694ce0b73221a8e37e17cee25767c094 /activerecord/test/cases
parentb97204c3439e584419afacaf7b61777a361f5437 (diff)
parentbc153cff9156e7e19b3587f0bb8062d238644b1d (diff)
downloadrails-88d27ae9181151f448f39298adce9d1b7401a376.tar.gz
rails-88d27ae9181151f448f39298adce9d1b7401a376.tar.bz2
rails-88d27ae9181151f448f39298adce9d1b7401a376.zip
Merge pull request #16517 from sgrif/sg-comparable-attributes
Implement `==` on `Type::Value` and `Attribute`
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/attribute_test.rb30
-rw-r--r--activerecord/test/cases/types_test.rb6
2 files changed, 36 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
diff --git a/activerecord/test/cases/types_test.rb b/activerecord/test/cases/types_test.rb
index 5c54812f30..db4f78d354 100644
--- a/activerecord/test/cases/types_test.rb
+++ b/activerecord/test/cases/types_test.rb
@@ -149,6 +149,12 @@ module ActiveRecord
end
end
+ def test_type_equality
+ assert_equal Type::Value.new, Type::Value.new
+ assert_not_equal Type::Value.new, Type::Integer.new
+ assert_not_equal Type::Value.new(precision: 1), Type::Value.new(precision: 2)
+ end
+
if current_adapter?(:SQLite3Adapter)
def test_binary_encoding
type = SQLite3Binary.new