From 009eb7d188404844959b808a7fe2869655201512 Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Thu, 7 Nov 2024 13:02:08 +0100 Subject: [PATCH] Fix contributors count to scope by active --- .../organizations/contributors_controller.rb | 2 +- spec/requests/contributors_spec.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/organizations/contributors_controller.rb b/app/controllers/organizations/contributors_controller.rb index c6befa1e6..5872aeffb 100644 --- a/app/controllers/organizations/contributors_controller.rb +++ b/app/controllers/organizations/contributors_controller.rb @@ -49,7 +49,7 @@ def destroy end def count - render json: { count: @organization.contributors.with_tags(params[:tag_list]).count } + render json: { count: @organization.contributors.active.with_tags(params[:tag_list]).count } end def conversations diff --git a/spec/requests/contributors_spec.rb b/spec/requests/contributors_spec.rb index ac0b37761..b9844713b 100644 --- a/spec/requests/contributors_spec.rb +++ b/spec/requests/contributors_spec.rb @@ -55,13 +55,27 @@ end describe 'GET /count' do + subject { -> { get count_organization_contributors_path(organization, tag_list: ['teacher'], as: user) } } + let!(:teachers) { create_list(:contributor, 2, tag_list: 'teacher', organization: organization) } let!(:other_teachers) { create_list(:contributor, 2, tag_list: 'teacher') } it 'returns count of contributors with a specific tag within the organization' do - get count_organization_contributors_path(organization, tag_list: ['teacher'], as: user) + subject.call expect(response.body).to eq({ count: 2 }.to_json) end + + context 'given non-active contributors' do + before do + create(:contributor, tag_list: 'teacher', deactivated_at: 1.day.ago, organization: organization) + create(:contributor, tag_list: 'teacher', unsubscribed_at: 1.day.ago, organization: organization) + subject.call + end + + it 'returns the count of contributors with a specific tag for active contributors' do + expect(response.body).to eq({ count: 2 }.to_json) + end + end end describe 'GET /conversations' do