Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 2cd0e5f

Browse files
reidmitTeal Stannard
andcommitted
v3: Improve error when multiple timestamps are given w/operator
Previously, we were giving an error like `has an invalid timestamp format. Timestamps should be formatted as 'YYYY-MM-DDThh:mm:ssZ'`. Now, we detect that you are giving multiple comma-separated values and give an error like `only accepts one value when using an inequality filter`. [finishes #173575312] Co-authored-by: Reid Mitchell <rmitchell@pivotal.io> Co-authored-by: Teal Stannard <tstannard@pivotal.io>
1 parent c5865d9 commit 2cd0e5f

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

app/messages/events_list_message.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def validate(record)
2727
record.errors[:created_ats] << "Invalid comparison operator: '#{comparison_operator}'"
2828
end
2929

30+
if timestamp.to_s.include?(',')
31+
record.errors[:created_ats] << 'only accepts one value when using an inequality filter'
32+
next
33+
end
34+
3035
opinionated_iso_8601(timestamp, record)
3136
end
3237
end

spec/unit/messages/events_list_message_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ module VCAP::CloudController
128128
expect(message).to be_valid
129129
end
130130

131+
it 'does not allow multiple timestamps with an operator' do
132+
message = EventsListMessage.from_params({ created_ats: { gte: "#{Time.now.utc.iso8601},#{Time.now.utc.iso8601}" } })
133+
expect(message).not_to be_valid
134+
expect(message.errors[:created_ats]).to include('only accepts one value when using an inequality filter')
135+
end
136+
131137
context 'when the operator is an equals operator' do
132138
it 'allows the equals operator' do
133139
message = EventsListMessage.from_params({ 'created_ats' => Time.now.utc.iso8601 })

0 commit comments

Comments
 (0)