Skip to content

Commit

Permalink
Update Notable#all_notes
Browse files Browse the repository at this point in the history
Update the concern so that records tagged with `name:value` will be
associated with notes tagged as `name`.

Fixes #7293
  • Loading branch information
gbp committed Nov 22, 2024
1 parent 63bba9f commit 8496335
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/models/concerns/notable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* Upgrade Stripe API version (Graeme Porteous)
* Drop support for Azure storage (Graeme Porteous)
* Add basic Citation searching in admin UI (Gareth Rees)
Expand Down
27 changes: 23 additions & 4 deletions spec/models/concerns/notable_and_taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@
describe '#all_notes' do
subject { record.all_notes }

before { record.tag_string = 'foo' }

let!(:tagged_note) { FactoryBot.create(:note, notable_tag: 'foo') }
let!(:other_tagged_note) { FactoryBot.create(:note, notable_tag: 'bar') }

it { is_expected.to include tagged_note }
it { is_expected.to_not include other_tagged_note }
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

context 'with name tag' do
before { record.tag_string = 'foo' }
it { is_expected.to include tagged_note }
it { is_expected.to_not 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

context 'with name:value tag' do
before { record.tag_string = 'foo:1' }
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
end

0 comments on commit 8496335

Please sign in to comment.