Trying understand syntax for testing around the Tire gem.
This controller spec (default from a scaffold template) is failing
describe "GET index" do
it "assigns all reports as @reports" do
report = Report.create! valid_attributes
get :index, {}, valid_session
assigns(:reports).should eq([report])
end
end
because
Failure/Error: assigns(:reports).should eq([report])
TypeError:
can't convert Tire::Results::Collection to Array (Tire::Results::Collection#to_ary gives Tire::Results::Collection)
How to write the spec so that it expects a Tire result collection instead of an array of active record objects? Or, is there a better way to go about this?
FWIW-
class ReportsController < ApplicationController
def index
@reports = Report.search(params)
end
...
and the model:
class Report < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
...
def self.search(params)
tire.search(load: true) do
query { string params[:query] } if params[:query].present?
end
end
...