Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad search names #2714

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Bad search names #2714

wants to merge 27 commits into from

Conversation

JoeCohen
Copy link
Member

@JoeCohen JoeCohen commented Feb 11, 2025

  • Prevents saving Names which lack a search_name
  • Prevents saving Names whose search_name is indistinct from that of an existing Name.
  • Prevents saving Name whose author ends in a bad character. (Can end only in a letter or period.)
  • Prevents saving Name whose author contains a bad character. See my comment below.
  • Delivers Indistinct search_names #2712

Some Manual Tests

  • Add a Name at rank Genus, without a period after L: Boletus L
    Expected Result: Redisplays form with flash: "Unable to save changes. Equivalent name exists: Boletus L. (14925)"
  • Edit a Name., e.g edit Boletus edulis, adding a comma at the end of author.
    Expected Result: Flash error: "Unable to save changes. Name author must end only in a letter or period." Author field is emphasized with red border.
  • Edit a Name., e.g edit Boletus edulis, enclosing author in parens.
    Expected Result: Flash error: "Unable to save changes. Name author must end only in a letter or period." Author field is emphasized with red border.
    Note: An author in the form (Blah) is incorrect. Parens enclose the author of the basionym, so (Blah) is missing the names of the authors of the re-classified name, or -- if it hasn't been reclassified -- there should be no parens.

- Prevents saving Name if an indistinct Name already exists
- Adds an error message
- Temporarily ignores Names without `search_name`
- Revises `create_test_name` utility to update an existing name instead creating an indistinct one
- Refactors test_name_spaceship_operator for clarity and non-circularity
@JoeCohen JoeCohen linked an issue Feb 11, 2025 that may be closed by this pull request
30 tasks
@JoeCohen JoeCohen changed the title Indistinct search names Bad search names Feb 11, 2025
- Prevents intermitten failure of test_getting_names_ok_for_export
[Example](https://github.com/MushroomObserver/mushroom-observer/actions/runs/13270003060/job/37046955064)
```ruby
Minitest::UnexpectedError:         ActiveRecord::RecordInvalid: Validation failed: Search name Equivalent name exists Macrocybe
            test/classes/api2/names_test.rb:259:in `test_getting_names_ok_for_export'
```
- Using `sample` invites intermittent failures.
Example: https://github.com/MushroomObserver/mushroom-observer/actions/runs/13270003060/job/37046955064
```ruby
Minitest::UnexpectedError:         ActiveRecord::RecordInvalid: Validation failed: Search name Equivalent name exists Macrocybe
            test/classes/api2/names_test.rb:259:in `test_getting_names_ok_for_export'
```
- As far as I can tell the only function of the removed line is to insures that there's a correctly spelled Name that's ok for export.
No longer needed because
- Each fixture & test case has a `search_name`
- There's now a validation for `search_name` presence.
- Gathers macros & methods per attribute
- revises metod names to reveal intent and for consistency
- better flash error
- additional, dryer test case
- Requires author to end only in a (letter or period) plus optional space(s).
- Breaks two tests. Both deal with the old style intrageneric Names.
- Both tests deal with merger of old-style infra-generic Names. No such such Names exist in the  db:
```ruby
foo = Name.where(Name[:author] =~ /\(.*Genus.*\)$/)
  Name Load (88.1ms)  SELECT `names`.* FROM `names` WHERE `names`.`author` REGEXP '\\(.*Genus.*\\)$' /* loading for pp */ LIMIT 11
=> []
```
@coveralls
Copy link
Collaborator

coveralls commented Feb 13, 2025

Coverage Status

coverage: 93.449% (+0.005%) from 93.444%
when pulling 9a95a3b on jdc-2712-indistinct-search_names
into 5a2a8ac on main.

This Error below occurs only during CI, only during the PR run (and not in the Push run).
The fix was suggested by ChatGPT
```
Run bundle exec rake db:schema:load
  bundle exec rake db:schema:load
  bundle exec rake db:fixtures:load
  shell: /usr/bin/bash -e {0}
rake aborted!
NoMethodError: private method `t' called for an instance of Symbol (NoMethodError)

              message: :validate_name_author_characters.t
                                                       ^^
/home/runner/work/mushroom-observer/mushroom-observer/app/models/name.rb:429:in `<class:Name>'
/home/runner/work/mushroom-observer/mushroom-observer/app/models/name.rb:331:in `<top (required)>'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/zeitwerk-2.7.1/lib/zeitwerk/core_ext/kernel.rb:26:in `require'
/home/runner/work/mushroom-observer/mushroom-observer/app/models/comment.rb:115:in `<class:Comment>'
/home/runner/work/mushroom-observer/mushroom-observer/app/models/comment.rb:107:in `<top (required)>'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/zeitwerk-2.7.1/lib/zeitwerk/core_ext/kernel.rb:26:in `require'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activesupport-7.2.2.1/lib/active_support/inflector/methods.rb:290:in `const_get'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activesupport-7.2.2.1/lib/active_support/inflector/methods.rb:290:in `constantize'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activesupport-7.2.2.1/lib/active_support/inflector/methods.rb:316:in `safe_constantize'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activesupport-7.2.2.1/lib/active_support/core_ext/string/inflections.rb:87:in `safe_constantize'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:803:in `default_fixture_model_class'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:793:in `block (2 levels) in read_fixture_files'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixture_set/file.rb:16:in `open'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:791:in `block in read_fixture_files'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:790:in `each'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:790:in `each_with_object'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:790:in `read_fixture_files'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:721:in `initialize'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:653:in `new'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:653:in `block in read_and_insert'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:651:in `map'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:651:in `read_and_insert'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/fixtures.rb:607:in `create_fixtures'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/railties/databases.rake:434:in `block (3 levels) in <top (required)>'
/home/runner/work/mushroom-observer/mushroom-observer/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
/opt/hostedtoolcache/Ruby/3.3.6/x64/bin/bundle:25:in `load'
/opt/hostedtoolcache/Ruby/3.3.6/x64/bin/bundle:25:in `<main>'
Tasks: TOP => db:fixtures:load
```
@JoeCohen JoeCohen marked this pull request as ready for review February 15, 2025 20:02
@JoeCohen
Copy link
Member Author

  • @mo-nathan, @nimmolo, @pellaea: rails db:migrate and/or rails db:load throw an Error if a validates macro includes a translated message, e.g. :symbol.t. In a perfect world that wouldn't happen. I left it as-is because:
    (1) A fix -- if one is possible -- is too deep for me. The issue is related to our .t extension and to how/when files get loaded. See the note in app/extensions/extensions.rb.
    (2) There's an easy work-around.
    I don't think it's worth anyone's time unless there's an easy, instant fix.
  • @mo-nathan @pellaea . Should we allow brackets in author? The PR precludes them, and that makes it easier to find things. But it's unclear if the ICN precludes brackets. We had one bracketed author Name in the db, https://mushroomobserver.org/names/46228/versions?version=3, but I changed it to remove the brackets.
    MB has brackets, IF does not..
  • We should consider doing more validations in the model.
    • It gets both the UI & API with one validation.
    • It's more Rails-conventional.
    • In many cases it nicely highlights the affected field in the model form.

@nimmolo
Copy link
Contributor

nimmolo commented Feb 20, 2025

Seems good to me. In favor of more validations on the model.

The class needs refactoring. A lot of Name modules can easily be broken off into POROs.

- Add an assertion
- Fix a comment
- Improve some assert messages
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.

Indistinct search_names
3 participants