0
I’m using the rspec-Rails to test my application, however while testing a view using Ransak for filters I have the following return error:
1) admin/cities/index renders a list of admin_cities
Failure/Error: render
ActionView::Template::Error:
No Ransack::Search object was provided to search_form_for!
My controller
def index
@q = City.search(params[:q])
@cities = @q.result(distinct: true).page params[:page]
end
My view
= search_form_for [:admin, @q] do |f|
= f.text_field :nome_cont
table
tr
th Nome
- @cities.each do |city|
tr
td = city.nome
My test
require 'rails_helper'
RSpec.describe "admin/cities/index", type: :view do
city_params1 = {codigo_municipio: 1, nome: 'Maringá', uf: 'PR', municipio: 1}
city_params2 = {codigo_municipio: 2, nome: 'Maringá2', uf: 'PR', municipio: 1}
before(:each) do
assign(:admin_cities, [
City.create!(city_params1),
City.create!(city_params2)
])
end
it "renders a list of admin_cities" do
render
end
end
What could fix this?