Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't evaluate original parameter name when custom method is provided #352

Merged
merged 1 commit into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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