Rails设置后最小的不一致数据

时间:2018-04-20 12:54:11

标签: ruby-on-rails minitest

我一直在跟随我的问题而没有运气: 尝试测试rake任务正确填充某些表,我有以下配置:

class InitialDataTest < ApplicationSystemTestCase
  def setup
    DatabaseCleaner.clean_with :truncation, only: %w[centres projects departments]
    System::Application.load_tasks
    Rake::Task['populate_lookup_tables:commit'].invoke

    sign_in users(:test_user)
  end

  test 'projects are created' do
    puts " Projects: #{Project.count}"
  end

  test 'centres are created' do
    puts "Centres: #{Centre.count}"
  end

  test 'departments are created' do
    puts " Departments: #{Department.count}"
  end
end

我的rake任务实际上按预期工作(例如在开发中),但是,对于测试,似乎只填充了1个表:

Running via Spring preloader in process 15362
Started with run options --seed 17058

:: Centre populated successfully
:: Project populated successfully
:: Department populated successfully
>> OperationType is not empty
>> DocumentType is not empty
>> RecordErrorType is not empty

Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.3-p222), codename: Private Caller
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:51272
Use Ctrl-C to stop
Departments: 5
Centres: 0
Projects: 0
3/3[========================================================] 100% Time: 00:00:03, Time: 00:00:03

Finished in 3.88633s
3 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to <My Stuff> (28.45%) covered.

1 个答案:

答案 0 :(得分:0)

默认情况下,Rake任务只能在给定的上下文中调用一次。如果您想再次运行它,则需要先调用Rake::Task['populate_lookup_tables:commit'].reenable