summaryrefslogtreecommitdiff
path: root/spec/bundler/commands/init_spec.rb
diff options
context:
space:
mode:
authorVictor Gama <hey@vito.io>2022-09-21 15:09:36 -0300
committergit <svn-admin@ruby-lang.org>2022-10-03 20:41:45 +0900
commitbc6c1e0e25a9dc80382e2ffb8559bbe171e0400e (patch)
treed28b7e58e6b27c460072cdaec827129399a0a080 /spec/bundler/commands/init_spec.rb
parentb7a61cb485a9bfaa52107f57782e53365f4bf59a (diff)
[rubygems/rubygems] Copy template contents instead of file and perms
This allows the file to be created without copying permissions from Bundler's installation source. The previous behaviour was noticed after installing Ruby through brew, and using bundle init, which yielded a read-only Gemfile. https://github.com/rubygems/rubygems/commit/839a06851d
Diffstat (limited to 'spec/bundler/commands/init_spec.rb')
-rw-r--r--spec/bundler/commands/init_spec.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/bundler/commands/init_spec.rb b/spec/bundler/commands/init_spec.rb
index eaf8fa170a..9c499b99a1 100644
--- a/spec/bundler/commands/init_spec.rb
+++ b/spec/bundler/commands/init_spec.rb
@@ -7,6 +7,29 @@ RSpec.describe "bundle init" do
expect(bundled_app_gemfile).to be_file
end
+ context "with a template with permission flags not matching current process umask" do
+ let(:template_file) do
+ gemfile = Bundler.preferred_gemfile_name
+ templates_dir.join(gemfile)
+ end
+
+ let(:target_dir) { bundled_app("init_permissions_test") }
+
+ around do |example|
+ old_chmod = File.stat(template_file).mode
+ FileUtils.chmod(old_chmod | 0o111, template_file) # chmod +x
+ example.run
+ FileUtils.chmod(old_chmod, template_file)
+ end
+
+ it "honours the current process umask when generating from a template" do
+ FileUtils.mkdir(target_dir)
+ bundle :init, :dir => target_dir
+ generated_mode = File.stat(File.join(target_dir, "Gemfile")).mode & 0o111
+ expect(generated_mode).to be_zero
+ end
+ end
+
context "when a Gemfile already exists" do
before do
create_file "Gemfile", <<-G