From 1633c475dd0e60e6fa3d1abc708c16055f1095db Mon Sep 17 00:00:00 2001 From: Yetrina Battad Date: Wed, 19 Jun 2024 14:31:40 +1000 Subject: [PATCH] fix: handle case where bibref is a Hash --- app/presenters/rendering/bibref.rb | 6 +++++- spec/files/notes/bibref_content.json | 6 ++++++ spec/presenters/rendering/bibref_spec.rb | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 spec/files/notes/bibref_content.json diff --git a/app/presenters/rendering/bibref.rb b/app/presenters/rendering/bibref.rb index 4edfcc66..434f8b66 100644 --- a/app/presenters/rendering/bibref.rb +++ b/app/presenters/rendering/bibref.rb @@ -20,7 +20,11 @@ def render_bibref # Sometimes the value is a single string instead of an array of strings Array.wrap(values).each do |value| doc.li do |list_item| - list_item << value + list_item << if value.is_a?(Hash) + value["content"] + else + value + end end end } diff --git a/spec/files/notes/bibref_content.json b/spec/files/notes/bibref_content.json new file mode 100644 index 00000000..510d771b --- /dev/null +++ b/spec/files/notes/bibref_content.json @@ -0,0 +1,6 @@ +{ + "bibref": { + "persname": "Sexton, Christopher", + "content": "Sexton, Christopher. Peggy van Praagh, a life of dance. South Melbourne : Macmillan, 1985." + } +} diff --git a/spec/presenters/rendering/bibref_spec.rb b/spec/presenters/rendering/bibref_spec.rb index 68dcf769..4c3a20c9 100644 --- a/spec/presenters/rendering/bibref_spec.rb +++ b/spec/presenters/rendering/bibref_spec.rb @@ -43,5 +43,20 @@ expect(rendered).to have_css("em", text: "Who's who in Australia") end end + + context "when the bibref contains a hash" do + let(:note) { JSON.parse(IO.read("spec/files/notes/bibref_content.json")) } + let(:values) { note["bibref"] } + + it "renders the bibref" do + expect(rendered).to have_css("h4", text: "Bibliographic Reference(s)") + expect(rendered).to have_css("ul.list-unstyled") + expect(rendered).to have_css("li", count: 1) + end + + it "inserts the existing HTML" do + expect(rendered).to have_css("span.persname", text: "Sexton, Christopher") + end + end end end