在 rails 应用程序中测试 ActiveRecords 时使用并行 gem

Using parallel gem when testing ActiveRecords in rails application

我正在使用 MiniTest,在我的测试用例中,我正在创建一个像这样的 ActiveRecord

test 'importing game from confirmed list' do
  Nba::Game.create(stats_id: 1)
  Data::SportData::ProcessUpdate.new(season_id: 2015, league: 'nba').process_boxscores
end

那么,我运行的process_boxscores方法就是

def process_boxscores
   #Nba::Game.all = [#<Nba::Game id: 1, stats_id: 1, created_at: "2015-12-07 20:39:26", updated_at: "2015-12-07 20:39:26">]
   loaders = Parallel.map(list, in_threads: 4) {|game| 
     #Nba::Game.all = []
     build_boxscore_loader(game)
   }.compact
end

在该方法中,正在使用并行 gem 来加速进程,但它不知何故不显示数据库中的活动记录。

我在并行块外和并行块内注释掉了Nba::Game.all的结果

关于为什么在并行块内它不能识别 activerecord 的任何想法?

我用 github issue 解决了这个问题,希望这对其他人有帮助