Skip to content

Commit f9e86f1

Browse files
authored
Improve how the sessions generator adds bcrypt (rails#52346)
* doc: fix CHANGELOG message for sessions generator * fix: Sessions generator adds bcrypt more robustly Use Thor's `uncomment_lines` instead of `gsub_file`. If the Gemfile does not contain bcrypt, either commented or uncommented, then run `bundle add bcrypt`. Make sure all bundler commands run within `Bundler.with_original_env` to avoid bundler resolution problems while trying to resolve bundler dependencies. Typically the failure mode here is seeing: > Could not find bcrypt-3.1.20 in cached gems or installed locally (Bundler::GemNotFound) while bootstrapping the process that will run bundle-install or bundle-add.
1 parent d35f52c commit f9e86f1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

railties/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
# Generate with...
5-
bin/rails sessions
5+
bin/rails generate sessions
66

77
# Generated files
88
app/models/current.rb

railties/lib/rails/generators/rails/sessions/sessions_generator.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ def configure_application
2020
end
2121

2222
def enable_bcrypt
23-
# FIXME: Make more resilient in case the default comment has been removed
24-
gsub_file "Gemfile", /# gem "bcrypt"/, 'gem "bcrypt"'
25-
execute_command :bundle, ""
23+
if File.read("Gemfile").include?('gem "bcrypt"')
24+
uncomment_lines "Gemfile", /gem "bcrypt"/
25+
Bundler.with_original_env { execute_command :bundle, "" }
26+
else
27+
Bundler.with_original_env { execute_command :bundle, "add bcrypt" }
28+
end
2629
end
2730

2831
def add_migrations

0 commit comments

Comments
 (0)