Skip to content

Commit

Permalink
Merge pull request #72 from tonobo/server-next-actions
Browse files Browse the repository at this point in the history
server: return `next_actions` data on create
  • Loading branch information
Stefan Koch committed Jan 30, 2023
2 parents 170a91a + de2cdbd commit b3e3a64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/hcloud/server_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def create(name:,
[
Action.new(client, response.parsed_json[:action]),
Server.new(client, response.parsed_json[:server]),
response.parsed_json[:root_password]
response.parsed_json[:root_password],
response.parsed_json[:next_actions].to_a.map do |action|
Action.new(client, action)
end
]
end
end
Expand Down
14 changes: 11 additions & 3 deletions spec/hcloud/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,22 @@
stub_collection("servers/#{servers[0][:id]}/actions", [related_action], resource_name: :actions)
stub('servers') do |_request, _page_info|
{
body: { server: servers[0], action: related_action, root_password: :moo },
body: {
server: servers[0],
action: related_action,
root_password: :moo,
next_actions: [new_action(:running, command: 'start_server')]
},
code: 201
}
end
action, server, pass = nil
action, server, pass, next_actions = nil
expect do
action, server, pass = client.servers.create(name: 'moo', server_type: 'cx11', image: 1)
action, server, pass, next_actions = client.servers.create(name: 'moo', server_type: 'cx11', image: 1)
end.not_to(raise_error)
expect(action).to be_a Hcloud::Action
expect(next_actions).to all be_a Hcloud::Action

expect(server.actions.count).to eq(1)
expect(server.id).to be_a Integer
expect(server.rescue_enabled).to be servers[0][:rescue_enabled]
Expand Down

0 comments on commit b3e3a64

Please sign in to comment.