aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
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/lib
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/lib')
-rw-r--r--activerecord/lib/active_record/attribute.rb7
-rw-r--r--activerecord/lib/active_record/type/value.rb7
2 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb
index 6d38224830..15cbbcff68 100644
--- a/activerecord/lib/active_record/attribute.rb
+++ b/activerecord/lib/active_record/attribute.rb
@@ -62,6 +62,13 @@ module ActiveRecord
true
end
+ def ==(other)
+ self.class == other.class &&
+ name == other.name &&
+ value_before_type_cast == other.value_before_type_cast &&
+ type == other.type
+ end
+
protected
def initialize_dup(other)
diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb
index 475e130013..9456a4a56c 100644
--- a/activerecord/lib/active_record/type/value.rb
+++ b/activerecord/lib/active_record/type/value.rb
@@ -76,6 +76,13 @@ module ActiveRecord
false
end
+ def ==(other)
+ self.class == other.class &&
+ precision == other.precision &&
+ scale == other.scale &&
+ limit == other.limit
+ end
+
private
def type_cast(value)