Skip to content

Commit

Permalink
Reword org and space quota update error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
acrmp committed Sep 13, 2022
1 parent 497d494 commit b57dfc8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
17 changes: 9 additions & 8 deletions app/actions/organization_quotas_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ def self.orgs_with_unlimited_processes(quota)

def self.unlimited_processes_exist_error!(orgs)
named_orgs = orgs.take(MAX_ORGS_TO_LIST_ON_FAILURE).map(&:name).join("', '")
message = if orgs.size == 1
"Org '#{named_orgs}' assigned this quota contains"
elsif orgs.size > MAX_ORGS_TO_LIST_ON_FAILURE
"Orgs '#{named_orgs}' and #{orgs.drop(MAX_ORGS_TO_LIST_ON_FAILURE).size}" \
' other orgs assigned this quota contain'
else
"Orgs '#{named_orgs}' assigned this quota contain"
end + ' apps running with an unlimited log rate limit.'
message = 'This quota is applied to ' +
if orgs.size == 1
"org '#{named_orgs}' which contains"
elsif orgs.size > MAX_ORGS_TO_LIST_ON_FAILURE
"orgs '#{named_orgs}' and #{orgs.drop(MAX_ORGS_TO_LIST_ON_FAILURE).size}" \
' other orgs which contain'
else
"orgs '#{named_orgs}' which contain"
end + ' apps running with an unlimited log rate limit.'

raise Error.new("Current usage exceeds new quota values. #{message}")
end
Expand Down
17 changes: 9 additions & 8 deletions app/actions/space_quota_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ def self.spaces_with_unlimited_processes(quota)

def self.unlimited_processes_exist_error!(spaces)
named_spaces = spaces.take(MAX_SPACES_TO_LIST_ON_FAILURE).map(&:name).join("', '")
message = if spaces.size == 1
"Space '#{named_spaces}' assigned this quota contains"
elsif spaces.size > MAX_SPACES_TO_LIST_ON_FAILURE
"Spaces '#{named_spaces}' and #{spaces.drop(MAX_SPACES_TO_LIST_ON_FAILURE).size}" \
' other spaces assigned this quota contain'
else
"Spaces '#{named_spaces}' assigned this quota contain"
end + ' apps running with an unlimited log rate limit.'
message = 'This quota is applied to ' +
if spaces.size == 1
"space '#{named_spaces}' which contains"
elsif spaces.size > MAX_SPACES_TO_LIST_ON_FAILURE
"spaces '#{named_spaces}' and #{spaces.drop(MAX_SPACES_TO_LIST_ON_FAILURE).size}" \
' other spaces which contain'
else
"spaces '#{named_spaces}' which contain"
end + ' apps running with an unlimited log rate limit.'

raise Error.new("Current usage exceeds new quota values. #{message}")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/request/organization_quotas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ module VCAP::CloudController
expect(last_response).to have_status_code(422)
expect(last_response).to include_error_message(
'Current usage exceeds new quota values. ' \
"Org '#{org.name}' assigned this quota contains apps running with an unlimited log rate limit.")
"This quota is applied to org '#{org.name}' which contains apps running with an unlimited log rate limit.")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/request/space_quotas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ module VCAP::CloudController

expect(last_response).to have_status_code(422)
expect(last_response).to include_error_message(
"Current usage exceeds new quota values. Space '#{space.name}' assigned this quota contains apps running with an unlimited log rate limit.")
"Current usage exceeds new quota values. This quota is applied to space '#{space.name}' which contains apps running with an unlimited log rate limit.")
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/actions/organization_quotas_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def create_orgs_with_unlimited_log_rate_process(count)
it 'errors with a message telling the user the affected org' do
expect do
OrganizationQuotasUpdate.update(org_quota, message)
end.to raise_error(OrganizationQuotasUpdate::Error, "Current usage exceeds new quota values. Org 'org-name-1' " \
'assigned this quota contains apps running with an unlimited log rate limit.')
end.to raise_error(OrganizationQuotasUpdate::Error, 'Current usage exceeds new quota values. This quota is applied to org ' \
"'org-name-1' which contains apps running with an unlimited log rate limit.")
end
end
context 'and they are in two orgs' do
Expand All @@ -132,8 +132,8 @@ def create_orgs_with_unlimited_log_rate_process(count)
it 'errors with a message telling the user the affected orgs' do
expect do
OrganizationQuotasUpdate.update(org_quota, message)
end.to raise_error(OrganizationQuotasUpdate::Error, "Current usage exceeds new quota values. Orgs 'org-name-1', 'org-name-2' " \
'assigned this quota contain apps running with an unlimited log rate limit.')
end.to raise_error(OrganizationQuotasUpdate::Error, 'Current usage exceeds new quota values. This quota is applied to orgs ' \
"'org-name-1', 'org-name-2' which contain apps running with an unlimited log rate limit.")
end
end

Expand All @@ -144,8 +144,8 @@ def create_orgs_with_unlimited_log_rate_process(count)
it 'errors with a message telling the user some of the affected orgs and a total count' do
expect do
OrganizationQuotasUpdate.update(org_quota, message)
end.to raise_error(OrganizationQuotasUpdate::Error, "Current usage exceeds new quota values. Orgs 'org-name-1', 'org-name-2' and 3 other orgs " \
'assigned this quota contain apps running with an unlimited log rate limit.')
end.to raise_error(OrganizationQuotasUpdate::Error, 'Current usage exceeds new quota values. This quota is applied to orgs ' \
"'org-name-1', 'org-name-2' and 3 other orgs which contain apps running with an unlimited log rate limit.")
end
end

Expand All @@ -159,8 +159,8 @@ def create_orgs_with_unlimited_log_rate_process(count)
it 'only names the org once in the error message' do
expect do
OrganizationQuotasUpdate.update(org_quota, message)
end.to raise_error(OrganizationQuotasUpdate::Error, "Current usage exceeds new quota values. Org 'org-name' assigned this quota contains apps " \
'running with an unlimited log rate limit.')
end.to raise_error(OrganizationQuotasUpdate::Error, 'Current usage exceeds new quota values. This quota is applied to org ' \
"'org-name' which contains apps running with an unlimited log rate limit.")
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/actions/space_quota_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def create_spaces_with_unlimited_log_rate_process(count)
it 'errors with a message telling the user the affected space' do
expect do
SpaceQuotaUpdate.update(space_quota, message)
end.to raise_error(SpaceQuotaUpdate::Error, "Current usage exceeds new quota values. Space 'space-name-1' " \
'assigned this quota contains apps running with an unlimited log rate limit.')
end.to raise_error(SpaceQuotaUpdate::Error, 'Current usage exceeds new quota values. This quota is applied to space ' \
"'space-name-1' which contains apps running with an unlimited log rate limit.")
end
end

Expand All @@ -121,8 +121,8 @@ def create_spaces_with_unlimited_log_rate_process(count)
it 'errors with a message telling the user the affected spaces' do
expect do
SpaceQuotaUpdate.update(space_quota, message)
end.to raise_error(SpaceQuotaUpdate::Error, "Current usage exceeds new quota values. Spaces 'space-name-1', 'space-name-2' " \
'assigned this quota contain apps running with an unlimited log rate limit.')
end.to raise_error(SpaceQuotaUpdate::Error, 'Current usage exceeds new quota values. This quota is applied to spaces ' \
"'space-name-1', 'space-name-2' which contain apps running with an unlimited log rate limit.")
end
end

Expand All @@ -133,8 +133,8 @@ def create_spaces_with_unlimited_log_rate_process(count)
it 'errors with a message telling the user some of the affected spaces and a total count' do
expect do
SpaceQuotaUpdate.update(space_quota, message)
end.to raise_error(SpaceQuotaUpdate::Error, "Current usage exceeds new quota values. Spaces 'space-name-1', 'space-name-2' and 3 other spaces " \
'assigned this quota contain apps running with an unlimited log rate limit.')
end.to raise_error(SpaceQuotaUpdate::Error, 'Current usage exceeds new quota values. This quota is applied to spaces ' \
"'space-name-1', 'space-name-2' and 3 other spaces which contain apps running with an unlimited log rate limit.")
end
end

Expand All @@ -148,8 +148,8 @@ def create_spaces_with_unlimited_log_rate_process(count)
it 'only names the space once in the error message' do
expect do
SpaceQuotaUpdate.update(space_quota, message)
end.to raise_error(SpaceQuotaUpdate::Error, "Current usage exceeds new quota values. Space 'space-name' assigned this quota contains apps " \
'running with an unlimited log rate limit.')
end.to raise_error(SpaceQuotaUpdate::Error, 'Current usage exceeds new quota values. This quota is applied to space ' \
"'space-name' which contains apps running with an unlimited log rate limit.")
end
end
end
Expand Down

0 comments on commit b57dfc8

Please sign in to comment.