ruby-on-railsrspecruby-on-rails-5rswag

when running rspec for rswag, key and value join together in the parameters as key and value become nil?


    get 'customer' do
      security [Token: []]
      parameter name: :params, in: :body, schema: {
        type: :object,
        properties: {
          search: { type: :string, example: Faker::Name.first_name }
        }
      }
      let(:params) { { search: Faker::Name.first_name } }

by considering the above code, the params will be this :

<ActionController::Parameters {"{\"search\":\"test_name\"}"=>nil, "controller"=>"api/v1/admin/staffs", "action"=>"new", "staff"=>{}} permitted: false>

so the search and faker:name.first_name attach in params as key, but i want search become key and faker become value.


Solution

  • you are using body params on get request. try this:

    get 'customer' do
      security [Token: []]
      type: :object,
      parameter name: :search, in: :query, type: :string, example: Faker::Name.first_name
      let(:search) { Faker::Name.first_name }
    .
    .
    .