Skip to content

Commit

Permalink
Merge pull request #352 from rafaelsales/reserved-params
Browse files Browse the repository at this point in the history
Don't evaluate original parameter name when custom method is provided
  • Loading branch information
oestrich authored Sep 27, 2017
2 parents e4bd4cf + 011f341 commit 16f6fea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/rspec_api_documentation/dsl/endpoint/set_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ def path_params
end

def method_name
@method_name ||= begin
[custom_method_name, scoped_key, key].find do |name|
name && example_group.respond_to?(name)
end
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

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 16f6fea

Please sign in to comment.