Fix rake task helpers polluting global namespace - #91
Conversation
Before, the `session` method (for example) would be redefined in the context of an RSpec request spec because the default definee in the block within the `namespace` call would be `main`, the global object. Additional context about default definees: https://blog.yugui.jp/entry/846
|
Another option is to define the methods in an external file/module, and only require them from within the task defs. That way they're only included when those tasks are actually run. |
|
Would you prefer that option? Willing to edit the PR if that's the case. |
|
@hibachrach I'm not one of the maintainers, so I can't speak for them or the project. However, moving the module(s) into an external file that is explicitly (and only) required when needed is the approach I use and recommend on my teams. As it stands in this PR, the What's more, then you can |
|
^ I agree with @jasonkarns |
Ported from graphiti-api/graphiti-rails#91, following the review there: the helpers move to their own file rather than being defined inside the rake namespace.
|
This is fixed in graphiti 2.0. graphiti-rails is merged into the 2.0 gem, so the rake tasks live at https://github.com/graphiti-api/graphiti/blob/beta/lib/tasks/graphiti.rake. Your commit is now in a different repo: graphiti-api/graphiti@0a41a60. I took @jasonkarns' suggestion from this thread and moved the helpers into their own file rather than defining them inside the |
# [2.0.0-beta.5](v2.0.0-beta.4...v2.0.0-beta.5) (2026-08-07) ### Bug Fixes * drop the relationship guard install notice ([c204312](c204312)) * keep rake task helpers out of the global namespace ([0a41a60](0a41a60)), closes [graphiti-api/graphiti-rails#91](graphiti-api/graphiti-rails#91) ### Features * add rspec matchers for resource relationships and attributes ([70525f7](70525f7)), closes [graphiti-api/graphiti_spec_helpers#14](graphiti-api/graphiti_spec_helpers#14) * let the resource generator name the controller ([6ea7141](6ea7141)), closes [graphiti-api/graphiti-rails#53](graphiti-api/graphiti-rails#53)
Before, the
sessionmethod (for example) would be redefined in thecontext of an RSpec request spec because the default definee in the
block within the
namespacecall would bemain, the global object.Additional context about default definees:
https://blog.yugui.jp/entry/846