Skip to content
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

Merged
merged 10 commits into from
Nov 21, 2024

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Nov 19, 2024

Closes #525

Depends on #529

Here are the new places in Rails we now find:

ActionMailbox::Callbacks
ActionMailbox::Routing
ActionMailer::Rescuable
ActionText::Attachable
ActionText::Attachments::Minification
ActionText::Attachments::TrixConversion
ActionText::Attribute
ActionText::Rendering
ActionText::Serialization
ActionText::Serialization
ActiveRecord::ConnectionAdapters::ColumnMethods
ActiveRecord::Encryption::Configurable
ActiveRecord::Encryption::Contexts
ActiveRecord::Encryption::EncryptableRecord
ActiveRecord::Encryption::ExtendedDeterministicQueries::CoreQueries
ActiveStorage::Attached::Model
Rails::Command::Behavior

@@ -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
Copy link
Contributor Author

@andyw8 andyw8 Nov 19, 2024

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.

@andyw8 andyw8 force-pushed the andyw8/class-methods-block branch 2 times, most recently from 03ab84f to bae514c Compare November 19, 2024 22:32
@andyw8 andyw8 marked this pull request as ready for review November 19, 2024 22:34
@andyw8 andyw8 requested a review from a team as a code owner November 19, 2024 22:34
@andyw8
Copy link
Contributor Author

andyw8 commented Nov 19, 2024

@vinistock I need to do some more manual verification, but opening for any feedback so far.

@andyw8 andyw8 marked this pull request as draft November 20, 2024 19:48
@andyw8
Copy link
Contributor Author

andyw8 commented Nov 20, 2024

Converting to draft until I have a a change to look into the test failures.

@andyw8 andyw8 force-pushed the andyw8/update-enhancements-api branch 2 times, most recently from 1bbc5ce to d6c4f17 Compare November 21, 2024 12:56
Base automatically changed from andyw8/update-enhancements-api to main November 21, 2024 17:30
@vinistock
Copy link
Member

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.

Comment on lines 10 to 11
# 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.
Copy link

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.

@vinistock
Copy link
Member

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
Copy link
Contributor Author

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).

Copy link
Member

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.

Copy link
Member

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.

@andyw8 andyw8 marked this pull request as ready for review November 21, 2024 20:12
@andyw8 andyw8 enabled auto-merge (squash) November 21, 2024 20:31
@andyw8 andyw8 merged commit 72c85a9 into main Nov 21, 2024
28 checks passed
@andyw8 andyw8 deleted the andyw8/class-methods-block branch November 21, 2024 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle class_methods do blocks for concerns
2 participants