Running tests in a Rails API application

Run the tests by following:

rails test test/controllers/money_records_controller_test.rb  -v

But getting errors

Error:
MoneyRecordsControllerTest#test_should_update_money_record:
ActiveRecord::Fixture::FixtureError: table "money_records" has no columns named "type".

This might be an issue with the database - which the model has been changed. Now I run below commands:

RAILS_ENV=test rails db:reset
RAILS_ENV=test rails db:migrate

Actually, the issue is in fixture files & in money_records_controller_test.rb because the model has been updated, changed the "type" to "event_type". Fixed thing this and rerun the test command, all looks fine

rails test test/controllers/money_records_controller_test.rb  -v
Running 5 tests in a single process (parallelization threshold is 50)
Run options: -v --seed 36836
# Running:
MoneyRecordsControllerTest#test_should_update_money_record = 2.28 s = .
MoneyRecordsControllerTest#test_should_destroy_money_record = 0.03 s = .
MoneyRecordsControllerTest#test_should_create_money_record = 0.03 s = .
MoneyRecordsControllerTest#test_should_show_money_record = 0.04 s = .
MoneyRecordsControllerTest#test_should_get_index = 0.04 s = .
Finished in 2.452687s, 2.0386 runs/s, 3.6694 assertions/s.
5 runs, 9 assertions, 0 failures, 0 errors, 0 skips 
Back to posts