Shopify / tapioca

The swiss army knife of RBI generation
MIT License
728 stars 121 forks source link

Handle deferred route drawing in URL helpers DSL compiler #1899

Closed bravehager closed 4 months ago

bravehager commented 4 months ago

Motivation

The URL helpers DSL compiler appears broken after https://github.com/rails/rails/commit/e97db3b3957781c781a61fb01265feb2b57688bb introduced deferred route drawing.

This leads to all helper methods being stripped from GeneratedUrlHelpersModule and GeneratedPathHelpersModule.

Implementation

Ensure routes are loaded before generating GeneratedUrlHelpersModule and GeneratedPathHelpersModule.

Tests

I was able to manually test this out in one of our Rails applications at @justworkshr.

Open to any ideas on how to unit test this behavior—it seems like the existing tests pass despite the change in Rails itself.

andyw8 commented 4 months ago

Thanks! Wondering if we need a test for this... it seems fairly low risk. @egiurleo?

egiurleo commented 4 months ago

The UrlHelpersSpec tests don't even seem to fail when running them with Rails main (RAILS_VERSION=main bundle install && bin/test spec/tapioca/dsl/compilers/url_helpers_spec.rb). I've been trying to write a integration test for this but I think it would require pretty significant changes to the DSL integration spec, which doesn't seem worth it.

I'm testing against Shopify core to make sure this doesn't break anything.