-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: extension:test_app
rake task should detect if Solidus engines are available
#4302
Fix: extension:test_app
rake task should detect if Solidus engines are available
#4302
Conversation
0906996
to
2b33feb
Compare
@@ -24,7 +24,7 @@ | |||
begin | |||
require "generators/#{ENV['LIB_NAME']}/install/install_generator" | |||
puts 'Running extension installation generator...' | |||
"#{ENV['LIB_NAMESPACE'] || ENV['LIB_NAME'].camelize}::Generators::InstallGenerator".constantize.start(["--auto-run-migrations"]) | |||
sh "bin/rails generate #{ENV['LIB_NAMESPACE']&.underscore || ENV['LIB_NAME']}:install --auto-run-migrations" |
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.
Hi @mdesantis! I saw that you introduced LIB_NAMESPACE
in #3161. Am I correct in assuming that its value can be underscored and prefixed in the <extension>:install
generator call? For example, with LIB_NAMESPACE=SolidusGraphQL
, the resulting call would be:
bin/rails generate solidus_graph_ql:install --auto-run-migrations
I haven't had time to test this today, but I'll test this tomorrow.
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.
@mdesantis I have just noticed now that you're no longer working with Nebulab. You can ignore my question earlier :)
@waiting-for-dev @kennyadsl Unfortunately, I wasn't able to get ENV['LIB_NAMESPACE']
to work with this change. I tested ENV['LIB_NAMESPACE']
against my SolidusHelloWorld extension by renaming the generator's module from SolidusHelloWorld::Generators::InstallGenerator
to UpdatedSolidusHelloWorld::Generators::InstallGenerator
:
solidus_hello_world 17:41:51 $ git diff HEAD
diff --git a/lib/generators/solidus_hello_world/install/install_generator.rb b/lib/generators/solidus_hello_world/install/install_generator.rb
index 65d613c..0802fe5 100644
--- a/lib/generators/solidus_hello_world/install/install_generator.rb
+++ b/lib/generators/solidus_hello_world/install/install_generator.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module SolidusHelloWorld
+module UpdatedSolidusHelloWorld
module Generators
class InstallGenerator < Rails::Generators::Base
class_option :auto_run_migrations, type: :boolean, default: false
I then tried to create the test app as follows:
LIB_NAMESPACE=UpdatedSolidusHelloWorld bundle exec rake extension:test_app
However, Rails is not able to find the generator:
solidus_hello_world 17:38:39 $ LIB_NAMESPACE=UpdatedSolidusHelloWorld bundle exec rake extension:test_app
Generating dummy Rails application...
create config/master.key
Copied migration 20220317093906_create_active_storage_tables.active_storage.rb from active_storage
Created database 'db/solidus_test.sqlite3'
Setting up dummy database...
bin/rails db:environment:set RAILS_ENV=test
bin/rails db:drop db:create db:migrate VERBOSE=false RAILS_ENV=test
Running extension installation generator...
bin/rails generate updated_solidus_hello_world:install --auto-run-migrations
Could not find generator 'updated_solidus_hello_world:install'.
Run `bin/rails generate --help` for more options.
cd /home/gsmendoza/repos/gsmendoza/solidus_hello_world
Is there any reason to keep the LIB_NAMESPACE
environment variable? The variable was introduced in #3161 to allow the test_app
task to work with the SolidusGraphQL
module name. However, the GraphQL extension is already using the more Inflector-friendly module name SolidusGraphqlApi
(https://github.com/solidusio-contrib/solidus_graphql_api).
The following searches in the solidusio and solidusio-contrib orgs also do not show any Code results for LIB_NAMESPACE
:
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.
If unused, we can definitely remove LIB_NAMESPACE
from here.
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.
Hey @gsmendoza, I wonder if that didn't work because you didn't rename the directory solidus_hello_world
to updated_solidus_hello_world
. If that works, I think it can be helpful to leave a way out from the default inferred name.
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.
Hi @waiting-for-dev! I've confirmed that if we make this additional change to common:test_app
, we can continue to use LIB_NAMESPACE
:
# core/lib/spree/testing_support/common_rake.rb
# ...
begin
# Add `ENV['LIB_NAMESPACE']&.underscore` in the line below:
require "generators/#{ENV['LIB_NAMESPACE']&.underscore || ENV['LIB_NAME']}/install/install_generator"
puts 'Running extension installation generator...'
sh "bin/rails generate #{ENV['LIB_NAMESPACE']&.underscore || ENV['LIB_NAME']}:install --auto-run-migrations"
rescue LoadError
# No extension generator to run
end
# ...
However, in the SolidusHelloWorld extension, we'll need to make the following corresponding changes:
- Rename the module for the generator, e.g. from
SolidusHelloWorld::Generators::InstallGenerator
toUpdatedSolidusHelloWorld::Generators::InstallGenerator
. - Rename the generator directory e.g. from
lib/generators/solidus_hello_world
tolib/generators/updated_solidus_hello_world
.
I intend to continue with the update to the require statement, since it provides a way to continue using the LIB_NAMESPACE
variable.
Let me know if you have additional thoughts!
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.
Great, @gsmendoza! Thanks for looking into it.
…are available Acceptance criteria ------------------- Given a Solidus extension calls `SolidusSupport.x_available?` in its Install generator to check if the engine is available When the I run `bundle exec rake extension:test_app` Then the `SolidusSupport.x_available?` should return true (since the dummy app installed by `extension:test_app` includes the frontend, backend, and api engines) Bug description --------------- When called within `bundle exec rake extension:test_app`, the install generator of the extension is not able to detect the Solidus engines within the dummy app, and as such, returns nil for any `SolidusSupport.x_available?` call. Cause ----- The `<Extension>::Generators::InstallGenerator.start` call within the `common:test_app` rake task is not able to detect the Solidus engines that were just installed by the rake task to the spec/dummy directory. Bug fix ------- Use the `bin/rails` executable to install the extension on the dummy app. Possibly related issues ----------------------- solidusio/solidus_support#66
2b33feb
to
9389844
Compare
@waiting-for-dev I've updated the PR. You can check my test at the "2022-03-22 Update" section under the PR's description. |
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.
Thanks, @gsmendoza !
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.
Looks good. Left a non-blocking question. Thanks!
Prior to solidusio#4302, `camelize` was called on the `LIB_NAME` value which converts `/` to `::`. This behaviour worked for namespaced extensions because we were invoking the class directly, instead of through the `bin/rails` bin stub. To fix this, we convert to a "rake style" namespace by replacing `/` with `:`. Co-authored-by: Chris Todorov <chris@super.gd> Co-authored-by: Adam Mueller <adam@super.gd>
Prior to solidusio#4302, `camelize` was called on the `LIB_NAME` value which converts `/` to `::`. This behaviour worked for namespaced extensions because we were invoking the class directly, instead of through the `bin/rails` bin stub. To fix this, we convert to a "rake style" namespace by replacing `/` with `:`. Co-authored-by: Chris Todorov <chris@super.gd> Co-authored-by: Adam Mueller <adam@super.gd>
Prior to solidusio#4302, `camelize` was called on the `LIB_NAME` value which converts `/` to `::`. This behaviour worked for namespaced extensions because we were invoking the class directly, instead of through the `bin/rails` bin stub. To fix this, we convert to a "rake style" namespace by replacing `/` with `:`. Co-authored-by: Chris Todorov <chris@super.gd> Co-authored-by: Adam Mueller <adam@super.gd>
Prior to solidusio#4302, `camelize` was called on the `LIB_NAME` value which converts `/` to `::`. This behaviour worked for namespaced extensions because we were invoking the class directly, instead of through the `bin/rails` bin stub. To fix this, we convert to a "rake style" namespace by replacing `/` with `:`. Co-authored-by: Chris Todorov <chris@super.gd> Co-authored-by: Adam Mueller <adam@super.gd>
Acceptance criteria
Given a Solidus extension calls
SolidusSupport.x_available?
in itsInstall generator to check if the engine is available
When the I run
bundle exec rake extension:test_app
Then the
SolidusSupport.x_available?
should return true (since the dummyapp installed by
extension:test_app
includes the frontend, backend, andapi engines)
Bug description
When called within
bundle exec rake extension:test_app
, the installgenerator of the extension is not able to detect the Solidus engines
within the dummy app, and as such, returns nil for any
SolidusSupport.x_available?
call.Demonstration
2022-03-22 Original
eng-316-fix-extensiontest_app-rake-task-should-demo-2022-03-16.mp4
2022-03-22 Update
eng-316-fix-extensiontest_app-rake-task-should-v2.mp4
You can find the SolidusHelloWorld extension at https://github.com/gsmendoza/solidus_hello_world.
Cause
The
<Extension>::Generators::InstallGenerator.start
call within thecommon:test_app
rake task is not able to detect the Solidus engines thatwere just installed by the rake task to the spec/dummy directory.
Bug fix
Use the
bin/rails
executable to install the extension on the dummy app.Possibly related issues
solidusio/solidus_support#66
Checklist