Skip to content

Commit

Permalink
Does not evaluate original parameter name when custom method is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsales committed Jul 10, 2017
1 parent 3ad1ab7 commit 5f867e0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/rspec_api_documentation/dsl/endpoint/set_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(parent, hash, param)

def call
return hash if path_params.include?(path_name)
return hash unless method_name
return hash unless param_method_name

hash.deep_merge build_param_hash(key_scope || [key])
end
Expand Down Expand Up @@ -44,16 +44,18 @@ def path_params
example.metadata[:route].scan(/:(\w+)/).flatten
end

def method_name
@method_name ||= begin
[custom_method_name, scoped_key, key].find do |name|
name && example_group.respond_to?(name)
end
def param_method_name
if custom_method_name
custom_method_name if example_group.respond_to?(custom_method_name)
elsif scoped_key && example_group.respond_to?(scoped_key)
scoped_key
elsif key && example_group.respond_to?(key)
key
end
end

def build_param_hash(keys)
value = keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(method_name)
value = keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(param_method_name)
{ keys[0].to_s => value }
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'
require 'rspec_api_documentation/dsl'
require 'net/http'
require "rack/test"

describe "Non-api documentation specs" do
it "should not be polluted by the rspec api dsl" do |example|
Expand Down Expand Up @@ -396,6 +397,36 @@
do_request
end
end

context "with reserved name parameter" do
context "without custom method name" do
parameter :status, "Filter order by status"

example "does not work as expected" do
expect { do_request }.to raise_error Rack::Test::Error, /No response yet/
end
end

context "with custom method name" do
parameter :status, "Filter order by status", method: :status_param

context "when parameter value is not specified" do
example "does not serialize param" do
expect(client).to receive(method).with("/orders", anything, anything)
do_request
end
end

context "when parameter value is specified" do
let(:status_param) { "pending" }

example "serializes param" do
expect(client).to receive(method).with("/orders?status=pending", anything, anything)
do_request
end
end
end
end
end
end

Expand Down

0 comments on commit 5f867e0

Please sign in to comment.