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

Support Rails 8 authentication generator #519

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions features/generators.feature
Original file line number Diff line number Diff line change
@@ -90,3 +90,19 @@ Feature:
And I run `bundle exec rails generate model User name:string age:integer` with a clean environment
Then the output should not contain "test/factories/users.rb"
And the output should contain "test/fixtures/users.yml"

Scenario: The factory_bot_rails authentication generator, coupled with rspec-rails, creates a user factory file
When I add "rspec-rails" with options `github: "rspec/rspec-rails", branch: "main"` as a dependency
And I run `bundle install --verbose` with a clean environment
Then the output should contain "rspec-rails"
And I run `bundle exec rails generate authentication` with a clean environment
Then the output should contain "test/factories/users.rb"
And the file "test/factories/users.rb" should contain exactly:
"""
FactoryBot.define do
factory :user do
email_address { "[email protected]" }
password_digest { "MyString" }
end
end
"""
4 changes: 4 additions & 0 deletions features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@
append_to_file("Gemfile", %(gem "#{gem_name}"\n))
end

When(/^I add "([^"]+)" with options `(.+)` as a dependency$/) do |gem_name, options|
append_to_file("Gemfile", %(gem "#{gem_name}", #{options}\n))
end

When(/^I print out "([^"]*)"$/) do |path|
in_current_dir do
File.open(path, "r") do |f|
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "generators/factory_bot"
require "factory_bot_rails"

module FactoryBot
module Generators
class AuthenticationGenerator < Base
def create_fixture_file
template "users.rb", "test/factories/users.rb"
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :user do
email_address { "[email protected]" }
password_digest { "MyString" }
end
end