amatsuda / jb

A simple and fast JSON API template engine for Ruby on Rails
MIT License
1.29k stars 43 forks source link

Deprecation warning with generators in Rails 6.0.2 #31

Closed peterxjang closed 4 years ago

peterxjang commented 4 years ago

In Rails 6.0.2, running any rails generate commands with the jb gem installed results in this deprecation warning:

Deprecation warning: Expected string default value for '--jb'; got true (boolean).
This will be rejected in the future unless you explicitly pass the options `check_default_type: false` or call `allow_incompatible_default_type!` in your code
You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.

I believe this issue is coming from the scaffold generator controller: https://github.com/amatsuda/jb/blob/master/lib/generators/rails/scaffold_controller_generator.rb. For some reason Rails 6.0.2 is expecting a string value here. This issue did not occur on Rails 6.0.1 or any other prior versions as far as I know.

I was able to eliminate the deprecation warning by adding the line config.generators.jb = "true" in my config/application.rb file, which is providing a string value as opposed to a boolean. However, I'm not sure if that's the correct approach, setting it to "true" or "false" didn't seem to have an effect on the generator functionality, although I didn't test every scenario. Any thoughts are appreciated, thanks!

amatsuda commented 4 years ago

@peterxjang Thank you so much for letting me know the issue! What was happening is that Thor 1.0 introduced a stricter type checking for default value via https://github.com/erikhuda/thor/commit/7d199c0367997939857a3c3d96209515239989e3 and it caused this warning even on existing Rails apps.

I just fixed the issue via 3fa34a285340939f8614564e62eaebfed816f866 and published version 0.7.1 gem with this fix.