-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Droplet serialization properties.
- Loading branch information
Robert Ross
committed
Aug 3, 2014
1 parent
9fa2d5a
commit 2970ac1
Showing
14 changed files
with
229 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
--color | ||
--warnings | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module DropletKit | ||
class Image < BaseModel | ||
attribute :id | ||
attribute :name | ||
attribute :distribution | ||
attribute :slug | ||
attribute :public | ||
attribute :regions | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module DropletKit | ||
class Region < BaseModel | ||
attribute :slug | ||
attribute :name | ||
attribute :sizes | ||
attribute :available | ||
attribute :features | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module DropletKit | ||
class Size < BaseModel | ||
attribute :slug | ||
attribute :transfer | ||
attribute :price_monthly | ||
attribute :price_hourly | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"droplets": [ | ||
{ | ||
"id": 19, | ||
"name": "test.example.com", | ||
"memory": 1024, | ||
"vcpus": 2, | ||
"disk": 20, | ||
"region": { | ||
"slug": "nyc1", | ||
"name": "New York", | ||
"sizes": [ | ||
"1024mb", | ||
"512mb" | ||
], | ||
"available": true, | ||
"features": [ | ||
"virtio", | ||
"private_networking", | ||
"backups", | ||
"ipv6" | ||
] | ||
}, | ||
"image": { | ||
"id": 119192817, | ||
"name": "Ubuntu 13.04", | ||
"distribution": "ubuntu", | ||
"slug": "ubuntu1304", | ||
"public": true, | ||
"regions": [ | ||
"nyc1" | ||
], | ||
"created_at": "2014-07-29T14:35:36Z" | ||
}, | ||
"size": { | ||
"slug": "1024mb", | ||
"transfer": 2, | ||
"price_monthly": 10.0, | ||
"price_hourly": 0.01488 | ||
}, | ||
"locked": false, | ||
"status": "active", | ||
"networks": { | ||
"v4": [ | ||
{ | ||
"ip_address": "127.0.0.19", | ||
"netmask": "255.255.255.0", | ||
"gateway": "127.0.0.20", | ||
"type": "public" | ||
} | ||
], | ||
"v6": [ | ||
{ | ||
"ip_address": "2001::13", | ||
"cidr": 124, | ||
"gateway": "2400:6180:0000:00D0:0000:0000:0009:7000", | ||
"type": "public" | ||
} | ||
] | ||
}, | ||
"kernel": { | ||
"id": 485432985, | ||
"name": "DO-recovery-static-fsck", | ||
"version": "3.8.0-25-generic" | ||
}, | ||
"created_at": "2014-07-29T14:35:36Z", | ||
"features": [ | ||
"ipv6" | ||
], | ||
"backup_ids": [ | ||
449676382 | ||
], | ||
"snapshot_ids": [ | ||
449676383 | ||
], | ||
"action_ids": [ | ||
|
||
] | ||
} | ||
], | ||
"meta": { | ||
"total": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe DropletKit::DropletResource do | ||
subject(:resource) { described_class.new(connection) } | ||
include_context 'resources' | ||
|
||
# Theres a lot to check | ||
def check_droplet(droplet) | ||
expect(droplet.name).to eq('test.example.com') | ||
expect(droplet.memory).to eq(1024) | ||
expect(droplet.vcpus).to eq(2) | ||
expect(droplet.disk).to eq(20) | ||
expect(droplet.locked).to eq(false) | ||
expect(droplet.status).to eq('active') | ||
expect(droplet.created_at).to eq('2014-07-29T14:35:36Z') | ||
|
||
expect(droplet.region).to be_kind_of(DropletKit::Region) | ||
expect(droplet.region.slug).to eq('nyc1') | ||
expect(droplet.region.name).to eq('New York') | ||
expect(droplet.region.sizes).to include('1024mb', '512mb') | ||
expect(droplet.region.available).to be(true) | ||
expect(droplet.region.features).to include("virtio", "private_networking", "backups", "ipv6") | ||
|
||
expect(droplet.image).to be_kind_of(DropletKit::Image) | ||
expect(droplet.image.id).to eq(119192817) | ||
expect(droplet.image.name).to eq("Ubuntu 13.04") | ||
expect(droplet.image.distribution).to eq("ubuntu") | ||
expect(droplet.image.slug).to eq("ubuntu1304") | ||
expect(droplet.image.public).to eq(true) | ||
expect(droplet.image.regions).to include('nyc1') | ||
|
||
expect(droplet.size).to be_kind_of(DropletKit::Size) | ||
expect(droplet.size.slug).to eq("1024mb") | ||
expect(droplet.size.transfer).to eq(2) | ||
expect(droplet.size.price_monthly).to eq(10.0) | ||
expect(droplet.size.price_hourly).to eq(0.01488) | ||
end | ||
|
||
describe '#all' do | ||
it 'returns all of the droplets' do | ||
stub_do_api('/v2/droplets', :get).to_return(body: api_fixture('droplets/all')) | ||
droplets = resource.all | ||
expect(droplets).to all(be_kind_of(DropletKit::Droplet)) | ||
|
||
check_droplet(droplets[0]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,11 @@ | ||
require 'droplet_kit' | ||
require 'webmock/rspec' | ||
|
||
RSpec.configure do |config| | ||
# The settings below are suggested to provide a good initial experience | ||
# with RSpec, but feel free to customize to your heart's content. | ||
=begin | ||
# These two settings work together to allow you to limit a spec run | ||
# to individual examples or groups you care about by tagging them with | ||
# `:focus` metadata. When nothing is tagged with `:focus`, all examples | ||
# get run. | ||
config.filter_run :focus | ||
config.run_all_when_everything_filtered = true | ||
# Many RSpec users commonly either run the entire suite or an individual | ||
# file, and it's useful to allow more verbose output when running an | ||
# individual spec file. | ||
if config.files_to_run.one? | ||
# Use the documentation formatter for detailed output, | ||
# unless a formatter has already been configured | ||
# (e.g. via a command-line flag). | ||
config.default_formatter = 'doc' | ||
end | ||
# Print the 10 slowest examples and example groups at the | ||
# end of the spec run, to help surface which specs are running | ||
# particularly slow. | ||
config.profile_examples = 10 | ||
Dir['./spec/support/**/*.rb'].each do |file| | ||
require file | ||
end | ||
|
||
# Run specs in random order to surface order dependencies. If you find an | ||
# order dependency and want to debug it, you can fix the order by providing | ||
# the seed, which is printed after each run. | ||
# --seed 1234 | ||
RSpec.configure do |config| | ||
config.order = :random | ||
# Seed global randomization in this process using the `--seed` CLI option. | ||
# Setting this allows you to use `--seed` to deterministically reproduce | ||
# test failures related to randomization by passing the same `--seed` value | ||
# as the one that triggered the failure. | ||
Kernel.srand config.seed | ||
# rspec-expectations config goes here. You can use an alternate | ||
# assertion/expectation library such as wrong or the stdlib/minitest | ||
# assertions if you prefer. | ||
config.expect_with :rspec do |expectations| | ||
# Enable only the newer, non-monkey-patching expect syntax. | ||
# For more details, see: | ||
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax | ||
expectations.syntax = :expect | ||
end | ||
# rspec-mocks config goes here. You can use an alternate test double | ||
# library (such as bogus or mocha) by changing the `mock_with` option here. | ||
config.mock_with :rspec do |mocks| | ||
# Enable only the newer, non-monkey-patching expect syntax. | ||
# For more details, see: | ||
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ | ||
mocks.syntax = :expect | ||
# Prevents you from mocking or stubbing a method that does not exist on | ||
# a real object. This is generally recommended. | ||
mocks.verify_partial_doubles = true | ||
end | ||
=end | ||
config.include RequestStubHelpers | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'sinatra/base' | ||
|
||
class FakeServer < Sinatra::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module RequestStubHelpers | ||
def stub_do_api(path, verb = :any) | ||
stub_request(verb, %r[#{DropletKit::Client::DIGITALOCEAN_API}#{path}]) | ||
end | ||
|
||
def api_fixture(fixture_name) | ||
Pathname.new('./spec/fixtures/').join("#{fixture_name}.json").read | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
shared_context 'resources' do | ||
let(:client) { DropletKit::Client.new(access_token: 'bunk-token') } | ||
let(:connection) { client.connection } | ||
end |