From a9d408d69c8d7deec52edad4ee4bf5a16dc00a61 Mon Sep 17 00:00:00 2001 From: Kevin Soltysiak Date: Mon, 12 Feb 2024 00:27:47 +0100 Subject: [PATCH] refactor: migrate db api endpoints and specs --- lib/scalingo/regional_database/backups.rb | 35 ++----------------- lib/scalingo/regional_database/databases.rb | 23 ++---------- samples/regional_database/backups/_meta.json | 2 +- .../regional_database/backups_spec.rb | 12 +++---- .../regional_database/databases_spec.rb | 8 ++--- 5 files changed, 16 insertions(+), 64 deletions(-) diff --git a/lib/scalingo/regional_database/backups.rb b/lib/scalingo/regional_database/backups.rb index 4ccafc1..59d3780 100644 --- a/lib/scalingo/regional_database/backups.rb +++ b/lib/scalingo/regional_database/backups.rb @@ -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 diff --git a/lib/scalingo/regional_database/databases.rb b/lib/scalingo/regional_database/databases.rb index f2d0ddb..00fdfe6 100644 --- a/lib/scalingo/regional_database/databases.rb +++ b/lib/scalingo/regional_database/databases.rb @@ -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 diff --git a/samples/regional_database/backups/_meta.json b/samples/regional_database/backups/_meta.json index 2baf9c3..bc70f41 100644 --- a/samples/regional_database/backups/_meta.json +++ b/samples/regional_database/backups/_meta.json @@ -1,4 +1,4 @@ { "addon_id": "63bfe3b600deff4f0516cc12", - "backup_id": "5bb95a904ffb096e9a2831b8" + "id": "5bb95a904ffb096e9a2831b8" } diff --git a/spec/scalingo/regional_database/backups_spec.rb b/spec/scalingo/regional_database/backups_spec.rb index ab88eab..dd48607 100644 --- a/spec/scalingo/regional_database/backups_spec.rb +++ b/spec/scalingo/regional_database/backups_spec.rb @@ -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" @@ -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 } @@ -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" @@ -41,7 +41,7 @@ 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] } @@ -49,7 +49,7 @@ 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" diff --git a/spec/scalingo/regional_database/databases_spec.rb b/spec/scalingo/regional_database/databases_spec.rb index 18d035a..21a0e34 100644 --- a/spec/scalingo/regional_database/databases_spec.rb +++ b/spec/scalingo/regional_database/databases_spec.rb @@ -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" @@ -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"