Skip to content

Commit

Permalink
fix: processing arrays for required except (#156)
Browse files Browse the repository at this point in the history
Nesting arrays would yield convert an Array to a String before matching it against the current environment and always fail.
  • Loading branch information
dominikb authored Feb 12, 2025
1 parent c6f7cb4 commit c6ad3eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- For Rails applications, `suppress_required_validations` is automatically set to `true` if `SECRET_KEY_BASE_DUMMY` is defined.

- Fix handling relative vs. absolute paths in `autoload_static_configs_path=`. ([@palkan][])
- Fix support for array values in `except` option for required attributes. ([@dominikb][])

## 2.6.4 (2024-04-30)

Expand Down
2 changes: 1 addition & 1 deletion lib/anyway/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def matching_env?(env)

if env.is_a?(::Hash)
envs = env[:except]
excluded_envs = [envs].flat_map(&:to_s)
excluded_envs = [*envs].flat_map(&:to_s)
excluded_envs.none?(current_environment)
elsif env.is_a?(::Array)
env.flat_map(&:to_s).include?(current_environment)
Expand Down
10 changes: 10 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,16 @@ def self.name
end
end

context "when current env matches one of env options under except array" do
before { allow(Anyway::Settings).to receive(:current_environment).and_return("local") }

let(:missed_keys) { [:sentry_api_key] }

it "not raises ValidationError" do
expect { demo_config.new }.to_not raise_error
end
end

context "when env value under except key mismatched" do
before { allow(Anyway::Settings).to receive(:current_environment).and_return("demo") }

Expand Down

0 comments on commit c6ad3eb

Please sign in to comment.