Skip to content

Commit

Permalink
Fix contributors count to scope by active
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 committed Nov 8, 2024
1 parent 8f57e9c commit 009eb7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/organizations/contributors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion spec/requests/contributors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 009eb7d

Please sign in to comment.