Skip to content

plugins: count every active mission in the community stats - #21678

Merged
freesteph merged 2 commits into
betagouv:masterfrom
Dev-next-gen:fix/community-stats-active-missions
Sep 15, 2026
Merged

freesteph merged 2 commits into
betagouv:masterfrom
Dev-next-gen:fix/community-stats-active-missions

Conversation

@Dev-next-gen

Copy link
Copy Markdown
Contributor

While reading #20910, which stopped the community filter from looking only at missions.last (member files aren't sorted chronologically), I noticed the render_community_stats tag in the same file still does exactly that:

if author.data['missions']&.last&.[]('end')&.>= now

That condition drives total and the per-domaine counts, so the "N membres" figure on /jobs and the stats on /communaute leave out anyone whose active mission isn't the last entry in their file. I ran both conditions over content/_authors at 2876a65 today: the old one gives 1290 members, Beta::Member#active_missions gives 1362. All 72 missing people have an active mission that isn't the last one (none of them are there because of a missing end date).

The fix reuses Beta::Member.new(author.data).active_missions.any?, like the filter does, and drops the now variable that's no longer used. employer and domaineOverDate don't change.

I added spec/plugins/community_stats_spec.rb. Without the fix, the case where the active mission comes first fails (expected: 2, got: 1); with it, both examples pass. The whole rspec suite passes (62 examples), and rubocop 1.90.0 from the lockfile reports nothing on the two files. I ran this in a ruby:3.4-bookworm container with the gems installed by hand, since I don't have Ruby 4.0.6 locally.

AI tools used

@revolunet
revolunet requested a review from freesteph September 14, 2026 11:51

@freesteph freesteph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some feedback around code organisation but all good otherwise

Comment thread spec/plugins/community_stats_spec.rb Resolved
Comment thread spec/plugins/community_stats_spec.rb Resolved
Comment thread spec/plugins/community_stats_spec.rb Resolved

@freesteph freesteph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

The community filter was fixed in betagouv#20910 to stop looking only at the
last mission, since member files are not sorted chronologically. The
render_community_stats tag still used missions.last to compute the
total and per-domaine counts, so members whose active mission is not
the last entry were left out of the "N membres" figure on /jobs and
the stats on /communaute.

Reuse Beta::Member#active_missions like the filter does.
Following review: the RenderCommunityStatsTag example now lives in
spec/plugins/community_spec.rb with the filter one, both nested under
a single top-level describe to satisfy RSpec/MultipleDescribes, and
the "active mission is not the last one" case is tested on
Beta::Member#active_missions in spec/lib/models/member_spec.rb.
@freesteph
freesteph force-pushed the fix/community-stats-active-missions branch from 3444bc3 to ee57403 Compare September 15, 2026 08:14
@freesteph
freesteph merged commit 7e6a477 into betagouv:master Sep 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants