-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for class_methods do
blocks within concerns
#530
Conversation
@@ -24,14 +24,42 @@ def setup | |||
|
|||
test "ClassMethods module inside concerns are automatically extended" do | |||
@index.index_single(RubyIndexer::IndexablePath.new(nil, "/fake.rb"), <<~RUBY) | |||
class Post < ActiveRecord::Base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this so that all the code is visible in the tests, rather than having to know what Rails does internally.
03ab84f
to
bae514c
Compare
bae514c
to
fcd8236
Compare
@vinistock I need to do some more manual verification, but opening for any feedback so far. |
fcd8236
to
fcc6515
Compare
Converting to draft until I have a a change to look into the test failures. |
1bbc5ce
to
d6c4f17
Compare
The code looks good to me. Not sure about the test failures, but after a rebase it might be easier to understand what's going on. |
e76beed
to
6f022bd
Compare
6f022bd
to
455b7aa
Compare
# For these tests, it's convenient to have the index fully populated with Rails information. | ||
# Reindexing each time is slow, but prevents state leaking between tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is inconsistent with the implementation. While it states that reindexing is slow and implies it's being avoided, the code actually reindexes on every test for better isolation. Consider updating the comment to: "Reindex before each test to prevent state leakage between tests, accepting the performance cost for better test isolation."
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
The issue with the tests is that we're reusing the same names. All examples in this test share the same index instance because the initial indexing takes too long. Just change the names of the modules and classes involved for each example so that the state doesn't leak between tests. |
def populated_index | ||
@index ||= begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vinistock avoiding the memoization solves in test instability here. It's obviously slower though.
A few possible alternatives:
- Have each test be responsible to removing things it added to the index (maybe compare the state before and after in a
teardown
to ensure clean-up isn't forgotten) - Have some naming convention for things we use in tests, and have them automatically removed from the index in a
teardown
. - Have a way to skip indexing of RBS in
index_all
(which takes a large portion of the test time).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we just add note to the test and use different names in each example? Trying to clean up all of the index state might be difficult and it will require exposing some internal APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually scratch that. We already have an API to delete entries, let's use that on teardown.
455b7aa
to
9554f2d
Compare
Closes #525
Depends on #529
Here are the new places in Rails we now find: