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

Fix plugin generation inside applications #46074

Merged
merged 1 commit into from
Sep 21, 2022

Conversation

skipkayhil
Copy link
Member

Motivation / Background

Previously, generating a plugin inside an application would throw an error when trying to create a dummy_app due to the generator trying to reuse the application's name.

Detail

This is fixed by extracting the logic used to determine the source of an application's name, and then only using the existing name as the source for the app:update and db:change tasks.

Additional information

Closes #45824
Fixes #18073

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • There are no typos in commit messages and comments.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Feature branch is up-to-date with main (if not - rebase it).
  • Pull request only contains one commit for bug fixes and small features. If it's a larger feature, multiple commits are permitted but must be descriptive.
  • Tests are added if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.
  • PR is not in a draft state.
  • CI is passing.

@rails-bot rails-bot bot added the railties label Sep 20, 2022
@rafaelfranca
Copy link
Member

We have a failing test because of this change. Can you take a look?

@skipkayhil skipkayhil force-pushed the fix-app-plugin-generation-2 branch 2 times, most recently from 1a3c460 to 499770b Compare September 20, 2022 21:10
Previously, generating a plugin inside an application would throw an
error when trying to create a dummy_app due to the generator trying to
reuse the application's name.

This is fixed by extracting the logic used to determine the source of an
application's name, and then only using the existing name as the source
for the app:update task.
@@ -79,7 +79,7 @@ class ChangeGeneratorTest < Rails::Generators::TestCase

assert_file("config/database.yml") do |content|
assert_match "adapter: mysql2", content
assert_match "database: test_app", content
assert_match "database: tmp_production", content
Copy link
Member Author

@skipkayhil skipkayhil Sep 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a real application, Rails.application throws a NoMethodError inside the Change Generator (bin/rails db:system:change). So instead of keeping the Rails.application.class... || File.basename for the Change Generator I think it makes more sense for the tests to reflect the real behavior (always File.basename, which is /tmp for these tests)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how was this passing before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Rails.application.class... path was hit before because the generator test requires generators/generators_test_helper -> abstract_unit which requires rails/all and defines TestApp::Application -> sets Rails.application.

In the bin_setup_test/real application case, config/application.rb is never required during bin/rails db:system:change so it never sets Rails.application.

@rafaelfranca rafaelfranca merged commit fa7b3fe into rails:main Sep 21, 2022
@skipkayhil skipkayhil deleted the fix-app-plugin-generation-2 branch September 21, 2022 22:56
zzak added a commit to zzak/turbo-rails that referenced this pull request Apr 19, 2024
My hunch is that this was fixed in Rails 7.1 by rails/rails#46074, but I'm less concerned here because this test suite uses a Dummy app for all of the tests.

This is a problem I've been working on in rails/rails#50427, to remove the dummy applications and replace them with a generated app like we've done here with the installer test.

I'm happy to investigate replacing the dummy app here afterwards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"rails generate plugin gems/engine --full" fails at vendor_app test/dummy
2 participants