File tree Expand file tree Collapse file tree
lib/generators/factory_bot/authentication Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,3 +90,21 @@ Feature:
9090 And I run `bundle exec rails generate model User name:string age:integer` with a clean environment
9191 Then the output should not contain "test/factories/users.rb"
9292 And the output should contain "test/fixtures/users.yml"
93+
94+
95+ @rails_8
96+ Scenario : The factory_bot_rails authentication generator, coupled with rspec-rails, creates a user factory file
97+ When I add "rspec-rails" as a dependency
98+ And I run `bundle install --verbose` with a clean environment
99+ Then the output should contain "rspec-rails"
100+ And I run `bundle exec rails generate authentication` with a clean environment
101+ Then the output should contain "spec/factories/users.rb"
102+ And the file "spec/factories/users.rb" should contain exactly:
103+ """
104+ FactoryBot.define do
105+ factory :user do
106+ email_address { "user@example.com" }
107+ password { "password" }
108+ end
109+ end
110+ """
Original file line number Diff line number Diff line change 1111 setup_aruba
1212end
1313
14+ Before ( "@rails_8" ) do
15+ rails_version = Gem ::Version . new (
16+ Bundler . load . specs . find { |spec | spec . name == 'rails' } &.version . to_s
17+ )
18+ required_version = Gem ::Version . new ( '8.0.0' )
19+
20+ if rails_version < required_version
21+ skip_this_scenario ( "Requires Rails 8.0 or higher (current: #{ rails_version } )" )
22+ end
23+ end
24+
1425if RUBY_PLATFORM == "java"
1526 Aruba . configure do |config |
1627 config . before_cmd do
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ source "https://rubygems.org"
44
55gem "appraisal"
66gem "aruba"
7+ gem "bcrypt", "~> 3.1.7"
78gem "brakeman"
89gem "byebug"
910gem "cucumber"
Original file line number Diff line number Diff line change 1- # frozen_string_literal: true
2-
31require "generators/factory_bot"
2+ require "generators/factory_bot/model/model_generator"
43require "factory_bot_rails"
5- require "fileutils"
4+
65
76module FactoryBot
87 module Generators
9- class AuthenticationGenerator < Base
10- def create_users_factory
11- dir = factories_dir
12- FileUtils . mkdir_p ( dir )
8+ FixedAttribute = Struct . new ( :name , :default )
139
14- target = File . join ( dir , "users.rb" )
15- if File . exist? ( target )
16- say_status :skip , "users.rb already exists at #{ target } " , :yellow
17- else
18- template "users.rb" , target
19- say_status :create , target , :green
20- end
21- end
10+ class AuthenticationGenerator < ModelGenerator
11+ self . source_paths << File . join ( File . dirname ( __FILE__ ) , "../model/templates" )
2212
2313 private
2414
25- def factories_dir
26- if Dir . exist? ( Rails . root . join ( "spec" ) )
27- Rails . root . join ( "spec" , "factories" ) . to_s
28- else
29- Rails . root . join ( "test" , "factories" ) . to_s
30- end
15+ def attributes
16+ [
17+ FixedAttribute . new ( :email_address , "user@example.com" ) ,
18+ FixedAttribute . new ( :password , "password" )
19+ ]
3120 end
3221 end
3322 end
You can’t perform that action at this time.
0 commit comments