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

Adding an error message during 'administrate' initialize when there are no models in db. #1782

Merged
merged 24 commits into from
Oct 31, 2020
Merged

Adding an error message during 'administrate' initialize when there are no models in db. #1782

merged 24 commits into from
Oct 31, 2020

Conversation

KOlofinmoyin
Copy link
Contributor

@KOlofinmoyin KOlofinmoyin commented Oct 5, 2020

This PR fixes the behaviour observed, during the administrate install on rails apps without models, where the admin route isn't created, resulting in an application error and no warning to the user.

The change displays a friendly error message, when this happens.

@@ -10,6 +10,12 @@ class InstallGenerator < Rails::Generators::Base

class_option :namespace, type: :string, default: "admin"

def model_check
if database_models.none?
puts "ERROR: Unable to generate a dashboard without models."
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about phrasing it something like: "Add models before installing Administrate" or similar?

I'm thinking that we want to just say that you can't have Administrate at all without models, which is broadly true and covers the cases where someone is trying to install Administrate before creating the first model which is a common first-use error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that is a better phrase, also as the check doesn't stop the rest of the generator trying to run (which could be done) maybe adding blank lines above and below to make it standout?

Copy link
Member

Choose a reason for hiding this comment

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

We could exit after the error. Is there anything in Rails' existing generators which behaves in a similar way?

Copy link
Member

Choose a reason for hiding this comment

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

I was initially wondering if we should actually be writing to standard error, but a quick search around didn't seem to find that being used for generators (but I might've just looked in bad places.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't find any other example of a generator exiting... so exit could be the best solution.

I think a puts error would be fine, especially if its the last output on the CL

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, sounds good!

@nickcharlton nickcharlton added feature new functionality that’s not yet implemented install initial setup, first-run experience, generators labels Oct 6, 2020
Copy link
Collaborator

@pablobm pablobm left a comment

Choose a reason for hiding this comment

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

This looks almost ready now. Just two things:

  1. The tests are failing because of a security advisory on a dependency. They should pass if you rebase.
  2. Make sure to correct the linter warnings raised by Hound.

lib/generators/administrate/install/install_generator.rb Outdated Show resolved Hide resolved
Copy link
Collaborator

@pablobm pablobm left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@hound hound bot deleted a comment from pablobm Oct 31, 2020
@pablobm pablobm merged commit 8408423 into thoughtbot:master Oct 31, 2020
@pablobm
Copy link
Collaborator

pablobm commented Oct 31, 2020

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new functionality that’s not yet implemented install initial setup, first-run experience, generators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants