mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #16138 from sgrif/sg-attribute-set-key
AttributeSet#include? -> AttributeSet#key?
This commit is contained in:
commit
6f15762fa6
3 changed files with 10 additions and 10 deletions
|
@ -251,7 +251,7 @@ module ActiveRecord
|
||||||
# person.has_attribute?('age') # => true
|
# person.has_attribute?('age') # => true
|
||||||
# person.has_attribute?(:nothing) # => false
|
# person.has_attribute?(:nothing) # => false
|
||||||
def has_attribute?(attr_name)
|
def has_attribute?(attr_name)
|
||||||
@attributes.include?(attr_name.to_s)
|
@attributes.key?(attr_name.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of names for the attributes available on this object.
|
# Returns an array of names for the attributes available on this object.
|
||||||
|
@ -386,7 +386,7 @@ module ActiveRecord
|
||||||
|
|
||||||
def attribute_method?(attr_name) # :nodoc:
|
def attribute_method?(attr_name) # :nodoc:
|
||||||
# We check defined? because Syck calls respond_to? before actually calling initialize.
|
# 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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -21,8 +21,8 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
alias_method :to_h, :to_hash
|
alias_method :to_h, :to_hash
|
||||||
|
|
||||||
def include?(name)
|
def key?(name)
|
||||||
attributes.include?(name) && self[name].initialized?
|
attributes.key?(name) && self[name].initialized?
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_value(name, &block)
|
def fetch_value(name, &block)
|
||||||
|
@ -53,7 +53,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset(key)
|
def reset(key)
|
||||||
if include?(key)
|
if key?(key)
|
||||||
write_from_database(key, nil)
|
write_from_database(key, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -88,15 +88,15 @@ module ActiveRecord
|
||||||
assert_equal [:foo], attributes.keys
|
assert_equal [:foo], attributes.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
test "uninitialized attributes return false for include?" do
|
test "uninitialized attributes return false for key?" do
|
||||||
attributes = attributes_with_uninitialized_key
|
attributes = attributes_with_uninitialized_key
|
||||||
assert attributes.include?(:foo)
|
assert attributes.key?(:foo)
|
||||||
assert_not attributes.include?(:bar)
|
assert_not attributes.key?(:bar)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "unknown attributes return false for include?" do
|
test "unknown attributes return false for key?" do
|
||||||
attributes = attributes_with_uninitialized_key
|
attributes = attributes_with_uninitialized_key
|
||||||
assert_not attributes.include?(:wibble)
|
assert_not attributes.key?(:wibble)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "fetch_value returns the value for the given initialized attribute" do
|
test "fetch_value returns the value for the given initialized attribute" do
|
||||||
|
|
Loading…
Reference in a new issue