Skip to content

Fix add space between Name ranks#4090

Merged
JoeCohen merged 13 commits intomainfrom
jdc-4087-add-space-between-rank
Apr 17, 2026
Merged

Fix add space between Name ranks#4090
JoeCohen merged 13 commits intomainfrom
jdc-4087-add-space-between-rank

Conversation

@JoeCohen
Copy link
Copy Markdown
Member

@JoeCohen JoeCohen commented Apr 4, 2026

Steps 1-4 of Issue #4087 Add space between ranks, which is the first stage of Add intermediate ranks #3359.

Copilot AI review requested due to automatic review settings April 4, 2026 23:50
@JoeCohen JoeCohen linked an issue Apr 4, 2026 that may be closed by this pull request
@JoeCohen JoeCohen added iNat interaction with iNat names labels Apr 4, 2026
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 4, 2026

Coverage Status

coverage: 96.269% (+0.003%) from 96.266% — jdc-4087-add-space-between-rank into main

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Name.rank enum mapping to introduce numeric gaps between ranks, and adjusts rank-dependent queries/scopes to avoid relying on contiguous integers.

Changes:

  • Re-maps Name.rank enum values from contiguous integers to spaced integers.
  • Updates Name.immediate_subtaxa_of to compute the “next lower rank” via all_ranks ordering instead of integer arithmetic.
  • Updates Checklist genus-rank selection logic to use Name.rank_range instead of an integer range.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
app/models/name.rb Re-maps rank enum integers to spaced values.
app/models/name/scopes.rb Adjusts immediate subtaxa rank selection to use ordered ranks.
app/classes/checklist.rb Replaces numeric rank range with Name.rank_range to select relevant ranks.

Comment thread app/models/name.rb
Comment thread app/models/name.rb
Comment thread app/models/name/scopes.rb
@@ -172,7 +172,8 @@ module Name::Scopes
# exclude_original_names: exclude_original)
name = find_by(text_name: name) if name.is_a?(String)
scope = if ranks_above_genus.include?(name.rank)
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

ranks_above_genus includes "Group" (app/models/name/taxonomy.rb:414-416), so this branch will run for Group names too. With the new enum ordering in Name, all_ranks.index("Group") - 1 resolves to "Species", so immediate_subtaxa_of for a Group will be constrained to Species. If Group is still used for higher-taxon clades (as the comment in Name says), this can make immediate_subtaxa_of return the wrong level or nothing; consider special-casing Group or aligning ranks_above_genus/rank ordering so the “next lower rank” logic is consistent.

Suggested change
scope = if ranks_above_genus.include?(name.rank)
scope = if ranks_above_genus.include?(name.rank) && name.rank != "Group"

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Rejected. Group names will be handled as part of Steps 6 and 7 of Add intermediate ranks #3359

Comment thread app/classes/checklist.rb Outdated
@JoeCohen JoeCohen removed a link to an issue Apr 5, 2026
JoeCohen added 2 commits April 4, 2026 19:51
Responds to Copilot comment #4090 (comment)

The concern is partially valid. There are two separate code paths for genus counting in this class and they now behave inconsistently:

Instance method path (count_taxa_genera_and_species, line 187): uses Name.rank_range("Stirps", "Genus"), which is index-based on the enum definition order — Group sits at index 4, Stirps at 5, so Group is excluded from this range. Correct behavior.

Class method path (calculate_taxa_by_user, line 156): uses rank.to_i <= Name.ranks[:Genus] (i.e. <= 500). Group is 410, so it is now included in genus counts. With the old integers, Group was 16 > 9 (old Genus), so it was excluded. This is a genuine behavioral change — a regression, not intent.

So the comment is correct about calculate_taxa_by_user line 156, but wrong to implicate the checklist instance path, which the rank_range fix already handles correctly. The fix for line 156 would be to add an explicit Group exclusion or switch to Name.rank_range("Stirps", "Genus").include?(rank.to_i) — consistent with the instance path.
@JoeCohen JoeCohen self-assigned this Apr 5, 2026
@JoeCohen JoeCohen requested review from mo-nathan and nimmolo April 5, 2026 16:26
@JoeCohen JoeCohen changed the title Add space between Name ranks Fix add space between Name ranks Apr 5, 2026
@JoeCohen JoeCohen marked this pull request as draft April 6, 2026 13:59
Extract Name.genus_display_ranks to replace two identical
Name.rank_range("Stirps", "Genus") calls in Checklist.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread db/migrate/20260405130303_respace_name_ranks.rb Outdated
Comment thread db/migrate/20260405130303_respace_name_ranks.rb Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@JoeCohen JoeCohen marked this pull request as ready for review April 6, 2026 15:17
JoeCohen and others added 6 commits April 6, 2026 09:52
Add tests for
- genus_display_ranks,
- immediate_subtaxa_of
- above genus,
- all_site_taxa_by_user
Fix truncated "before deploying" message. Ensure puma is restarted
in all error recovery paths (stash, pull, stash pop failures).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@mo-nathan mo-nathan left a comment

Choose a reason for hiding this comment

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

Looks good! Let's ship it!

@JoeCohen JoeCohen merged commit e6edc23 into main Apr 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

iNat interaction with iNat names

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants