-
Notifications
You must be signed in to change notification settings - Fork 57
[1422] Create helper method to check ENV variables #1583
base: master
Are you sure you want to change the base?
Conversation
@@ -1,19 +1,19 @@ | |||
staging: | |||
adapter: mysql2 | |||
encoding: utf8 | |||
database: <%= ENV['RES_DB_NAME'] %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are pulling in the values themselves, not just checking them as booleans, so they shouldn't be replaced.
I like how this was implemented; that said, I started going through this and found a bunch of places where the custom method was used incorrectly (e.g. assigning things to variables vs checking a boolean). I also think we should figure out a better place to put the helper method, so let's chat about the latter point and why don't you do a quick pass through this to check for any other cases where you replaced an |
Ah, the dangers of using |
@@ -5,7 +5,7 @@ PartyFoul.configure do |config| | |||
['ActiveRecord::RecordNotFound', 'ActionController::RoutingError'] | |||
|
|||
# The OAuth token for the account that is opening the issues on GitHub | |||
config.oauth_token = ENV['PARTY_FOUL_TOKEN'] | |||
config.oauth_token = env?('PARTY_FOUL_TOKEN') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no helper
Okay, ready for rereview! |
@@ -1,3 +1,4 @@ | |||
include EnvironmentHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is how it gets included everywhere--I'm not sure if this is the best solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put it in its own initializer - they run in alphabetical order so I'd call it something like config/initializers/000_env_helper.rb
or whatever will place it before the Devise initializer.
A few more inline comments, I'm particularly concerned by |
c206d50
to
efb539f
Compare
1521dd9
to
5e132f4
Compare
Pushed an update resolving the issues with the production config. I think this will be good to merge after the build passes |
So basically we should remove the change from #1618 when this is merged in and instead add a committed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things need to be fixed here, and I think we should probably include an empty string as "falsey". Let me know what you think!
@@ -24,7 +26,7 @@ | |||
|
|||
# Disable serving static files from the `/public` folder by default since | |||
# Apache or NGINX already handles this. | |||
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? | |||
config.serve_static_files = !FALSE.include?(ENV['RAILS_SERVE_STATIC_FILES']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be ENV_FALSE.include?
? Same below
@@ -1,5 +1,7 @@ | |||
# frozen_string_literal: true | |||
Rails.application.configure do | |||
ENV_FALSE = [0, '0', false, 'false', nil].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also include an empty string?
@@ -77,7 +79,8 @@ | |||
# config.action_controller.asset_host = 'http://assets.example.com' | |||
|
|||
# Disable e-mails if environment variable is set | |||
config.action_mailer.perform_deliveries = ENV['DISABLE_EMAILS'].nil? | |||
config.action_mailer.perform_deliveries = \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this should be inverted.
@@ -0,0 +1,8 @@ | |||
# frozen_string_literal: true | |||
module EnvironmentHandler | |||
FALSE = [0, '0', false, 'false', nil].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, do we want to include an empty string?
include EnvironmentHandler | ||
|
||
describe EnvironmentHandler do | ||
describe '.env?' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated above, I think that we should include an empty string as being "falsey". We should also add a test for that.
FYI, this also needs to be rebased. |
5e132f4
to
771dbbe
Compare
updated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the specs for the seed generators is failing and I think there's also one inverted env?
call. Once those two are resolved we should be good to go. It would probably also be good if you could do one more complete read-through to make sure I didn't miss any other inversions that aren't handled by testing.
@@ -18,7 +18,7 @@ | |||
end | |||
# if we want to use password authentication all users can reset their | |||
# passwords so it doesn't matter if they already have them or not | |||
elsif ENV['CAS_AUTH'].nil? && user && (user.username != user.email) | |||
elsif env?('CAS_AUTH') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be inverted?
Resolves #1422