-
Notifications
You must be signed in to change notification settings - Fork 533
Troubleshooting RSpec issues
match_array
comparison in RSpec requires index
to not defined in the model. Tire, however, will overload index
to model as class method and instance method. This breaks when the object on the lefthand side of the comparison is ActiveRecord::Relation
(e.g. called from a scope) since ActiveRecord::Delegation
will attempt to delegate it to the Model#index
instead of Array#index
. You have two solutions.
Add this to your model:
class << self
remove_method :index
end
This will remove the index
method from your class method. You can still access Tire index using Model.tire.index
.
Instead of doing Model.scoped.should match_array Model.where("query")
you can do this:
Model.scoped.to_a.should match_array Model.where("query")
However, in this case lefthand side will evaluated first. This won't work if you rely on laziness of the righthand side comparison (e.g. with subject
or let
).
Do note, that simply having an index
method in your model will break RSpec in the same way:
class Book < ActiveRecord::Base
attr_accessible :title
scope :titled, where("title IS NOT NULL")
class << self
def index
"Blah"
end
end
end
See issue https://github.com/karmi/tire/issues/456.