Lately, I was refactoring authentication on a Rails application, a big refactoring on a recent application. I found myself filling authentication form several times by minute.

I decided to code a test to save time on filling this form.

Run tests

First let’s check if tests are configured.

$ rails test
/Users/kevin/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/activerecord-8.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:69:in 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new_client': connection to server at "::1", port 5432 failed: Connection refused (ActiveRecord::ConnectionNotEstablished)
        Is the server running on that host and accepting TCP/IP connections?
connection to server at "127.0.0.1", port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?

Surprise!

Tests look wired to database out of the box.

Reading documentation1, I get that it is in the spirit of Rails testing. You’re always end up finding yourself testing something with some model.