Skip to content

Commit

Permalink
Forbid use of reserved parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsales committed Jul 10, 2017
1 parent 3ad1ab7 commit dd578a8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/rspec_api_documentation/dsl/endpoint/set_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ module RspecApiDocumentation
module DSL
module Endpoint
class SetParam
RESERVED_WORDS = %w(status)

def initialize(parent, hash, param)
@parent = parent
@hash = hash
@param = param

if reserved_word?(key) && !custom_method_name
raise ArgumentError, "Parameter name '#{key}' is reserved. " \
"Please provide `method` argument with custom method name."
end
end

def call
Expand Down Expand Up @@ -46,12 +53,16 @@ def path_params

def method_name
@method_name ||= begin
[custom_method_name, scoped_key, key].find do |name|
name && example_group.respond_to?(name)
[custom_method_name, scoped_key, key].compact.find do |name|
example_group.respond_to?(name) && !reserved_word?(name)
end
end
end

def reserved_word?(word)
RESERVED_WORDS.include?(word.to_s)
end

def build_param_hash(keys)
value = keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(method_name)
{ keys[0].to_s => value }
Expand Down

0 comments on commit dd578a8

Please sign in to comment.