I have model:
class Topic < ActiveRecord::Base
attr_accessible :title, :description
has_many :comments, :dependent => :destroy
end
And:
class Comment < ActiveRecord::Base
attr_accessible :body, :topic_id
belongs_to :topic
end
In my topic_spec.rb:
it "should have the right associated comment" do
@topic.comments.should include(@comment)
end
it "should destroy associated comments" do
@topic.destroy
Comment.find_by_id(@comment.id).should be_nil
end
And I receive following errors:
1) Failure/Error: @topic.comments.should == @comment
NameError:
undefined method `inspect' for class `ActiveRecord::Associations::CollectionProxy'
2) Failure/Error: Comment.find_by_id(@comment.id).should be_nil
expected: nil
got: #<Comment id: 1, body: "first", created_at: "2011-08-18 09:55:06", updated_at: "2011-08-18 09:55:06">
What I doing wrong? This errors appeared after I started using sunspot.
In my topic.rb:
searchable :auto_index => true, :auto_remove => true do
text :title, :boost => 5
text :description
text :comments do
comments.map(&:body)
end
end
If I commented this lines:
# text :comments do
# comments.map(&:body)
# end
All tests successfully pass!
I solved this problem by adding following lines in
spec_helper.rb: