Reputation: 63
I've been hitting my head with following issue with no luck: Trying to test that a rake task populates some tables correctly, I have following configuration:
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
My rake task actually works as expected (in development, for instance) however, for the test it seems that only 1 table is being populated:
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.
Upvotes: 1
Views: 73
Reputation: 24617
By default, Rake task can be only invoked once in a given context. If you want to run it again you need to call Rake::Task['populate_lookup_tables:commit'].reenable
first.
Upvotes: 2