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
```

1 Answer 1

1

In Rails 4, you pass the params without defining the params key:

get :show, format: :json, search: c

As of Rails 5, you pass the params with the params key:

get :show, format: :json, params: { search: c }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.