Skip to content

Commit

Permalink
Fix available_tags count to scope by active contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 committed Nov 8, 2024
1 parent 085921a commit 8f57e9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def contributors_tags_with_count
ActsAsTaggableOn::Tag
.for_tenant(id)
.joins(:taggings)
.where(taggings: { taggable_type: Contributor.name })
.where(taggings: { taggable_type: Contributor.name, taggable_id: Contributor.active })
.select('tags.id, tags.name, count(taggings.id) as taggings_count')
.group('tags.id')
.all
Expand Down
8 changes: 8 additions & 0 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
let!(:request) { create(:request, tag_list: %w[Homeowner], organization: organization) }
it { should eq([['Homeowner', 1]]) }
end

context 'given an inactive contributor with the same tag' do
before { create(:contributor, tag_list: %w[Homeowner], organization: organization, deactivated_at: 1.day.ago) }

it "does not count inactive contributor's tags" do
expect(subject).to eq([['Homeowner', 1]])
end
end
end
end
end

0 comments on commit 8f57e9c

Please sign in to comment.