JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
NameError: uninitialized constant JSONAPI::ResourceController in Rails 7.1
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
This issue is a (choose one):
- Problem/bug report.
- Feature request.
- Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.
Checklist before submitting:
- I've searched for an existing issue.
- I've NOT asked my question on Gitter because Gitter seems to be abandoned by the core team. There a lots of questions posted there that have no responses at all.
- I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
- The feature I'm asking for is compliant with the JSON:API spec.
Description
In trying to update to Rails 7.1 I'm running into random instances of this error when running my test suite.
Error:
Jsonapi::V1::TeamProjectsControllerTest#test_should_not_create_for_a_forbidden_team:
NameError: uninitialized constant JSONAPI::ResourceController
app/controllers/jsonapi/v1/base_controller.rb:3:in `<main>'
app/controllers/jsonapi/v1/team_projects_controller.rb:1:in `<main>'
test/controllers/jsonapi/v1/team_projects_controller_test.rb:126:in `block in <class:TeamProjectsControllerTest>'
Sometimes there will be 2 of them, other times 20 or 30.
Via some trial and error I discovered that if I alter my BaseController to look like this:
class Jsonapi::V1::BaseController < ActionController::Base
include JSONAPI::ActsAsResourceController
# ...
end
Instead of this:
class Jsonapi::V1::BaseController < JSONAPI::ResourceController
# ...
end
then the random errors go away.
I also noticed that these errors were only happening locally, and not in CI, and so I tried setting config.eager_load = true in config/environments/test.rb which also made the errors go away.
I poked around this gem a little bit and I think that this block of code isn't exactly working as expected in Rail 7.1.
Ruby: 3.3.6
Rails: 7.1.5.1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/jsonapi-resources.rb lines 12-18 and the loading path used by app/controllers/jsonapi/v1/base_controller.rb. Reproduce the intermittent failure through test/controllers/jsonapi/v1/team_projects_controller_test.rb under Ruby 3.3.6 and Rails 7.1.5.1. Done means the test suite no longer raises the uninitialized constant error without requiring eager loading or the reported controller workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100