Skip to content

Commit 5f58bfc

Browse files
committed
make max length 5000, let empty be valid
1 parent f9f0d98 commit 5f58bfc

10 files changed

Lines changed: 14 additions & 68 deletions

File tree

‎app/actions/stack_update.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def update(stack, message)
1515
stack_updates = {}
1616
stack_updates[:state] = message.state if message.requested?(:state)
1717
stack_updates[:state_reason] = message.state_reason if message.state_reason_requested?
18-
stack_updates[:description] = message.description if message.description_requested?
18+
stack_updates[:description] = message.description if message.requested?(:description)
1919
stack.update(stack_updates) if stack_updates.any?
2020

2121
MetadataUpdate.update(stack, message)

‎app/messages/stack_create_message.rb‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ class StackCreateMessage < MetadataBaseMessage
66
register_allowed_keys %i[name description state state_reason]
77

88
validates :name, presence: true, length: { maximum: 250 }
9-
validates :description, presence: true, length: { maximum: 250 }, if: :description_requested?
9+
validates :description, length: { maximum: 250 }
1010
validates :state, inclusion: { in: StackStates::VALID_STATES, message: "must be one of #{StackStates::VALID_STATES.join(', ')}" }, allow_nil: false, if: :state_requested?
1111
validates :state_reason, length: { maximum: 5000 }, allow_nil: true
1212

1313
def state_requested?
1414
requested?(:state)
1515
end
1616

17-
def description_requested?
18-
requested?(:description)
19-
end
20-
2117
def state
2218
return @state if defined?(@state)
2319

‎app/messages/stack_update_message.rb‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class StackUpdateMessage < MetadataBaseMessage
88
validates_with NoAdditionalKeysValidator
99
validates :state, inclusion: { in: StackStates::VALID_STATES, message: "must be one of #{StackStates::VALID_STATES.join(', ')}" }, allow_nil: false, if: :state_requested?
1010
validates :state_reason, length: { maximum: 5000 }, allow_nil: true
11-
validates :description, presence: true, length: { maximum: 250 }, if: :description_requested?
11+
validates :description, length: { maximum: 5000 }, allow_nil: true
1212

1313
def state_requested?
1414
requested?(:state)
@@ -17,9 +17,5 @@ def state_requested?
1717
def state_reason_requested?
1818
requested?(:state_reason)
1919
end
20-
21-
def description_requested?
22-
requested?(:description)
23-
end
2420
end
2521
end

‎docs/openapi/apis/cf/latest/components/requestBodies/StackCreateRequestBody.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ content:
1111
maxLength: 250
1212
description:
1313
type: string
14-
description: Description of the stack; must be non-empty and no longer than 250 characters
14+
description: Description of the stack; must be no longer than 5000 characters
1515
maxLength: 250
1616
metadata:
1717
$ref: '../schemas/Metadata.yaml'

‎docs/openapi/apis/cf/latest/paths/Stacks.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
properties:
156156
description:
157157
type: string
158-
description: Description of the stack; must be non-empty and no longer than 250 characters
158+
description: Description of the stack; must be no longer than 5000 characters
159159
maxLength: 250
160160
metadata:
161161
$ref: ../components/schemas/Metadata.yaml

‎docs/v3/source/includes/resources/stacks/_create.md.erb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Name | Type | Description
4141

4242
Name | Type | Description | Default
4343
---- | ---- | ----------- | -------
44-
**description** | _string_ | Description of the stack; when provided, must be non-empty and no longer than 250 characters | `null`
44+
**description** | _string_ | Description of the stack; must be no longer than 5000 characters | `null`
4545
**metadata.labels** | [_label object_](#labels) | Labels applied to the stack
4646
**metadata.annotations** | [_annotation object_](#annotations) | Annotations applied to the stack
4747
**state** | string | The state of the stack; valid states are: `ACTIVE`, `RESTRICTED`, `DEPRECATED`, `DISABLED`

‎docs/v3/source/includes/resources/stacks/_update.md.erb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Content-Type: application/json
3131

3232
Name | Type | Description
3333
---- | ---- | -----------
34-
**description** | _string_ | Description of the stack; must be non-empty and no longer than 250 characters
34+
**description** | _string_ | Description of the stack; must be no longer than 5000 characters
3535
**metadata.labels** | [_label object_](#labels) | Labels applied to the stack
3636
**metadata.annotations** | [_annotation object_](#annotations) | Annotations applied to the stack
3737
**state** | string | The state of the stack; valid states are: `ACTIVE`, `RESTRICTED`, `DEPRECATED`, `DISABLED`

‎spec/request/stacks_spec.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,11 @@
774774
expect(stack.description).to eq('Preview stack, do not use in production')
775775
end
776776

777-
it 'returns 422 when description is empty' do
778-
patch "/v3/stacks/#{stack.guid}", { description: '' }.to_json, headers
777+
it 'returns 422 when description exceeds the maximum length' do
778+
patch "/v3/stacks/#{stack.guid}", { description: 'A' * 5001 }.to_json, headers
779779

780780
expect(last_response.status).to eq(422)
781-
expect(last_response).to have_error_message("Description can't be blank")
781+
expect(last_response).to have_error_message('Description is too long (maximum is 5000 characters)')
782782
end
783783
end
784784

‎spec/unit/messages/stack_create_message_spec.rb‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,6 @@
8888
expect(subject.errors[:description]).to eq ["is too long (maximum is #{MAX_DESCRIPTION_LENGTH} characters)"]
8989
end
9090
end
91-
92-
context 'when it is an empty string' do
93-
let(:params) { valid_params.merge({ description: '' }) }
94-
95-
it 'returns an error' do
96-
expect(subject).not_to be_valid
97-
expect(subject.errors[:description]).to include("can't be blank")
98-
end
99-
end
100-
101-
context 'when it is only whitespace' do
102-
let(:params) { valid_params.merge({ description: ' ' }) }
103-
104-
it 'returns an error' do
105-
expect(subject).not_to be_valid
106-
expect(subject.errors[:description]).to include("can't be blank")
107-
end
108-
end
109-
110-
context 'when it is explicitly null' do
111-
let(:params) { valid_params.merge({ description: nil }) }
112-
113-
it 'returns an error' do
114-
expect(subject).not_to be_valid
115-
expect(subject.errors[:description]).to include("can't be blank")
116-
end
117-
end
11891
end
11992

12093
describe 'state' do

‎spec/unit/messages/stack_update_message_spec.rb‎

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@
130130
it 'is valid' do
131131
expect(subject).to be_valid
132132
end
133-
134-
it 'reports description not requested' do
135-
expect(subject.description_requested?).to be false
136-
end
137133
end
138134

139135
context 'when it is provided' do
@@ -143,10 +139,6 @@
143139
expect(subject).to be_valid
144140
expect(subject.description).to eq('Preview stack, do not use in production')
145141
end
146-
147-
it 'reports description requested' do
148-
expect(subject.description_requested?).to be true
149-
end
150142
end
151143

152144
context 'when it is at maximum length' do
@@ -169,27 +161,16 @@
169161
context 'when it is an empty string' do
170162
let(:params) { valid_params.merge({ description: '' }) }
171163

172-
it 'returns an error' do
173-
expect(subject).not_to be_valid
174-
expect(subject.errors[:description]).to include("can't be blank")
175-
end
176-
end
177-
178-
context 'when it is only whitespace' do
179-
let(:params) { valid_params.merge({ description: ' ' }) }
180-
181-
it 'returns an error' do
182-
expect(subject).not_to be_valid
183-
expect(subject.errors[:description]).to include("can't be blank")
164+
it 'is valid' do
165+
expect(subject).to be_valid
184166
end
185167
end
186168

187169
context 'when it is explicitly null' do
188170
let(:params) { valid_params.merge({ description: nil }) }
189171

190-
it 'returns an error' do
191-
expect(subject).not_to be_valid
192-
expect(subject.errors[:description]).to include("can't be blank")
172+
it 'is valid' do
173+
expect(subject).to be_valid
193174
end
194175
end
195176
end

0 commit comments

Comments
 (0)