From 011f3410333a16de5272c71dad209578f9e2f947 Mon Sep 17 00:00:00 2001 From: Rafael Sales Date: Sun, 9 Jul 2017 23:20:29 -0300 Subject: [PATCH] Does not evaluate original parameter name when custom method is provided --- .../dsl/endpoint/set_param.rb | 10 +++--- spec/dsl_spec.rb | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/rspec_api_documentation/dsl/endpoint/set_param.rb b/lib/rspec_api_documentation/dsl/endpoint/set_param.rb index f2927658..760212b2 100644 --- a/lib/rspec_api_documentation/dsl/endpoint/set_param.rb +++ b/lib/rspec_api_documentation/dsl/endpoint/set_param.rb @@ -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 diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index ec6cff5f..77756733 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -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| @@ -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