Skip to content

Commit

Permalink
Proper flash message when product's system name produces invalid prox…
Browse files Browse the repository at this point in the history
…y endpoints
  • Loading branch information
guicassolato committed Jan 7, 2020
1 parent dbbfc42 commit 6ffe6ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/services/service_creator.rb
Expand Up @@ -2,7 +2,7 @@

class ServiceCreator

delegate :backend_api_configs, :backend_api_proxy, :account, to: :@service
delegate :backend_api_configs, :backend_api_proxy, :account, :proxy, to: :@service
delegate :provider_can_use?, to: :account

def initialize(service:, backend_api: nil)
Expand All @@ -22,6 +22,10 @@ def call!(params = {})
def call(params = {})
call!(params)
rescue ActiveRecord::RecordInvalid
if proxy && proxy.errors[:endpoint].any? { |message| message =~ /the accepted format is/ }
@service.errors.add(:system_name, :invalid_for_proxy_endpoints)
end

false
end

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -888,6 +888,7 @@ en:
attributes:
system_name:
invalid: invalid. Only ASCII letters, numbers, dashes and underscores are allowed.
invalid_for_proxy_endpoints: must be shorter.

cinstance:
attributes:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/api/services_controller_test.rb
Expand Up @@ -245,7 +245,7 @@ class ServiceCreateTest < Api::ServicesControllerTest
@provider.settings.allow_multiple_services!

post admin_services_path, service: { name: 'My New Product', system_name: 'this-hostname-label-is-longer-than-63-chars-which-is-not-allowed-according-to-rfc-1035' }
assert_equal 'Couldn\'t create Product. Check your Plan limits', flash[:error]
assert_equal 'System name must be shorter.', flash[:error]

post admin_services_path, service: { name: 'My New Product', system_name: 'short-labels-are-ok' }
refute flash[:error].presence
Expand Down

0 comments on commit 6ffe6ce

Please sign in to comment.