rspec_api_documentation icon indicating copy to clipboard operation
rspec_api_documentation copied to clipboard

Extra parameters are passing to the controller

Open pedramteymoori opened this issue 8 years ago • 1 comments

Hi!

Imagine you have an endpoint test like below :

  post '/api/v0/users' do
    parameter :email
    parameter :role_ids, required: false

    example 'do_req' do
      do_request(email: [email protected])
    end
  end

  # In related controller
  params.keys.include?(:email)    # => True
  params[:email]                  # => "[email protected]"
  params.keys.include?(:role_ids) # => True (why?)
  params[:role_ids]               # => nil

As you can see, params[:role_ids] exists although I don't pass it to do_request

Is there any option to disable this behaviour?

In my case, because of a bug in rails_params gem following validation fails when params[:role_id] is nil.

role_ids = param! :role_ids, Array do |array, index|
  array.param! index, String
end


> NoMethodError:
>    undefined method `each_with_index' for nil:NilClass

Ruby : 2.2.3 Rails : 4.2.6

pedramteymoori avatar Aug 06 '16 13:08 pedramteymoori

+1 this is happening to me also! Not sure why, but looks happen in https://github.com/zipmark/rspec_api_documentation/blob/d3892cc7388460a98476734963face5a7a2ac158/lib/rspec_api_documentation/dsl/endpoint/set_param.rb#L11

twss avatar Jan 27 '23 12:01 twss