Skip to content

Commit

Permalink
Merge pull request #17370 from NobodysNightmare/simple-provider-short…
Browse files Browse the repository at this point in the history
…ening

Simplify provider name shortening
  • Loading branch information
NobodysNightmare authored Dec 9, 2024
2 parents 1a5079d + e0b11a1 commit 5604aaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 6 additions & 8 deletions modules/storages/app/models/storages/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,12 @@ class Storage < ApplicationRecord
}.freeze, _prefix: :health

def self.shorten_provider_type(provider_type)
case /Storages::(?'provider_name'.*)Storage/.match(provider_type)
in provider_name:
provider_name.underscore
else
raise ArgumentError,
"Unknown provider_type! Given: #{provider_type}. " \
"Expected the following signature: Storages::{Name of the provider}Storage"
end
short, = PROVIDER_TYPE_SHORT_NAMES.find { |_, long| provider_type == long }
return short.to_s if short

raise ArgumentError,
"Unknown provider_type! Given: #{provider_type}. " \
"Known provider types are defined in Storages::Storage::PROVIDER_TYPE_SHORT_NAMES."
end

def self.one_drive_without_ee_token?(provider_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@
end
end

context "when provider_type does not match the signature" do
context "when provider_type is unknown" do
it "raises an error", :aggregate_failures do
expect do
described_class.shorten_provider_type("Storages::Nextcloud")
end.to raise_error("Unknown provider_type! Given: Storages::Nextcloud. " \
"Expected the following signature: Storages::{Name of the provider}Storage")
"Known provider types are defined in Storages::Storage::PROVIDER_TYPE_SHORT_NAMES.")
expect do
described_class.shorten_provider_type("Storages:NextcloudStorage")
end.to raise_error("Unknown provider_type! Given: Storages:NextcloudStorage. " \
"Expected the following signature: Storages::{Name of the provider}Storage")
"Known provider types are defined in Storages::Storage::PROVIDER_TYPE_SHORT_NAMES.")
expect do
described_class.shorten_provider_type("Storages::NextcloudStorag")
end.to raise_error("Unknown provider_type! Given: Storages::NextcloudStorag. " \
"Expected the following signature: Storages::{Name of the provider}Storage")
"Known provider types are defined in Storages::Storage::PROVIDER_TYPE_SHORT_NAMES.")
expect do
described_class.shorten_provider_type("Storages::UnknownStorage")
end.to raise_error("Unknown provider_type! Given: Storages::UnknownStorage. " \
"Known provider types are defined in Storages::Storage::PROVIDER_TYPE_SHORT_NAMES.")
end
end
end
Expand Down

0 comments on commit 5604aaf

Please sign in to comment.