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

Nested config validation and configure not raises error #121

Open
bigforcegun opened this issue Oct 30, 2020 · 1 comment
Open

Nested config validation and configure not raises error #121

bigforcegun opened this issue Oct 30, 2020 · 1 comment

Comments

@bigforcegun
Copy link

bigforcegun commented Oct 30, 2020

Summary

If we use methods like validate_with and configure with nested deep setting structure and custom validation methods, validation methods gets old settings payload and always returns true

Code

class FlatConfig < Qonfig::DataSet
  expose_yaml Rails.root.join('tmp/flat_config.yml'), via: :env_key, env: :default

  validate by: :some_validation_method

  def some_validation_method
    puts "try to validate settings.some_key = #{settings.some_key}"
    settings.some_key != 'bad'
  end
end

class NestedDeepConfig < Qonfig::DataSet
  expose_yaml Rails.root.join('tmp/deep_config.yml'), via: :env_key, env: :default

  validate by: :some_validation_method

  def some_validation_method
    puts "try to validate settings.some_key.some_key2 = #{settings.some_key.some_key2}"
    settings.some_key.some_key2 != 'bad' # HERE we have settings.some_key.some_key2 = good
  end
end
end

example 1 (flat)

    config = FlatConfig.new
    invalid_payload = {
      some_key: 'bad',
    }

    puts "valid_with? = #{config.valid_with?(invalid_payload)}"
    begin
      puts 'config.configure(invalid_payload)'
      config.configure(invalid_payload)
      puts 'Hello invalid config =('
      puts config.settings.some_key.to_s
    rescue StandardError => error
      puts error
    end

example 2 (nested)

    config = NestedDeepConfig.new
    invalid_payload = {
      some_key: {
        some_key2: 'bad',
      },
    }
    puts "valid_with? = #{config.valid_with?(invalid_payload)}"
    begin
      puts 'config.configure(invalid_payload)'
      config.configure(invalid_payload)
      puts 'Hello invalid config =('
      puts config.settings.some_key.some_key2.to_s
    rescue StandardError => error
      puts error
    end

tmp/flat_config.yml

default:
  some_key: 'good'

tmp/deep_config.yml

default:
  some_key:
    some_key2: 'good'

Expected behavior

  • example 1 (flat)
    • valid_with? = false
    • configure(invalid_payload) - raises error
  • example 2 (nested)
    • valid_with? = false
    • configure(invalid_payload) - raises error

Current behavior

  • example 1 (flat)
    • valid_with? = false
    • configure(invalid_payload) - raises error
  • example 2 (nested)
    • valid_with? = true
    • configure(invalid_payload) - no error raises =(
@0exp
Copy link
Owner

0exp commented Oct 30, 2020

Hi! Thx for issue! I will check it as soon as possible.

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

No branches or pull requests

2 participants