Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rails 8 authentication generator #2811

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

jeromedalbert
Copy link
Contributor

@jeromedalbert jeromedalbert commented Nov 11, 2024

Fixes #2810.

Problem

When running Rails 8's bin/rails generate authentication, generation ends with with the following error: error rspec [not found].

This is because the Rails AuthenticationGenerator contains hook_for :test_framework, which calls rspec-rails, but it errors out since rspec-rails does not have an authentication generator.

Solution

Add authentication generator that creates a user test and possibly a fixture, similarly to Rails' TestUnit::Generators::AuthenticationGenerator. The fixture is basically the same as the Rails one except that it has a comment similar to rspec-rails' model fixture.

An alternative solution could be to somehow disable the authentication generator for rspec-rails so nothing is generated while not having any errors. This might be a viable option if Rails adds more generators in the future and playing catch-up is undesired.

@jeromedalbert jeromedalbert force-pushed the authentication-generator branch 3 times, most recently from a2471be to 1d18e60 Compare November 11, 2024 09:37
@JonRowe
Copy link
Member

JonRowe commented Nov 13, 2024

I think this is a good start, I'm sort of wondering if it makes sense to add some scaffold specs showing that login works but I think I'm right in thinking the generator as is doesn't generate any tests at all?

@jeromedalbert
Copy link
Contributor Author

jeromedalbert commented Nov 13, 2024

I think I'm right in thinking the generator as is doesn't generate any tests at all?

Correct, the Rails 8 generator doesn't generate any controller or integration or system tests or anything, I guess the Rails team decided to leave these as an exercise for the user. The only test it generates is an empty test/models/user_test.rb ActiveSupport::TestCase, and a fixture. So this PR is doing the same in the RSpec world.

I think that if Rails generates more tests in a future version, such as login tests, then the same could be done in rspec-rails.

@JonRowe JonRowe merged commit 7df09ce into rspec:main Nov 13, 2024
18 checks passed
JonRowe added a commit that referenced this pull request Nov 13, 2024
@JonRowe
Copy link
Member

JonRowe commented Nov 13, 2024

Thanks!

@jeromedalbert jeromedalbert deleted the authentication-generator branch November 13, 2024 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lacks a corresponding generator to the Rails 8 authentication system generator
2 participants