-
Notifications
You must be signed in to change notification settings - Fork 143
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
keys should be symbolized before merge #631
keys should be symbolized before merge #631
Conversation
👍 LGTM |
@juliancheal unrecognized command 'asign', ignoring... Accepted commands are: add_label, add_reviewer, assign, close_issue, move_issue, remove_label, rm_label, remove_reviewer, set_milestone |
@miq-bot assign @abellotti |
@miq-bot add_label ivanchuk/yes |
85f6fc4
to
7842948
Compare
@AlexanderZagaynov can you add some spec for this fix ? |
@AlexanderZagaynov and where is the issue ? this works:
|
@lpichler what do you mean "this works"? Try with |
returns
I just don't understand what is the issue because from code: in
there you do:
you have in
and then finally
what looks same result as with you change. so what is the issue or what I missed ? |
@lpichler issue is that we have |
@lpichler The problem was, the data from the api request was if there was no which would then result in Once they were symbolised we would only get Therefore when we got to |
ah I see thanks @juliancheal for explanation! to be honest it is pretty hidden what is going on in code I would to like prefer something like this (it is pseudocode):
what do you think about it ? thanks! |
@lpichler I believe the simplest changes are better. This PR is quite obvious, and if we'll start inventions and refactoring, we're at risk to never finish that. |
creds.reverse_merge!(:userid => host.authentication_userid(auth_type)) | ||
hash[auth_type.to_sym] = creds.symbolize_keys! | ||
hash[auth_type.to_sym] = creds |
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'd rather prefer not using mutability here and drop the exclamation marks:
hash[auth_type.to_sym] = creds | |
hash[auth_type.to_sym] = creds.symbolize_keys.reverse_merge(:userid => host.authentication_userid(auth_type)) |
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 just following existing pattern, trying to KISS
it is hard to read from code what has bigger priority if params are comming request or from host - who remembers behaviour of but ok if you are going to refactor it - so just add some specs and I can merge it ;) thanks |
@juliancheal Thank you for explaining the issue above. Once spec are added LGTM |
keys are not the same, that's the problem. they was string and symbol - it's a different objects. I added the spec. Here is the result without my change: Failures:
1) hosts API editing a host's password with an appropriate role prevents duplicate string/symbol keys mess
Failure/Error:
expect do
post api_host_url(nil, host), :params => gen_request(:edit, options)
end.to change { host.reload.authentication_password(:default) }.to("abc123")
expected `host.reload.authentication_password(:default)` to have changed to "abc123", but did not change
# ./spec/requests/hosts_spec.rb:32:in `block (4 levels) in <top (required)>'
Finished in 3.94 seconds (files took 7.11 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/requests/hosts_spec.rb:26 # hosts API editing a host's password with an appropriate role prevents duplicate string/symbol keys mess With this change it is green. |
with you change keys are also same objects. creds.symbolize!
=> {:userid=>'11'} creds.reverse_merge!(:userid =>'222')
=> {:userid=>'11'} or {:userid=>'222'} ? it is hard to know. I still think that using |
@lpichler I guess you still didn't understand the issue reason (( |
Checked commits AlexanderZagaynov/manageiq-api@7842948~...4cf6368 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 |
@lpichler maybe if you'll run my spec without that change, you'll get what I mean :) |
LGTM! Thank you @AlexanderZagaynov |
For everybody who don't understand what |
…_credentials keys should be symbolized before merge (cherry picked from commit 2f85ef4) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1718209
Ivanchuk backport details:
|
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1718209