Skip to content

Commit 16f6fea

Browse files
authored
Merge pull request #352 from rafaelsales/reserved-params
Don't evaluate original parameter name when custom method is provided
2 parents e4bd4cf + 011f341 commit 16f6fea

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

lib/rspec_api_documentation/dsl/endpoint/set_param.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ def path_params
4545
end
4646

4747
def method_name
48-
@method_name ||= begin
49-
[custom_method_name, scoped_key, key].find do |name|
50-
name && example_group.respond_to?(name)
51-
end
48+
if custom_method_name
49+
custom_method_name if example_group.respond_to?(custom_method_name)
50+
elsif scoped_key && example_group.respond_to?(scoped_key)
51+
scoped_key
52+
elsif key && example_group.respond_to?(key)
53+
key
5254
end
5355
end
5456

spec/dsl_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'spec_helper'
22
require 'rspec_api_documentation/dsl'
33
require 'net/http'
4+
require "rack/test"
45

56
describe "Non-api documentation specs" do
67
it "should not be polluted by the rspec api dsl" do |example|
@@ -396,6 +397,36 @@
396397
do_request
397398
end
398399
end
400+
401+
context "with reserved name parameter" do
402+
context "without custom method name" do
403+
parameter :status, "Filter order by status"
404+
405+
example "does not work as expected" do
406+
expect { do_request }.to raise_error Rack::Test::Error, /No response yet/
407+
end
408+
end
409+
410+
context "with custom method name" do
411+
parameter :status, "Filter order by status", method: :status_param
412+
413+
context "when parameter value is not specified" do
414+
example "does not serialize param" do
415+
expect(client).to receive(method).with("/orders", anything, anything)
416+
do_request
417+
end
418+
end
419+
420+
context "when parameter value is specified" do
421+
let(:status_param) { "pending" }
422+
423+
example "serializes param" do
424+
expect(client).to receive(method).with("/orders?status=pending", anything, anything)
425+
do_request
426+
end
427+
end
428+
end
429+
end
399430
end
400431
end
401432

0 commit comments

Comments
 (0)