Skip to content
Browse files

Merge pull request #16138 from sgrif/sg-attribute-set-key

AttributeSet#include? -> AttributeSet#key?
  • Loading branch information...
2 parents 7880f39 + 9c83e84 commit 6f15762fa601a5e3238888038684aae7446cfc16 @senny senny committed
View
4 activerecord/lib/active_record/attribute_methods.rb
@@ -251,7 +251,7 @@ def respond_to?(name, include_private = false)
# person.has_attribute?('age') # => true
# person.has_attribute?(:nothing) # => false
def has_attribute?(attr_name)
- @attributes.include?(attr_name.to_s)
+ @attributes.key?(attr_name.to_s)
end
# Returns an array of names for the attributes available on this object.
@@ -386,7 +386,7 @@ def arel_attributes_with_values_for_update(attribute_names) # :nodoc:
def attribute_method?(attr_name) # :nodoc:
# We check defined? because Syck calls respond_to? before actually calling initialize.
- defined?(@attributes) && @attributes.include?(attr_name)
+ defined?(@attributes) && @attributes.key?(attr_name)
end
private
View
6 activerecord/lib/active_record/attribute_set.rb
@@ -21,8 +21,8 @@ def to_hash
end
alias_method :to_h, :to_hash
- def include?(name)
- attributes.include?(name) && self[name].initialized?
+ def key?(name)
+ attributes.key?(name) && self[name].initialized?
end
def fetch_value(name, &block)
@@ -53,7 +53,7 @@ def initialize_clone(_)
end
def reset(key)
- if include?(key)
+ if key?(key)
write_from_database(key, nil)
end
end
View
10 activerecord/test/cases/attribute_set_test.rb
@@ -88,15 +88,15 @@ class AttributeSetTest < ActiveRecord::TestCase
assert_equal [:foo], attributes.keys
end
- test "uninitialized attributes return false for include?" do
+ test "uninitialized attributes return false for key?" do
attributes = attributes_with_uninitialized_key
- assert attributes.include?(:foo)
- assert_not attributes.include?(:bar)
+ assert attributes.key?(:foo)
+ assert_not attributes.key?(:bar)
end
- test "unknown attributes return false for include?" do
+ test "unknown attributes return false for key?" do
attributes = attributes_with_uninitialized_key
- assert_not attributes.include?(:wibble)
+ assert_not attributes.key?(:wibble)
end
test "fetch_value returns the value for the given initialized attribute" do

0 comments on commit 6f15762

Please sign in to comment.
Something went wrong with that request. Please try again.