Skip to content

Commit

Permalink
refactor: migrate db api endpoints and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ksol committed Feb 11, 2024
1 parent 93aded5 commit a9d408d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 64 deletions.
35 changes: 3 additions & 32 deletions lib/scalingo/regional_database/backups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,8 @@

module Scalingo
class RegionalDatabase::Backups < API::Endpoint
def create(addon_id, headers = nil, &block)
data = nil

database_connection(addon_id).post(
"databases/#{addon_id}/backups",
data,
headers,
&block
)
end

def for(addon_id, headers = nil, &block)
data = nil

database_connection(addon_id).get(
"databases/#{addon_id}/backups",
data,
headers,
&block
)
end

def archive(addon_id, backup_id, headers = nil, &block)
data = nil

database_connection(addon_id).get(
"databases/#{addon_id}/backups/#{backup_id}/archive",
data,
headers,
&block
)
end
get :for, "databases/{addon_id}/backups"
get :archive, "databases/{addon_id}/backups/{id}/archive"
post :create, "databases/{addon_id}/backups"
end
end
23 changes: 2 additions & 21 deletions lib/scalingo/regional_database/databases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,7 @@

module Scalingo
class RegionalDatabase::Databases < API::Endpoint
def find(id, headers = nil, &block)
data = nil

database_connection(id).get(
"databases/#{id}",
data,
headers,
&block
)
end

def upgrade(id, headers = nil, &block)
data = nil

database_connection(id).post(
"databases/#{id}/upgrade",
data,
headers,
&block
)
end
get :find, "databases/{id}"
post :upgrade, "databases/{id}/upgrade"
end
end
2 changes: 1 addition & 1 deletion samples/regional_database/backups/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"addon_id": "63bfe3b600deff4f0516cc12",
"backup_id": "5bb95a904ffb096e9a2831b8"
"id": "5bb95a904ffb096e9a2831b8"
}
12 changes: 6 additions & 6 deletions spec/scalingo/regional_database/backups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

describe_method "create" do
context "success" do
let(:arguments) { [meta[:addon_id]] }
let(:params) { meta.slice(:addon_id) }
let(:stub_pattern) { "create-201" }

it_behaves_like "a singular object response", 201
end

context "failure" do
let(:arguments) { [meta[:addon_id]] }
let(:params) { meta.slice(:addon_id) }
let(:stub_pattern) { "create-400" }

it_behaves_like "a client error"
Expand All @@ -23,7 +23,7 @@

describe_method "for" do
context "success" do
let(:arguments) { [meta[:addon_id]] }
let(:params) { meta.slice(:addon_id) }
let(:stub_pattern) { "for-200" }
let(:expected_count) { 3 }

Expand All @@ -32,7 +32,7 @@
end

context "failure" do
let(:arguments) { [meta[:addon_id]] }
let(:params) { meta.slice(:addon_id) }
let(:stub_pattern) { "for-400" }

it_behaves_like "a client error"
Expand All @@ -41,15 +41,15 @@

describe_method "archive" do
context "success" do
let(:arguments) { [meta[:addon_id], meta[:backup_id]] }
let(:params) { meta.slice(:addon_id, :id) }
let(:stub_pattern) { "archive-200" }
let(:expected_keys) { %i[download_url] }

it_behaves_like "a singular object response"
end

context "failure" do
let(:arguments) { [meta[:addon_id], meta[:backup_id]] }
let(:params) { meta.slice(:addon_id, :id) }
let(:stub_pattern) { "archive-400" }

it_behaves_like "a client error"
Expand Down
8 changes: 4 additions & 4 deletions spec/scalingo/regional_database/databases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

describe_method "find" do
context "success" do
let(:arguments) { [meta[:id]] }
let(:params) { meta.slice(:id) }
let(:stub_pattern) { "find-200" }

it_behaves_like "a singular object response"
end

context "failure" do
let(:arguments) { [meta[:id]] }
let(:params) { meta.slice(:id) }
let(:stub_pattern) { "find-400" }

it_behaves_like "a client error"
Expand All @@ -23,14 +23,14 @@

describe_method "upgrade" do
context "success" do
let(:arguments) { [meta[:id]] }
let(:params) { meta.slice(:id) }
let(:stub_pattern) { "upgrade-202" }

it_behaves_like "a singular object response", 202
end

context "failure" do
let(:arguments) { [meta[:id]] }
let(:params) { meta.slice(:id) }
let(:stub_pattern) { "upgrade-400" }

it_behaves_like "a client error"
Expand Down

0 comments on commit a9d408d

Please sign in to comment.