From ee40815ae727976035bac19d23531adb009ac1d8 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Fri, 11 Oct 2024 09:43:05 +0100 Subject: [PATCH] Update Notable#all_notes Update the concern so that records tagged with `name:value` will be associated with notes tagged as `name`. Fixes #7293 --- app/models/concerns/notable.rb | 6 +++++- doc/CHANGES.md | 2 ++ spec/models/concerns/notable_and_taggable.rb | 10 +++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/notable.rb b/app/models/concerns/notable.rb index bd881c2f8f..1302c82c30 100644 --- a/app/models/concerns/notable.rb +++ b/app/models/concerns/notable.rb @@ -23,6 +23,10 @@ def tagged_notes private def notable_tags - tags.map(&:name_and_value) + tags.inject([]) do |arr, tag| + arr << tag.name + arr << tag.name_and_value if tag.value + arr + end end end diff --git a/doc/CHANGES.md b/doc/CHANGES.md index 015684d991..c776a7475c 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -2,6 +2,8 @@ ## Highlighted Features +* Change notes so that records tagged with `name:value` will be associated with + notes tagged as `name` (Graeme Porteous) * Add basic Citation searching in admin UI (Gareth Rees) * Improve citations admin to allow title and description updates (Graeme Porteous) diff --git a/spec/models/concerns/notable_and_taggable.rb b/spec/models/concerns/notable_and_taggable.rb index 7c0683ada5..f4ce308a60 100644 --- a/spec/models/concerns/notable_and_taggable.rb +++ b/spec/models/concerns/notable_and_taggable.rb @@ -4,12 +4,20 @@ describe '#all_notes' do subject { record.all_notes } - before { record.tag_string = 'foo' } + before { record.tag_string = 'foo:1' } let!(:tagged_note) { FactoryBot.create(:note, notable_tag: 'foo') } let!(:other_tagged_note) { FactoryBot.create(:note, notable_tag: 'bar') } + let!(:tagged_note_with_value) do + FactoryBot.create(:note, notable_tag: 'foo:1') + end + let!(:tagged_note_with_other_value) do + FactoryBot.create(:note, notable_tag: 'foo:2') + end it { is_expected.to include tagged_note } + it { is_expected.to include tagged_note_with_value } it { is_expected.to_not include other_tagged_note } + it { is_expected.to_not include tagged_note_with_other_value } end end