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

Add ability for app to run without application.yml file #907

Merged
merged 3 commits into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/initializers/figaro.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('../../../lib/figaro_yaml_validator', __FILE__)
require File.join(Rails.root, 'lib', 'config_validator')

Figaro.require_keys(
'allow_third_party_auth',
Expand Down Expand Up @@ -38,4 +38,4 @@
'valid_service_providers'
)

FigaroYamlValidator.new.validate
ConfigValidator.new.validate
24 changes: 24 additions & 0 deletions lib/config_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class ConfigValidator
def validate(env = ENV)
bad_keys = keys_with_bad_values(env, candidate_keys(env))
return unless bad_keys.any?
raise warning(bad_keys).tr("\\\n", ' ')
end

private

def candidate_keys(env)
env.keys.delete_if { |key| key.starts_with?(Figaro::Application::FIGARO_ENV_PREFIX) }
end

def keys_with_bad_values(env, keys)
keys.keep_if { |key| %w(yes no).include?(env[key]) }
end

def warning(bad_keys)
<<~HEREDOC
You have invalid values for #{bad_keys.uniq.to_sentence} in
config/application.yml. Please change them to true or false
HEREDOC
end
end
30 changes: 0 additions & 30 deletions lib/figaro_yaml_validator.rb

This file was deleted.

24 changes: 24 additions & 0 deletions spec/lib/config_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'rails_helper'

describe ConfigValidator do
describe '#validator' do
it 'raises if one or more candidate key values is set to yes or no' do
bad_key = 'bad_key'
other_bad_key = 'other_bad_key'
noncandidate_key = '_FIGARO_KEY'
good_key = 'good_key'

env = {
bad_key => 'yes',
other_bad_key => 'no',
noncandidate_key => 'yes',
good_key => 'foo'
}

expect { ConfigValidator.new.validate(env) }.to raise_error(
RuntimeError,
/You have invalid values for #{bad_key} and #{other_bad_key}/
)
end
end
end
22 changes: 0 additions & 22 deletions spec/lib/figaro_yaml_validator_spec.rb

This file was deleted.