Skip to content

Commit eddb11d

Browse files
committed
fix validation inconsistency
1 parent dc4d6ae commit eddb11d

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

lib/grape/validations/validators/base.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ def validate(request)
3939
def validate!(params)
4040
attributes = AttributesIterator.new(self, @scope, params)
4141
array_errors = []
42-
attributes.each do |resource_params, attr_name, inside_array|
42+
attributes.each do |resource_params, attr_name|
4343
next unless @required || (resource_params.respond_to?(:key?) && resource_params.key?(attr_name))
4444

4545
begin
4646
validate_param!(attr_name, resource_params)
4747
rescue Grape::Exceptions::Validation => e
48-
raise e unless inside_array
4948
# we collect errors inside array because
5049
# there may be more than one error per field
5150
array_errors << e

spec/grape/validations/validators/presence_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def app
145145
it 'validates name, company' do
146146
get '/'
147147
expect(last_response.status).to eq(400)
148-
expect(last_response.body).to eq('{"error":"name is missing"}')
148+
expect(last_response.body).to eq('{"error":"name is missing, company is missing"}')
149149

150150
get '/', name: 'Bob'
151151
expect(last_response.status).to eq(400)

0 commit comments

Comments
 (0)