Fix ActiveRecordScope Compiler to not duplicate relation methods of superclass #1453
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.
Motivation
We encountered a strange situation where CI was reporting that a rbi file has changed and needs to be regenerated, but running
bin/tapioca dsl
locally on the dev environment would not generate any changes.It seems on the CI build, a method in one of the rbi files is generated twice while on dev environment not, leading to CI failing all the time we regenerate the rbis. It is unclear why this is happening, the same version of tapioca is used in both cases and there is no obvious reason why it is happening.
As a workaround we had to undo the changes to that rbi file on each branch, leading to confusion within the team.
After investigation I found that the ActiveRecordScope Compiler gathers scope methods until it hits "ActiveRecord::Base" and concatenates the methods in an array. The problem is it does not remove duplicates, if a method is defined twice along the class hierarchy chain.
Given the class hierarchy
Before this PR:
After this PR:
Implementation
Removed duplicates from ActiveRecordScope Compiler while gathering scope methods of the class hierarchy chain.
Tests
Added a test that asserts that no methods defined twice in the class hierarchy are duplicated in the rbi file.