RailsApps / rails_apps_composer

A gem with recipes to create Rails application templates for Rails starter apps.
http://railsapps.github.io/rails_apps_composer/
1.42k stars 306 forks source link

prefs[:pref] = config['pref'] unless config['pref'] == 'none' #349

Closed vfonic closed 8 years ago

vfonic commented 8 years ago

For some strange reason, when using double equal, and defaults.yml, the following command resolved prefs[:pref] to 'none':

prefs[:pref] = config['pref'] unless config['pref'] == 'none'

While this works just fine:

prefs[:pref] = config['pref'] unless config['pref'] = 'none'

defaults.yml:

prefs:
  :pref: true

I guess the issue is due to prefs[:admin] being set, but we're checking config['admin']. When config['admin'] == 'none' is false we set prefs[:admin] which is wrong.

Here are two examples, one with single equals sign, one with two: https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/admin.rb#L4

https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/extras.rb#L76

EDIT: Digging deeper, here's what I've found out:

say_wizard "config['admin'] = '#{config['admin']}' before"
say_wizard "prefer :admin, 'activeadmin' = '#{prefer :admin, 'activeadmin'}' before"

prefs[:admin] = config['admin'] unless config['admin'] = 'none'

say_wizard "config['admin'] = '#{config['admin']}' after"
say_wizard "prefer :admin, 'activeadmin' = '#{prefer :admin, 'activeadmin'}' after"

Outputs:

admin  config['admin'] = '' before
admin  prefer :admin, 'activeadmin' = 'true' before
admin  config['admin'] = 'none' after
admin  prefer :admin, 'activeadmin' = 'true' after

Double equals:

say_wizard "config['admin'] = '#{config['admin']}' before"
say_wizard "prefer :admin, 'activeadmin' = '#{prefer :admin, 'activeadmin'}' before"

prefs[:admin] = config['admin'] unless config['admin'] == 'none'

say_wizard "config['admin'] = '#{config['admin']}' after"
say_wizard "prefer :admin, 'activeadmin' = '#{prefer :admin, 'activeadmin'}' after"

Outputs:

admin  config['admin'] = '' before
admin  prefer :admin, 'activeadmin' = 'true' before
admin  config['admin'] = '' after
admin  prefer :admin, 'activeadmin' = 'false' after
DanielKehoe commented 8 years ago

Sorry, I'm really lost and confused. I merged an old pull request that refactored some conditionals. I think there was a typo: the single equal should be a double equal. Is that right? Is that what you've determined? Shall I make the single equal a double equal? I don't have time to investigate so if you can make a recommendation, I'll act on it.