Mutable drops should fallback to their own methods when a mutation isn't present (#6350)
Merge pull request 6350
This commit is contained in:
parent
66e2d38d58
commit
a5fd0c0b26
|
@ -104,11 +104,9 @@ module Jekyll
|
|||
#
|
||||
# Returns true if the given key is present
|
||||
def key?(key)
|
||||
if self.class.mutable?
|
||||
@mutations.key?(key)
|
||||
else
|
||||
!key.nil? && (respond_to?(key) || fallback_data.key?(key))
|
||||
end
|
||||
return false if key.nil?
|
||||
return true if self.class.mutable? && @mutations.key?(key)
|
||||
respond_to?(key) || fallback_data.key?(key)
|
||||
end
|
||||
|
||||
# Generates a list of keys with user content as their values.
|
||||
|
|
|
@ -10,12 +10,12 @@ class DropFixture < Jekyll::Drops::Drop
|
|||
end
|
||||
|
||||
def fallback_data
|
||||
@fallback_data ||= {}
|
||||
@fallback_data ||= { "baz" => "buzz" }
|
||||
end
|
||||
end
|
||||
|
||||
class TestDrop < JekyllUnitTest
|
||||
context "a document drop" do
|
||||
context "Drops" do
|
||||
setup do
|
||||
@site = fixture_site({
|
||||
"collections" => ["methods"],
|
||||
|
@ -52,6 +52,7 @@ class TestDrop < JekyllUnitTest
|
|||
end
|
||||
end
|
||||
|
||||
context "a document drop" do
|
||||
context "fetch" do
|
||||
should "raise KeyError if key is not found and no default provided" do
|
||||
assert_raises KeyError do
|
||||
|
@ -87,4 +88,32 @@ class TestDrop < JekyllUnitTest
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "key?" do
|
||||
context "a mutable drop" do
|
||||
should "respond true for native methods" do
|
||||
assert @drop.key? "foo"
|
||||
end
|
||||
|
||||
should "respond true for mutable keys" do
|
||||
@drop["bar"] = "baz"
|
||||
assert @drop.key? "bar"
|
||||
end
|
||||
|
||||
should "return true for fallback data" do
|
||||
assert @drop.key? "baz"
|
||||
end
|
||||
end
|
||||
|
||||
context "a document drop" do
|
||||
should "respond true for native methods" do
|
||||
assert @document_drop.key? "collection"
|
||||
end
|
||||
|
||||
should "return true for fallback data" do
|
||||
assert @document_drop.key? "title"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue