Skip to content

Commit

Permalink
Updated custom validations spec
Browse files Browse the repository at this point in the history
  • Loading branch information
schinery committed Oct 23, 2023
1 parent 5ecb7c7 commit 32ca429
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions spec/grape/api/custom_validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ def validate(request)

# check if user is admin or not
# as an example get a token from request and check if it's admin or not
header = if Gem::Version.new(Rack.release) < Gem::Version.new('3')
'X-Access-Token'
else
'x-access-token'
end
raise Grape::Exceptions::Validation.new(params: @attrs, message: 'Can not set Admin only field.') unless request.headers[header] == 'admin'
raise Grape::Exceptions::Validation.new(params: @attrs, message: 'Can not set Admin only field.') unless request.headers[access_header] == 'admin'
end

def access_header
if Gem::Version.new(Rack.release) < Gem::Version.new('3')
'X-Access-Token'
else
'x-access-token'
end
end
end
end
Expand Down

0 comments on commit 32ca429

Please sign in to comment.