-
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
Tasks: delete support #220
Conversation
Hi @himdel can you add some specs for this? Is there any reason you didn't add delete on the collection (for bulk delete)? and you can reuse existing identifiers :) |
@jntullo Sure, will do :) (wasn't quite sure if we wanted to spec methods that aren't technically there, but definitely can't hurt :)) As for bulk delete.. I just didn't think of it :).. but there I have questions.. (I'm not seeing any docs on custom collection actions, sorry :).) Collection actions are named |
... Never mind :). It's really that easy, it does seem to call the resource action for each of the resources .. so while I still don't know how to custom collection action, I don't seem to need it right now :). Addded, on to the specs now :) |
@jntullo Specs added, WDYT? :) |
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.
Looking good @himdel !! Just a few minor things/nits 😃
spec/requests/tasks_spec.rb
Outdated
|
||
delete(url) | ||
|
||
expect(response).to have_http_status(204) |
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.
For the http status, could you use :forbidden
rather than 204
? will help to keep our specs consistent
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.
Probably not :forbidden
... I guess something like :empty
?
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.
Turns out :no_content
, according to http://billpatrianakos.me/blog/2013/10/13/list-of-rails-status-code-symbols/
That's why I prefer the numerical values, no confusion about what it could be :).
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)
spec/requests/tasks_spec.rb
Outdated
|
||
post(url, :params => data) | ||
|
||
expect(response).to have_http_status(200) |
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.
Similarly, you could use :ok
instead of 200
spec/requests/tasks_spec.rb
Outdated
:resources => [ | ||
{:href => api_task_url(nil, task.id)}, | ||
{:href => api_task_url(nil, task2.id)}, | ||
], |
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.
nit, but no ,
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.
fixed :) Funnily enough, in ui, trailing commas are strongly encouradged :).
spec/requests/tasks_spec.rb
Outdated
post(url, :params => data) | ||
|
||
expect(response).to have_http_status(200) | ||
expect_deleted(task, task2) |
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.
Generally, the API is concerned with the responses rather than validating the objects, something like 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.
Well, I don't care about the response at all, only that it actually deleted the thing :).
Should I add something like that then?
But.. more and more this looks like I'm testing your generic functions for one specific case, which is identical to all the other specific cases.
Would you be interested in specs for the generic resource_delete
instead?
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.
Or at least a set of helpers so that we can write the tests once, and then only give that the things that should be different?
That task_spec should not really have to be more code than something like..
describe 'TasksController' do
let(:task) { FactoryGirl.create(:miq_task, :state => MiqTask::STATE_FINISHED) }
let(:task2) { FactoryGirl.create(:miq_task, :state => MiqTask::STATE_FINISHED) }
test_generic_delete(:methods => [:delete, :post, :bulk], :resources => [:task, :task2])
end
spec/requests/tasks_spec.rb
Outdated
it 'bulk deletes' do | ||
api_basic_authorize collection_action_identifier(:tasks, :delete) | ||
|
||
url = api_tasks_url |
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.
are you only using this variable in one place? May not be necessary to assign it
spec/requests/tasks_spec.rb
Outdated
it 'deletes on POST' do | ||
api_basic_authorize resource_action_identifier(:tasks, :delete) | ||
|
||
url = api_task_url(nil, task.id) |
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.
You may not need to assign this to a variable if you're only calling it once, same as above and below
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.
Sure I don't.
But is it not clearer to write..
url = function call with not-so clear params
data = create the structure
post(url, :params => data)
than to have it all in one blob, like
post(api_task_url(nil, task.id), :params => {
:action => 'delete',
:resources => [
{:href => api_task_url(nil, task.id)},
{:href => api_task_url(nil, task2.id)},
],
})
?
But of course your repo, your rules, just tell me you're sure you want it that way :).
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.
My two penneth: I think "clearer" is always going to be a bit subjective in these cases. I personally find your counter example clearer.
both via DELETE and via POST {action:"delete"}
``` API.post('/api/tasks', { action: "delete", resources: [ { href: 'http://localhost:3000/api/tasks/10000000054726' }, { href: 'http://localhost:3000/api/tasks/10000000054727' }, ], }); ```
similar to `collection_action_identifier` except for resource actions
@jntullo Can you check again please? I've added the spec for status and message in response, and removed the extra vars. |
@miq-bot add_label gaprindashvili/yes |
apparently miq-bot complains about readable hashes - moving back to vars
.. and I can't fix both miq-bot and not using vars for data while still being readable .. undoing that change. And not touching this again :D. |
spec/requests/tasks_spec.rb
Outdated
:action => 'delete', | ||
:resources => [ | ||
{:href => api_task_url(nil, task.id)}, | ||
{:href => api_task_url(nil, task2.id)} |
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.
Hi @himdel minor, but on all the api_task_url calls, prefer just the object being specified i.e.
api_task_url(nil, task)
LGTM!! minor nit on the rails url helper usage in specs. |
Thanks @abellotti, updated :) |
Thanks @himdel for the update and the API enhancement !! 👍 will merge when 🍏 |
Checked commits https://github.com/himdel/manageiq-api/compare/8cc67b298383313f5616d8e518113343a44a8585~...74b36b6d10a7c803f80108e893b4fa05c24455ab with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0 |
Tasks: delete support (cherry picked from commit 85f3153)
Gaprindashvili backport details:
|
This adds deletion for
MiqTask
, both viaDELETE
and viaPOST {action:"delete"}
, and bulk deletion (POST {action:"delete", resources: [...]}
).Closes #203
(Needed for ManageIQ/manageiq-ui-classic#2708.)
Is it OK to reuse existing identifiers (
miq_task_delete
) or is that frowned upon? :)