I'm trying to pass an array in the query string of an rspec test but it's giving me an error. I will be sending query strings like "products[]=desk,chair" and expect the controller to be able to handle it.
Here's the error:
Failure/Error: get :index, { :format => :json, :products => [product_1, product_2]}, { "Accept" => "application/json" }
NoMethodError:
undefined method `each' for "[\"desk\", \"chair\"]":String
Here's my test method:
product_1 = "desk"
product_2 = "chair"
get :index, { :format => :json, :products => [product_1, product_2]}, { "Accept" => "application/json" }
Heres my controller:
products.each do |product|
puts "product: #{product}"
end
def products
params[:products].to_s
end
Any ideas?
Note: this is running Rails 3.2.12
products[]=desk&products[]=chairif you want an array.