Add failing tests for polymorphic filtering inconsistency with OR conditions #1596
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.
This PR adds comprehensive failing tests to reproduce the polymorphic filtering inconsistency issue described in the original GitHub issue.
Problem
When using Ransack to filter records with OR conditions between polymorphic foreign keys, the query fails with:
This is inconsistent because:
Message.ransack(from_id_eq: '123')
Message.ransack(id_or_from_id_or_to_id_eq: '123')
Test Model Added
Test Cases
Failing Cases (should work but raise errors):
from_id_or_to_id_eq
- Core issue from GitHub reportto_id_or_from_id_eq
- Reverse order variationuser_id_or_from_id_eq
- Mixed regular/polymorphic FKWorking Cases (demonstrate the inconsistency):
from_id_eq
- Single polymorphic FK worksid_or_from_id_or_to_id_eq
- Workaround mentioned in issue worksuser_id_or_id_eq
- No polymorphic FKs involved worksFiles Added
spec/ransack/adapters/active_record/polymorphic_spec.rb
- Comprehensive RSpec test suitespec/support/schema.rb
- Added Message model and database schemaspec/blueprints/messages.rb
- Blueprint factory for Message modeltest_polymorphic_issue.rb
- Simple standalone test runnerPOLYMORPHIC_ISSUE_README.md
- Detailed documentation and reproduction stepsExpected Behavior
OR conditions between polymorphic foreign keys should work just like regular foreign keys since we're only filtering by ID values without needing polymorphic class computation. The behavior should be consistent with single polymorphic FK filtering that already works correctly.
These tests will serve as the foundation for implementing a fix for this inconsistency.
Additional instructions:
Fixes #1267
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.