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: extension:test_app rake task should detect if Solidus engines are available #4302

Conversation

gsmendoza
Copy link
Contributor

@gsmendoza gsmendoza commented Mar 16, 2022

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.

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

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • N/A - I have updated Guides and README accordingly to this change (if needed)
  • N/A - I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@gsmendoza gsmendoza force-pushed the gsmendoza/eng-316-fix-extensiontest_app-rake-task-should branch from 0906996 to 2b33feb Compare March 16, 2022 10:31
@gsmendoza gsmendoza marked this pull request as ready for review March 16, 2022 10:31
@gsmendoza gsmendoza marked this pull request as draft March 16, 2022 10:35
@@ -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"
Copy link
Contributor Author

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.

Copy link
Contributor Author

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:

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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:

  1. Rename the module for the generator, e.g. from SolidusHelloWorld::Generators::InstallGenerator to UpdatedSolidusHelloWorld::Generators::InstallGenerator.
  2. Rename the generator directory e.g. from lib/generators/solidus_hello_world to lib/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!

Copy link
Contributor

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.

@gsmendoza gsmendoza marked this pull request as ready for review March 17, 2022 00:44
@gsmendoza gsmendoza marked this pull request as draft March 17, 2022 00:44
…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
@gsmendoza gsmendoza force-pushed the gsmendoza/eng-316-fix-extensiontest_app-rake-task-should branch from 2b33feb to 9389844 Compare March 22, 2022 06:13
@gsmendoza gsmendoza marked this pull request as ready for review March 22, 2022 06:45
@gsmendoza
Copy link
Contributor Author

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

Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @gsmendoza !

Copy link
Member

@kennyadsl kennyadsl left a 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!

core/lib/spree/testing_support/common_rake.rb Outdated Show resolved Hide resolved
@waiting-for-dev waiting-for-dev merged commit 564b4fe into solidusio:master Mar 25, 2022
mamhoff pushed a commit to mamhoff/solidus that referenced this pull request Apr 19, 2022
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>
rmparr pushed a commit to rmparr/solidus that referenced this pull request Jun 1, 2022
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>
rmparr pushed a commit to rmparr/solidus that referenced this pull request Jun 1, 2022
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>
cpfergus1 pushed a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
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>
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.

3 participants