Skip to content

Commit

Permalink
Ignore .local files in test environment (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
franzliedke authored and pkuczynski committed Jul 11, 2019
1 parent 636d737 commit df10c42
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changes

* Get rid of activesupport dependency ([#230](https://github.com/railsconfig/config/pull/230))
* Ignore .local files in test environment ([#135](https://github.com/railsconfig/config/issues/135), [#233](https://github.com/railsconfig/config/pull/233))

## 2.0.0

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ Rails.root.join("config", "settings", "#{Rails.env}.local.yml").to_s,
Rails.root.join("config", "environments", "#{Rails.env}.local.yml").to_s
```

**NOTE:** The file `settings.local.yml` will not be loaded in tests to prevent local
configuration from causing flaky or non-deterministic tests. Environment-specific files
(e.g. `settings/test.local.yml`) will still be loaded to allow test-specific credentials.

### Adding sources at runtime

You can add new YAML config files at runtime. Just use:
Expand Down
9 changes: 7 additions & 2 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ def self.setting_files(config_root, env)
File.join(config_root, 'settings.yml').to_s,
File.join(config_root, 'settings', "#{env}.yml").to_s,
File.join(config_root, 'environments', "#{env}.yml").to_s,
*local_setting_files(config_root, env)
].freeze
end

File.join(config_root, 'settings.local.yml').to_s,
def self.local_setting_files(config_root, env)
[
(File.join(config_root, 'settings.local.yml').to_s if env != 'test'),
File.join(config_root, 'settings', "#{env}.local.yml").to_s,
File.join(config_root, 'environments', "#{env}.local.yml").to_s
].freeze
].compact
end

def self.reload!
Expand Down
13 changes: 12 additions & 1 deletion spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
describe Config do

it "should get setting files" do
config = Config.setting_files("root/config", "staging")
expect(config).to eq([
'root/config/settings.yml',
'root/config/settings/staging.yml',
'root/config/environments/staging.yml',
'root/config/settings.local.yml',
'root/config/settings/staging.local.yml',
'root/config/environments/staging.local.yml'
])
end

it "should ignore local config in test environment" do
config = Config.setting_files("root/config", "test")
expect(config).to eq([
'root/config/settings.yml',
'root/config/settings/test.yml',
'root/config/environments/test.yml',
'root/config/settings.local.yml',
'root/config/settings/test.local.yml',
'root/config/environments/test.local.yml'
])
Expand Down

0 comments on commit df10c42

Please sign in to comment.