<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt" -->

---
title: Testing authentication in Rails | daily.dev
description: A step-by-step chapter walks through testing Rails 8's built-in authentication generator in a sample Cookbook app built with Minitest. It covers generating...
canonical: https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Testing authentication in Rails | daily.dev
og:description: A step-by-step chapter walks through testing Rails 8's built-in authentication generator in a sample Cookbook app built with Minitest. It covers generating...
og:url: https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt
og:image: https://api.daily.dev/og/posts/MYv1qPXBt.png
og:image:alt: Testing authentication in Rails
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing authentication in Rails

**[Ruby Flow](https://daily.dev/sources/rubyflow)** · 38 min read · 0 upvotes · 0 comments

## Summary

A step-by-step chapter walks through testing Rails 8's built-in authentication generator in a sample Cookbook app built with Minitest. It covers generating authentication, adding user fixtures, writing a current_user helper, testing sign-in and sign-out over integration and system tests, restricting guests to read-only access while allowing signed-in users full CRUD, and setting up session helpers for both integration and system test suites.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://minitestrails.com/guide/testing-authentication>

## Questions this post answers

### How do I test Rails 8 built-in authentication with Minitest?

Use the sign_in_as helper for integration tests, which creates a real Session row and sets the signed session_id cookie directly, and a custom sign_in_to_ui_as helper for system tests that visits the sign-in page then injects the signed cookie into the browser. Reserve driving the actual sign-in form for testing the sign-in flow itself; use the cookie-injection helpers for everything else that just needs an existing session.

_Developers wiring up Rails 8 auth tests can compare approaches like this on daily.dev before writing their own helpers._

### What files does the Rails 8 generate authentication command create?

Running bin/rails generate authentication creates app/models/user.rb, session.rb, and current.rb, an Authentication concern in app/controllers/concerns, sessions_controller.rb and passwords_controller.rb, a passwords_mailer, views for sessions and passwords, migrations for users and sessions tables, and a session_test_helper.rb for integration tests, plus a starter users.yml fixture.

_Rails developers evaluating the built-in generator versus Devise can track this kind of breakdown on daily.dev._

### How do I restrict guest users to read-only access in a Rails app using the authentication concern?

Add allow_unauthenticated_access only: %i[index show] to the controller so index and show skip the require_authentication before_action while every other action still requires a session. Wrap New, Edit, Destroy, and Remove buttons in views with an authenticated? check so guests never see controls for actions they cannot perform.

_Teams designing guest versus signed-in permissions in Rails can dig into patterns like this on daily.dev._

## Similar posts on daily.dev

- [Testing JSON APIs in Rails](https://daily.dev/posts/testing-json-apis-in-rails-9cgptzglb) · Ruby Flow · 1 upvotes · 0 comments
- [Authorization testing in Rails](https://daily.dev/posts/authorization-testing-in-rails-wcdiqgboi) · Ruby Flow · 0 upvotes · 0 comments
- [How to Test User Registration with Minitest Rails](https://daily.dev/posts/how-to-test-user-registration-with-minitest-rails-kmrtpfv3e) · Ruby Flow · 0 upvotes · 0 comments
- [Test Driving Rails](https://daily.dev/posts/test-driving-rails-ultya1fh1) · Ruby Flow · 0 upvotes · 0 comments
- [Migrate from Devise to Rails authentication generator](https://daily.dev/posts/migrate-from-devise-to-rails-authentication-generator-4ulkcxakw) · RUBYLAND · 0 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#authentication](https://daily.dev/tags/authentication), [#rails](https://daily.dev/tags/rails)

[View this post on daily.dev](https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Testing authentication in Rails","url":"https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt"},"datePublished":"2026-08-13T21:55:27.746Z","dateModified":"2026-08-13T22:14:09.984Z","description":"A step-by-step chapter walks through testing Rails 8's built-in authentication generator in a sample Cookbook app built with Minitest. It covers generating...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f9434c996ff2a0b7afb67a9cbe94d368?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f9434c996ff2a0b7afb67a9cbe94d368?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Ruby Flow","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Ruby Flow","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/a21aaa8bcbbf448193a016895c90a0e1","url":"https://daily.dev/sources/rubyflow"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,authentication,rails","timeRequired":"PT38M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Ruby Flow","item":"https://daily.dev/sources/rubyflow"},{"@type":"ListItem","position":3,"name":"Testing authentication in Rails"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt#faq","mainEntity":[{"@type":"Question","name":"How do I test Rails 8 built-in authentication with Minitest?","acceptedAnswer":{"@type":"Answer","text":"Use the sign_in_as helper for integration tests, which creates a real Session row and sets the signed session_id cookie directly, and a custom sign_in_to_ui_as helper for system tests that visits the sign-in page then injects the signed cookie into the browser. Reserve driving the actual sign-in form for testing the sign-in flow itself; use the cookie-injection helpers for everything else that just needs an existing session. Developers wiring up Rails 8 auth tests can compare approaches like this on daily.dev before writing their own helpers."}},{"@type":"Question","name":"What files does the Rails 8 generate authentication command create?","acceptedAnswer":{"@type":"Answer","text":"Running bin/rails generate authentication creates app/models/user.rb, session.rb, and current.rb, an Authentication concern in app/controllers/concerns, sessions_controller.rb and passwords_controller.rb, a passwords_mailer, views for sessions and passwords, migrations for users and sessions tables, and a session_test_helper.rb for integration tests, plus a starter users.yml fixture. Rails developers evaluating the built-in generator versus Devise can track this kind of breakdown on daily.dev."}},{"@type":"Question","name":"How do I restrict guest users to read-only access in a Rails app using the authentication concern?","acceptedAnswer":{"@type":"Answer","text":"Add allow_unauthenticated_access only: %i[index show] to the controller so index and show skip the require_authentication before_action while every other action still requires a session. Wrap New, Edit, Destroy, and Remove buttons in views with an authenticated? check so guests never see controls for actions they cannot perform. Teams designing guest versus signed-in permissions in Rails can dig into patterns like this on daily.dev."}}]}
```

