samedi 23 mai 2020

How to test json format with specific url use RSpec Rails 4.0?

I need to test url like "/users.json?search=" + "[params]":

it "renders a successful response" do
 get :show, params: "/users.json?search=c"
 expect(response).to have_http_status(200)
 expect(response).to be_successful
end

My controller like

def index
  @users = User.search(params[:search]).limit(10)

  respond_to do |f|
    f.json { render json: @users }
  end
end

When I run test I have this error:

Failure/Error: before { get :show, params: "/users.json?search=unk" }

NoMethodError:
undefined method `symbolize_keys' for "/users.json?search=unk":String
```

Aucun commentaire:

Enregistrer un commentaire