Fix ArgumentError when filtering by scopes with array arguments#1590
Merged
scarroll32 merged 4 commits intomainfrom Sep 24, 2025
Merged
Fix ArgumentError when filtering by scopes with array arguments#1590scarroll32 merged 4 commits intomainfrom
scarroll32 merged 4 commits intomainfrom
Conversation
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Filtering by scopes with an array as an argument raises ArgumentError
Fix ArgumentError when filtering by scopes with array arguments
Sep 24, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an ArgumentError that occurred when filtering by scopes with array arguments in Ransack, specifically for scopes with arity 1 that expect an array as a single parameter. The fix adds special handling to prevent incorrect array splatting while maintaining backwards compatibility.
- Added conditional logic to handle scopes with arity 1 receiving array arguments
- Added comprehensive test coverage for various scope arity scenarios
- Maintained backwards compatibility with existing workarounds
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/ransack/context.rb | Added special case handling for arity 1 scopes to pass arrays as single arguments instead of splatting |
| spec/ransack/search_spec.rb | Added comprehensive test coverage for array argument handling across different scope arities |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #XXX where filtering by scopes that accept arrays as single arguments would raise
ArgumentError: wrong number of arguments (given 2, expected 1).Problem
When using scopes with arity 1 that expect an array as a single parameter, Ransack would incorrectly splat the array arguments, causing argument count mismatches:
Root Cause
The
chain_scopemethod inlib/ransack/context.rbwas always using the splat operator (*args) when calling scopes, regardless of the scope's arity. For scopes expecting a single array argument, this would split['US', 'JP']into two separate arguments'US', 'JP', violating the lambda's arity constraint.Solution
Added special handling in
chain_scopeto detect when a scope has arity 1 and receives an array argument. In this case, the array is passed as a single argument instead of being splatted:Testing
Added comprehensive test coverage for various scope arity scenarios:
Impact
Person.search(domestic: ['US', 'JP'])now worksThis change makes Ransack's scope handling more intuitive and eliminates the need for users to understand lambda arity details when using array arguments with scopes.
Fixes #404
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.