-
Notifications
You must be signed in to change notification settings - Fork 141
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
Enhanced API to catch Settings validation errors #356
Enhanced API to catch Settings validation errors #356
Conversation
Marking as WIP for now, tests will fail until we update/sync up with @Fryguy's magic settings fix. |
spec/requests/settings_spec.rb
Outdated
it "updates to settings return a BadRequestError upon failed validation" do | ||
api_basic_authorize(:user => super_admin.userid, :password => super_admin.password) | ||
|
||
patch(api_server_settings_url(nil, server), :params => {:authentication => {:mode => "bogus_auth_mode"}}) |
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.
The other server settings specs are in spec/requests/servers_spec.rb
- would it make sense for this to live there too?
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.
starting going that way, but then realizing I'm really testing a settings update handling that's generic to all and it didn't make sense to duplicate for servers, zone, region, so I put that here.
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.
Right, but you're hitting a different endpoint to the one suggested by this file. Does it work if you hit the api_settings_url
? If not, perhaps consider a shared example to eliminate duplication?
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.
ahh good point, I'll move it the proper file.
@@ -117,7 +117,7 @@ def settings | |||
case @req.method | |||
when :patch | |||
raise ForbiddenError, "You are not authorized to edit settings." unless super_admin? | |||
resource.add_settings_for_resource(@req.json_body) | |||
resource_update_settings(resource, @req.json_body) |
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'm not opposed to extracting a method here, but I think its name should reflect the responsibilit(y|ies) of the new method - here's it's to try an update and raise on a validation error. I'm having a hard time trying to find a succinct way to say that, so maybe inline for now?
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.
wasn't crazy about have the begin/rescue inside the when block, (you never know when rubocop starts complaining about complexity 😉 ) so I created the separate method. I can go either way really. up to you.
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.
poke @imtayadeway any preference ?
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 think my preference is for in-line 👍
…ingly to the client via a BadRequestError.
…ive servers_spec.rb
20f1c5c
to
4f64cec
Compare
Checked commits abellotti/manageiq-api@f21df07~...4f64cec with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@Fryguy PR updated following ManageIQ/manageiq#17247 Thanks!! |
now gives us:
|
poke @imtayadeway |
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 good. I would prefer a spec for zones and regions, since the fact that they have a common pathway is an implementation detail to an integration test, but that's more of a nit. 👍
Enhanced API to catch Settings validation errors and reporting accordingly to the client via a BadRequestError.