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

Fixes the pxe_servers collection actions #678

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2505,20 +2505,16 @@
- :pxe_images
- :pxe_menus
:collection_actions:
:get:
- :name: read
:identifier: pxe_server_view
:post:
- :name: create
:identifier: pxe_server_create
- :name: edit
:identifier: pxe_server_edit
:patch:
- :name: edit
:identifier: pxe_server_edit
:delete:
- :name: delete
:identifier: pxe_server_delete
:get:
- :name: read
:identifier: pxe_server_view
:resource_actions:
:get:
- :name: read
Expand Down
44 changes: 42 additions & 2 deletions spec/requests/pxe_servers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,51 @@
end
end

describe 'POST /api/pxe_servers with delete action' do
let!(:pxe_server1) { FactoryBot.create(:pxe_server) }
let!(:pxe_server2) { FactoryBot.create(:pxe_server) }

it "can bulk delete pxe_servers" do
api_basic_authorize(collection_action_identifier(:pxe_servers, :delete, :post))

post(
api_pxe_servers_url,
:params => {
:action => "delete",
:resources => [
{:href => api_pxe_server_url(nil, pxe_server1)},
{:href => api_pxe_server_url(nil, pxe_server2)}
]
}
)

expected = {
"results" => a_collection_containing_exactly(
a_hash_including(
"message" => "pxe_servers id: #{pxe_server1.id} deleting",
"success" => true,
"href" => api_pxe_server_url(nil, pxe_server1)
),
a_hash_including(
"message" => "pxe_servers id: #{pxe_server2.id} deleting",
"success" => true,
"href" => api_pxe_server_url(nil, pxe_server2)
)
)
}

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
expect(PxeServer.exists?(pxe_server1.id)).to be_falsey
expect(PxeServer.exists?(pxe_server2.id)).to be_falsey
end
end

describe 'update /api/pxe_servers/:id' do
let(:url) { "/api/pxe_servers/#{pxe_server.id}" }

it 'update pxe server' do
api_basic_authorize collection_action_identifier(:pxe_servers, :edit, :patch)
api_basic_authorize resource_action_identifier(:pxe_servers, :edit, :patch)
patch(url, :params => {:name => 'updated name', :uri => 'updated://url', :pxe_menus => [{:file_name => 'updated menu'}]})
expect(response).to have_http_status(:ok)
expect(response.parsed_body['name']).to eq('updated name')
Expand All @@ -215,7 +255,7 @@
let(:url) { "/api/pxe_servers/#{pxe_server.id}" }

it 'delete pxe server' do
api_basic_authorize collection_action_identifier(:pxe_servers, :delete, :delete)
api_basic_authorize resource_action_identifier(:pxe_servers, :delete, :delete)
delete(url)
expect(response).to have_http_status(:no_content)
expect(PxeServer.exists?(pxe_server.id)).to be_falsey
Expand Down