Fix regression in rendering Markdown references that do not exist
Closes #30972
This commit is contained in:
parent
309bab4310
commit
e89d4741d3
2 changed files with 23 additions and 3 deletions
|
@ -136,7 +136,8 @@ module Banzai
|
|||
|
||||
nodes.each_with_object({}) do |node, hash|
|
||||
if node.has_attribute?(attribute)
|
||||
hash[node] = objects_by_id[node.attr(attribute).to_i]
|
||||
obj = objects_by_id[node.attr(attribute).to_i]
|
||||
hash[node] = obj if obj
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -114,8 +114,27 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
|
|||
expect(hash).to eq({ link => user })
|
||||
end
|
||||
|
||||
it 'returns an empty Hash when the list of nodes is empty' do
|
||||
expect(subject.grouped_objects_for_nodes([], User, 'data-user')).to eq({})
|
||||
it 'returns an empty Hash when entry does not exist in the database' do
|
||||
link = double(:link)
|
||||
|
||||
expect(link).to receive(:has_attribute?).
|
||||
with('data-user').
|
||||
and_return(true)
|
||||
|
||||
expect(link).to receive(:attr).
|
||||
with('data-user').
|
||||
and_return('1')
|
||||
|
||||
nodes = [link]
|
||||
bad_id = user.id + 100
|
||||
|
||||
expect(subject).to receive(:unique_attribute_values).
|
||||
with(nodes, 'data-user').
|
||||
and_return([bad_id.to_s])
|
||||
|
||||
hash = subject.grouped_objects_for_nodes(nodes, User, 'data-user')
|
||||
|
||||
expect(hash).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue