2021-01-07 17:25

FactoryGirl + RSpec not updating indexes

It seems like the indexes in my test environment aren't being updated after the creation of my factories (it works perfectly in development). I've tried


as well as

bundle exec rake sunspot:solr:reindex RAILS_ENV=test

Any suggestions?


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39613692 weixin_39613692 4月前

    Do you have transactional fixtures turned on? If you do, in your factories you'll have to have a hook like so: after_create { |c| c.index! }

    点赞 评论 复制链接分享
  • weixin_39695672 weixin_39695672 4月前

    Thanks for the response. I am indeed using transactional fixtures however having that callback in my factory doesn't seem to work for me. The callback is working--it's the .index! method that I'm not having success with it. I tried calling it directly in my tests for my factories

    p = Factory :foo

    and also had no luck with that. Any ideas?

    点赞 评论 复制链接分享
  • weixin_39613692 weixin_39613692 4月前

    Are you using the StubSessionProxy? What's returned when you call Sunspot.session?

    Are you seeing anything in the logs? When you call index! you should get a "SOLR Request" line followed immediately by a "Solr Commit" line.

    点赞 评论 复制链接分享
  • weixin_39695672 weixin_39695672 4月前

    Thanks for your help, figured it out. It wasn't clearing my previous indexes which was messing me up. Before my tests, I had to do something like

    点赞 评论 复制链接分享