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

Add response for no droplets found #48

Merged
merged 3 commits into from
Jul 10, 2013
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
21 changes: 14 additions & 7 deletions lib/tugboat/middleware/list_droplets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ class ListDroplets < Base
def call(env)
ocean = env["ocean"]

ocean.droplets.list.droplets.each do |droplet|
droplet_list = ocean.droplets.list.droplets

if droplet.status == "active"
status_color = GREEN
else
status_color = RED
end
if droplet_list.empty?
say "You don't appear to have any droplets.", :red
say "Try creating one with #{GREEN}\`tugboat create\`"
else
droplet_list.each do |droplet|

if droplet.status == "active"
status_color = GREEN
else
status_color = RED
end

say "#{droplet.name} (ip: #{droplet.ip_address}, status: #{status_color}#{droplet.status}#{CLEAR}, region: #{droplet.region_id}, id: #{droplet.id})"
say "#{droplet.name} (ip: #{droplet.ip_address}, status: #{status_color}#{droplet.status}#{CLEAR}, region: #{droplet.region_id}, id: #{droplet.id})"
end
end

@app.call(env)
Expand Down
16 changes: 15 additions & 1 deletion spec/cli/droplets_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include_context "spec"

describe "droplets" do
it "shows a list" do
it "shows a list when droplets exist" do
stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
to_return(:status => 200, :body => fixture("show_droplets"))

Expand All @@ -18,6 +18,20 @@

expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
end

it "returns an error when no droplets exist" do
stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
to_return(:status => 200, :body => fixture("show_droplets_empty"))

@cli.droplets

expect($stdout.string).to eq <<-eos
You don't appear to have any droplets.
Try creating one with \e[32m`tugboat create`
eos

expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
end
end

end
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/show_droplets_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status":"OK",
"droplets":[]
}