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

Install Generator to Properly Install Engine in Host Apps #19

Merged
merged 4 commits into from
Oct 6, 2020

Conversation

adrianna-chang-shopify
Copy link
Contributor

@adrianna-chang-shopify adrianna-chang-shopify commented Sep 30, 2020

Closes: #16

Background

  • We want users to be able to easily set up their host app for use with our gem
  • Providing an install generator is IMO the best option, and can handle mounting the engine, running the migrations, and creating our initializer files (it's also the way I've seen other engines handle installation, such as devise)
  • Users will simply need to install the gem, and then perform rails g maintenance_tasks:install in order to complete the setup

Summary of Changes in this PR:

Implementing abstract_class in MaintenanceTasks::Task

  • Needed so that we exclude ApplicationTask from the list of tasks that are available to enqueue in the UI
  • Will allow users to specify other groupings of tasks if they'd like, and have them excluded from the UI

Implementing the install generator

  • Generator will mount the engine, copy and run migrations, create an initializer for our engine as well as a base ApplicationTask class
  • Testing the generator is a bit tricky because it requires a sample app to be set up to do things like mount the engine and run the migrations. To achieve this, I've basically copied the dummy app into a sample directory, and removed things we don't want. This test is slow because it needs to run db migrations. I think we need test coverage for this, so I'd argue that one slow test is manageable

To 🎩

  • Navigate to http://localhost:3000/maintenance_tasks

To test the install generator:

  • cd test/dummy
  • rm db/schema.rb config/initializers/maintenance_tasks.rb app/jobs/maintenance/application_task.rb
  • rails db:drop (so we can run the migrations)
  • rails g maintenance_tasks:install
    AFTER YOU'RE DONE
  • Remove the copied migration and recreate the db rails db:drop db:setup

@adrianna-chang-shopify adrianna-chang-shopify marked this pull request as ready for review October 2, 2020 17:35
Copy link
Member

@etiennebarrie etiennebarrie left a comment

Choose a reason for hiding this comment

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

Really nice!
We should also add that to the README so that people know to run that after adding the gem.

@adrianna-chang-shopify
Copy link
Contributor Author

@volmer this is ready for a look when you have a chance 😄

@adrianna-chang-shopify adrianna-chang-shopify force-pushed the install-generator-for-engine branch 2 times, most recently from d941149 to be5d91c Compare October 6, 2020 12:48
@adrianna-chang-shopify adrianna-chang-shopify merged commit 0beae44 into main Oct 6, 2020
@adrianna-chang-shopify adrianna-chang-shopify deleted the install-generator-for-engine branch October 6, 2020 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants