-
Notifications
You must be signed in to change notification settings - Fork 15
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
Cast boolean values #45
Conversation
`rspec/core` is loaded by default.
require 'rubygems' | ||
require 'bundler' | ||
|
||
Bundler.require |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://bundler.io/guides/bundler_setup.html
For such a small Gemfile, we’d advise you to skip Bundler.require and just require the gems by hand
@@ -1,12 +1,7 @@ | |||
# frozen_string_literal: true | |||
|
|||
require 'rubygems' | |||
require 'bundler' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not find why these were needed.
@@ -95,7 +95,7 @@ def load_parameters_from_ssm(next_token = nil) | |||
def build_configuration_from_parameters(parameters) | |||
configuration = {} | |||
parameters.each do |parameter| | |||
parameter_parts = parameter.name[@prefix.length..-1].split(PATH_SEPARATOR).map(&:to_sym) | |||
parameter_parts = parameter.name[@prefix.length..].split(PATH_SEPARATOR).map(&:to_sym) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rubocop autofix. applies to other as well.
'off', :off, | ||
'OFF', :OFF | ||
].to_set.freeze | ||
private_constant :FALSE_VALUES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FALSE_VALUES
is implementation details and should not be exposed.
normalized_method = normalize_key_by_method(method) | ||
if key?(normalized_method) | ||
value = get_configuration_value(normalized_method) | ||
boolean_method?(method) ? cast_boolean(value) : value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is what this PR is all about.
require 'aws-sdk-ssm' | ||
require 'global/backend/aws_parameter_store' | ||
|
||
RSpec.describe Global::Backend::AwsParameterStore do | ||
subject(:parameter_store) do | ||
described_class.new(prefix: '/testapp/', client: client) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed rubocop abuses. applies to other spec files.
@@ -1,9 +1,5 @@ | |||
# frozen_string_literal: true | |||
|
|||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | |||
$LOAD_PATH.unshift(File.dirname(__FILE__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec
and lib
directories are in the load path by default
@@ -1,9 +1,5 @@ | |||
# frozen_string_literal: true | |||
|
|||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | |||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | |||
require 'rspec' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rspec/core
is loaded by default
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
require 'rspec' | ||
require 'global' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simplecov
should be required before any code is loaded
https://github.com/simplecov-ruby/simplecov?tab=readme-ov-file#troubleshooting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the ruby version range is acceptable, seeing as 3.0 is already EOL
- 3.3 | ||
- 3.2 | ||
- 3.1 | ||
- 3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need some fixes
|
||
Gem::Specification.new do |s| | ||
s.name = 'global' | ||
s.version = Global::VERSION | ||
s.required_ruby_version = '>= 3.0.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may require by semver release major version
s.summary = 'Simple way to load your configs from yaml/aws/gcp' | ||
|
||
s.metadata['rubygems_mfa_required'] = 'true' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, we activated this and how ci will do release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@le0pard could you please share the script that does the release? I want to check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how ci will do release
I assumed there is CI that pushed a new version automatically. Ok.
Could you please check if MFA is on or off? If not maybe we should turn it on?
lib/global/configuration.rb
Outdated
@@ -61,6 +77,11 @@ def boolean_method?(method) | |||
'?' == method.to_s[-1] | |||
end | |||
|
|||
# @see ActiveModel::Type::Boolean#cast_value | |||
def cast_boolean(value) | |||
!FALSE_VALUES.include?(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so empty string will be true
? should it be nil
...
lib/global/version.rb
Outdated
@@ -2,6 +2,6 @@ | |||
|
|||
module Global | |||
|
|||
VERSION = '2.1.0' | |||
VERSION = '2.2.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, new major version - removed ruby 2 support
|
||
it 'reads parameters from the parameter store' do | ||
it 'reads parameters from the parameter store' do # rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSpec/MultipleExpectations
- you can fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried several options. next_token
expectations is the tricky part. If you want to keep them, you have to adjust rubocop configuration. To reduce the number of lines again you have to deal with next_token
expectations, move stubs to elsewhere which does not improve code readability.
At the end I think disabling those two rules for one it
is fine. If you disagree please suggest how to deal with these offences.
spec/global/configuration_spec.rb
Outdated
{ | ||
'key' => 'value', | ||
'boolean_key' => true, | ||
'string_boolean_key' => '1', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test with empty string and false value
subject(:global) { described_class } | ||
|
||
describe 'merging backends' do | ||
# rubocop:disable RSpec/VerifiedDoubles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be fixed and written correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global takes an object that quacks like a configuration. This spec tests merging, thus abstract doubles are legit.
|
||
@not_match_item = double | ||
allow(@not_match_item).to receive(:name).and_return('different_key') | ||
secret_data = double(data: 'secret value') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️
Google::Cloud::SecretManager::V1::SecretPayload.new.data
# => ""
instance_double(Google::Cloud::SecretManager::V1::SecretPayload, data: 'secret value')
# => RSpec::Mocks::MockExpectationError: class does not implement the instance method: data
Boolean methods return raw values. AWS Parameters Store does not support boolean type.
In this PR I attempted to address this problem: