Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

[1422] Create helper method to check ENV variables #1583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

esoterik
Copy link
Collaborator

Resolves #1422

@@ -1,19 +1,19 @@
staging:
adapter: mysql2
encoding: utf8
database: <%= ENV['RES_DB_NAME'] %>
Copy link
Contributor

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.

@orenyk
Copy link
Contributor

orenyk commented Jun 14, 2016

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 ENV call with the helper incorrectly. Thanks!

@esoterik esoterik changed the title Create helper method to check ENV variables [1422] Create helper method to check ENV variables Jun 14, 2016
@esoterik
Copy link
Collaborator Author

Ah, the dangers of using sed to replace everything and not checking it thoroughly enough--I'll go through it

@@ -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')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no helper

@esoterik
Copy link
Collaborator Author

Okay, ready for rereview!

@@ -1,3 +1,4 @@
include EnvironmentHandler
Copy link
Collaborator Author

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

Copy link
Contributor

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.

@orenyk
Copy link
Contributor

orenyk commented Jun 21, 2016

A few more inline comments, I'm particularly concerned by config/environments/production.rb, we have a few boolean flags but I don't know if there's a way to load the helper before it gets processed. Let me know what you think!

@orenyk orenyk self-assigned this Sep 19, 2016
@esoterik esoterik force-pushed the 1422_fix_env_behavior branch from 1521dd9 to 5e132f4 Compare September 25, 2016 14:36
@esoterik
Copy link
Collaborator Author

Pushed an update resolving the issues with the production config. I think this will be good to merge after the build passes

@orenyk
Copy link
Contributor

orenyk commented Oct 28, 2016

So basically we should remove the change from #1618 when this is merged in and instead add a committed .env.test file.

Copy link
Contributor

@orenyk orenyk left a 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'])
Copy link
Contributor

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
Copy link
Contributor

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 = \
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

@orenyk
Copy link
Contributor

orenyk commented Nov 15, 2016

FYI, this also needs to be rebased.

@esoterik
Copy link
Collaborator Author

updated!

Copy link
Contributor

@orenyk orenyk left a 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')
Copy link
Contributor

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants