diff --git a/Gemfile.lock b/Gemfile.lock index 65ac0d27..bf375624 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,9 +8,9 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (8.0.2) - actionview (= 8.0.2) - activesupport (= 8.0.2) + actionpack (8.0.2.1) + actionview (= 8.0.2.1) + activesupport (= 8.0.2.1) nokogiri (>= 1.8.5) rack (>= 2.2.4) rack-session (>= 1.0.1) @@ -18,28 +18,28 @@ GEM rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actionview (8.0.2) - activesupport (= 8.0.2) + actionview (8.0.2.1) + activesupport (= 8.0.2.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (8.0.2) - activesupport (= 8.0.2) + activejob (8.0.2.1) + activesupport (= 8.0.2.1) globalid (>= 0.3.6) - activemodel (8.0.2) - activesupport (= 8.0.2) - activerecord (8.0.2) - activemodel (= 8.0.2) - activesupport (= 8.0.2) + activemodel (8.0.2.1) + activesupport (= 8.0.2.1) + activerecord (8.0.2.1) + activemodel (= 8.0.2.1) + activesupport (= 8.0.2.1) timeout (>= 0.4.0) - activestorage (8.0.2) - actionpack (= 8.0.2) - activejob (= 8.0.2) - activerecord (= 8.0.2) - activesupport (= 8.0.2) + activestorage (8.0.2.1) + actionpack (= 8.0.2.1) + activejob (= 8.0.2.1) + activerecord (= 8.0.2.1) + activesupport (= 8.0.2.1) marcel (~> 1.0) - activesupport (8.0.2) + activesupport (8.0.2.1) base64 benchmark (>= 0.3) bigdecimal @@ -56,55 +56,55 @@ GEM bundler rake thor (>= 0.14.0) - aruba (2.3.0) + aruba (2.3.1) bundler (>= 1.17, < 3.0) contracts (>= 0.16.0, < 0.18.0) - cucumber (>= 8.0, < 10.0) + cucumber (>= 8.0, < 11.0) rspec-expectations (~> 3.4) thor (~> 1.0) ast (2.4.3) base64 (0.3.0) benchmark (0.4.1) - bigdecimal (3.2.2) - bigdecimal (3.2.2-java) + bigdecimal (3.2.3) + bigdecimal (3.2.3-java) builder (3.3.0) concurrent-ruby (1.3.5) - connection_pool (2.5.3) + connection_pool (2.5.4) contracts (0.17.2) crass (1.0.6) - cucumber (9.2.1) + cucumber (10.1.0) + base64 (~> 0.2) builder (~> 3.2) cucumber-ci-environment (> 9, < 11) - cucumber-core (> 13, < 14) - cucumber-cucumber-expressions (~> 17.0) - cucumber-gherkin (> 24, < 28) + cucumber-core (> 15, < 17) + cucumber-cucumber-expressions (> 17, < 19) cucumber-html-formatter (> 20.3, < 22) - cucumber-messages (> 19, < 25) diff-lcs (~> 1.5) + logger (~> 1.6) mini_mime (~> 1.1) multi_test (~> 1.1) - sys-uname (~> 1.2) + sys-uname (~> 1.3) cucumber-ci-environment (10.0.1) - cucumber-core (13.0.3) - cucumber-gherkin (>= 27, < 28) - cucumber-messages (>= 20, < 23) + cucumber-core (15.2.1) + cucumber-gherkin (> 27, < 33) + cucumber-messages (> 26, < 30) cucumber-tag-expressions (> 5, < 7) - cucumber-cucumber-expressions (17.1.0) + cucumber-cucumber-expressions (18.0.1) bigdecimal - cucumber-gherkin (27.0.0) - cucumber-messages (>= 19.1.4, < 23) - cucumber-html-formatter (21.10.1) + cucumber-gherkin (32.2.0) + cucumber-messages (> 25, < 28) + cucumber-html-formatter (21.14.0) cucumber-messages (> 19, < 28) - cucumber-messages (22.0.0) + cucumber-messages (27.2.0) cucumber-tag-expressions (6.1.2) date (3.4.1) date (3.4.1-java) diff-lcs (1.6.2) drb (2.2.3) - erb (5.0.1) - erb (5.0.1-java) + erb (5.0.2) + erb (5.0.2-java) erubi (1.13.1) - factory_bot (6.5.4) + factory_bot (6.5.5) activesupport (>= 6.1.0) ffi (1.17.2) ffi (1.17.2-java) @@ -112,15 +112,15 @@ GEM activesupport (>= 6.1) i18n (1.14.7) concurrent-ruby (~> 1.0) - io-console (0.8.0) - io-console (0.8.0-java) + io-console (0.8.1) + io-console (0.8.1-java) irb (1.15.2) pp (>= 0.6.0) rdoc (>= 4.0.0) reline (>= 0.4.2) jar-dependencies (0.5.5) - json (2.12.2) - json (2.12.2-java) + json (2.13.2) + json (2.13.2-java) language_server-protocol (3.17.0.5) lint_roller (1.1.0) logger (1.7.0) @@ -128,18 +128,19 @@ GEM crass (~> 1.0.2) nokogiri (>= 1.12.0) marcel (1.0.4) + memoist3 (1.0.0) mini_mime (1.1.5) mini_portile2 (2.8.9) minitest (5.25.5) multi_test (1.1.0) mutex_m (0.3.0) - nokogiri (1.18.8) + nokogiri (1.18.9) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.18.8-java) + nokogiri (1.18.9-java) racc (~> 1.4) parallel (1.27.0) - parser (3.3.8.0) + parser (3.3.9.0) ast (~> 2.4.1) racc pp (0.6.2) @@ -154,7 +155,7 @@ GEM jar-dependencies (>= 0.1.7) racc (1.8.1) racc (1.8.1-java) - rack (3.1.16) + rack (3.2.1) rack-session (2.1.1) base64 (>= 0.1.0) rack (>= 3.0.0) @@ -169,9 +170,9 @@ GEM rails-html-sanitizer (1.6.2) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) - railties (8.0.2) - actionpack (= 8.0.2) - activesupport (= 8.0.2) + railties (8.0.2.1) + actionpack (= 8.0.2.1) + activesupport (= 8.0.2.1) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) @@ -179,13 +180,13 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.3.0) - rdoc (6.14.0) + rdoc (6.14.2) erb psych (>= 4.0.0) - regexp_parser (2.10.0) - reline (0.6.1) + regexp_parser (2.11.2) + reline (0.6.2) io-console (~> 0.5) - rspec-core (3.13.4) + rspec-core (3.13.5) rspec-support (~> 3.13.0) rspec-expectations (3.13.5) diff-lcs (>= 1.2.0, < 2.0) @@ -193,7 +194,7 @@ GEM rspec-mocks (3.13.5) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-rails (8.0.0) + rspec-rails (8.0.2) actionpack (>= 7.2) activesupport (>= 7.2) railties (>= 7.2) @@ -201,7 +202,7 @@ GEM rspec-expectations (~> 3.13) rspec-mocks (~> 3.13) rspec-support (~> 3.13) - rspec-support (3.13.4) + rspec-support (3.13.5) rubocop (1.75.8) json (~> 2.3) language_server-protocol (~> 3.17.0.2) @@ -213,7 +214,7 @@ GEM rubocop-ast (>= 1.44.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.45.1) + rubocop-ast (1.46.0) parser (>= 3.3.7.2) prism (~> 1.4) rubocop-performance (1.25.0) @@ -222,7 +223,7 @@ GEM rubocop-ast (>= 1.38.0, < 2.0) ruby-progressbar (1.13.0) securerandom (0.4.1) - sqlite3 (2.7.0) + sqlite3 (2.7.3) mini_portile2 (~> 2.8.0) standard (1.50.0) language_server-protocol (~> 3.17.0.2) @@ -237,13 +238,14 @@ GEM lint_roller (~> 1.1) rubocop-performance (~> 1.25.0) stringio (3.1.7) - sys-uname (1.3.1) + sys-uname (1.4.1) ffi (~> 1.1) - thor (1.3.2) + memoist3 (~> 1.0.0) + thor (1.4.0) timeout (0.4.3) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (3.1.4) + unicode-display_width (3.1.5) unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uri (1.0.3) diff --git a/features/generators.feature b/features/generators.feature index d0e22c91..ecf9c47c 100644 --- a/features/generators.feature +++ b/features/generators.feature @@ -90,3 +90,21 @@ 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" + + + @rails_8 + Scenario: The factory_bot_rails authentication generator, coupled with rspec-rails, creates a user factory file + When I add "rspec-rails" 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 "spec/factories/users.rb" + And the file "spec/factories/users.rb" should contain exactly: + """ + FactoryBot.define do + factory :user do + email_address { "user@example.com" } + password { "password" } + end + end + """ diff --git a/features/support/env.rb b/features/support/env.rb index 02249f92..6c1d7cfb 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -11,6 +11,17 @@ setup_aruba end +Before("@rails_8") do + rails_version = Gem::Version.new( + Bundler.load.specs.find { |spec| spec.name == "rails" }&.version.to_s + ) + required_version = Gem::Version.new("8.0.0") + + if rails_version < required_version + skip_this_scenario("Requires Rails 8.0 or higher (current: #{rails_version})") + end +end + if RUBY_PLATFORM == "java" Aruba.configure do |config| config.before_cmd do diff --git a/gemfiles/rails8.0.gemfile b/gemfiles/rails8.0.gemfile index c09e83ec..c00ba4d2 100644 --- a/gemfiles/rails8.0.gemfile +++ b/gemfiles/rails8.0.gemfile @@ -4,6 +4,7 @@ source "https://rubygems.org" gem "appraisal" gem "aruba" +gem "bcrypt", "~> 3.1.7" gem "brakeman" gem "byebug" gem "cucumber" diff --git a/lib/generators/factory_bot/authentication/authentication_generator.rb b/lib/generators/factory_bot/authentication/authentication_generator.rb new file mode 100644 index 00000000..f6b6de7b --- /dev/null +++ b/lib/generators/factory_bot/authentication/authentication_generator.rb @@ -0,0 +1,22 @@ +require "generators/factory_bot" +require "generators/factory_bot/model/model_generator" +require "factory_bot_rails" + +module FactoryBot + module Generators + FixedAttribute = Struct.new(:name, :default) + + class AuthenticationGenerator < ModelGenerator + source_paths << File.join(File.dirname(__FILE__), "../model/templates") + + private + + def attributes + [ + FixedAttribute.new(:email_address, "user@example.com"), + FixedAttribute.new(:password, "password") + ] + end + end + end +end diff --git a/lib/generators/factory_bot/authentication/templates/users.rb b/lib/generators/factory_bot/authentication/templates/users.rb new file mode 100644 index 00000000..ab38e1b1 --- /dev/null +++ b/lib/generators/factory_bot/authentication/templates/users.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :user do + password { "password123" } + password_confirmation { "password123" } + email_address { "user#{SecureRandom.hex(3)}@example.com" } + end +end