How do I write a test for posting a file to my controller?

I’m posting a CSV file from my front end to my backend API, and I’d like to write a unit test using ActionController::TestCase. In Rails 2 and 3 there was a helper, but it doesn’t seem to exist in Rails 6…

Any pointers, or am I thinking about this wrong?

In Rails 7 tests are based on ActiveSupport::TestCase. Controller tests extend that with ActionDispatch::IntegrationTest. See Testing Rails Applications — Ruby on Rails Guides.

1 Like

You can use fixture_file_upload fixture_file_upload (ActionController::TestProcess) - APIdock

1 Like

Thank you for this…!!!

1 Like