Skip to content

Commit

Permalink
fix rubocop warning + failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
vnegi-digitalocean committed Jan 16, 2025
1 parent 32ee4dd commit d30c69a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/droplet_kit/mappings/reserved_ipv6_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ReservedIpv6Mapping
root_key plural: 'reserved_ipv6s', singular: 'reserved_ipv6', scopes: [:read]

property :ip, scopes: [:read]
property :region_slug, scopes: [:read, :create]
property :region_slug, scopes: %i[read create]
property :droplet, scopes: [:read], include: DropletMapping
property :reserved_at, scopes: [:read]
end
Expand Down
3 changes: 2 additions & 1 deletion lib/droplet_kit/resources/reserved_ipv6_resource.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module DropletKit
class ReservedIpv6Resource < ResourceKit::Resource
resources do
Expand All @@ -9,7 +10,7 @@ class ReservedIpv6Resource < ResourceKit::Resource

action :find, 'GET /v2/reserved_ipv6/:ip' do
handler(200) { |response| ReservedIpv6Mapping.extract_single(response.body, :read) }
handler(404) { |response| ErrorMapping.fail_with(Error, response.body) }
handler(404) { |response| ErrorMapping.fail_with(Error, response.body) }
end

action :create, 'POST /v2/reserved_ipv6' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
end

it_behaves_like 'an action that handles invalid parameters' do
let(:arguments) { { ip: ip} }
let(:arguments) { { ip: ip } }
end

it_behaves_like 'an action that handles bad request' do
Expand Down
13 changes: 6 additions & 7 deletions spec/lib/droplet_kit/resources/reserved_ipv6_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

include_context 'resources'

RSpec::Matchers.define :match_reserved_ip_fixture do |droplet|
RSpec::Matchers.define :match_reserved_ipv6_fixture do |droplet|
match do |reserved_ip|
expect(reserved_ip.droplet).to be_a(DropletKit::Droplet) if droplet

Expand All @@ -20,7 +20,7 @@
reserved_ips = resource.all
expect(reserved_ips).to all(be_a(DropletKit::ReservedIpv6))

expect(reserved_ips.first).to match_reserved_ip_fixture
expect(reserved_ips.first).to match_reserved_ipv6_fixture
end

it 'returns an empty array of reserved_ipv6s' do
Expand All @@ -40,19 +40,19 @@
stub_do_api('/v2/reserved_ipv6/2a03:b0c0:3:f0::5dcf:9000', :get).to_return(body: api_fixture('reserved_ipv6/find'))
reserved_ip = resource.find(ip: '2a03:b0c0:3:f0::5dcf:9000')
expect(reserved_ip).to be_a(DropletKit::ReservedIpv6)
expect(reserved_ip).to match_reserved_ip_fixture
expect(reserved_ip).to match_reserved_ipv6_fixture
end

it 'return a not_found response' do
stub_do_api('/v2/reserved_ipv6/2a03:b0c0:3:f0::5dcf:9000', :get).to_return(body: '{"id": "not_found", "message": "not found"}', status: 404)
expect { resource.find(ip: '2a03:b0c0:3:f0::5dcf:9000') }.to raise_exception(DropletKit::Error).with_message("not found")
expect { resource.find(ip: '2a03:b0c0:3:f0::5dcf:9000') }.to raise_exception(DropletKit::Error).with_message('not found')
end
end

describe '#create' do
let(:path) { '/v2/reserved_ipv6' }

context 'for a successful create' do
context 'with a successful create' do
it 'returns the created reserved_ipv6' do
reserved_ip = DropletKit::ReservedIpv6.new(
region: 'nyc1'
Expand Down Expand Up @@ -80,10 +80,9 @@
expect(request).to have_been_made
end


it 'return a not_found response' do
stub_do_api('/v2/reserved_ipv6/2a03:b0c0:3:f0::5dcf:9000', :delete).to_return(body: '{"id": "not_found", "message": "not found"}', status: 404)
expect { resource.delete(ip: '2a03:b0c0:3:f0::5dcf:9000') }.to raise_exception(DropletKit::FailedDelete).with_message("not found")
expect { resource.delete(ip: '2a03:b0c0:3:f0::5dcf:9000') }.to raise_exception(DropletKit::FailedDelete).with_message('not found')
end
end
end

0 comments on commit d30c69a

Please sign in to comment.