diff --git a/CHANGELOG.md b/CHANGELOG.md index 22e5f9ebf..cee1a062d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com] - React on Rails server rendering now supports contexts outside of browser rendering, such as ActionMailer templates [#486](https://github.com/shakacode/react_on_rails/pull/486) by [eacaps](https://github.com/eacaps). - React on Rails now correctly parses single-digit version strings from package.json [#491](https://github.com/shakacode/react_on_rails/pull/491) by [samphilipd ](https://github.com/samphilipd ). +- Fixed assets symlinking to correctly use filenames with spaces. Begining in [#510](https://github.com/shakacode/react_on_rails/pull/510), ending in [#513](https://github.com/shakacode/react_on_rails/pull/513) by [dzirtusss](https://github.com/dzirtusss) ## [6.0.5] - 2016-07-11 ##### Added diff --git a/lib/react_on_rails/assets_precompile.rb b/lib/react_on_rails/assets_precompile.rb index 5f772a129..7004ecea5 100644 --- a/lib/react_on_rails/assets_precompile.rb +++ b/lib/react_on_rails/assets_precompile.rb @@ -39,9 +39,11 @@ def symlink_file(target, symlink) # need to cd to directory and then symlink target_sub_path, _divider, target_filename = target.rpartition("/") _symlink_sub_path, _divider, symlink_filename = symlink.rpartition("/") - puts "React On Rails: Symlinking #{target} to #{symlink}" + puts "React On Rails: Symlinking \"#{target}\" to \"#{symlink}\"" dest_path = File.join(@assets_path, target_sub_path) - `cd #{dest_path} && ln -s #{target_filename} #{symlink_filename}` + FileUtils.chdir(dest_path) do + File.symlink(target_filename, symlink_filename) + end end end diff --git a/spec/react_on_rails/assets_precompile_spec.rb b/spec/react_on_rails/assets_precompile_spec.rb index fe8c12685..364c157cc 100644 --- a/spec/react_on_rails/assets_precompile_spec.rb +++ b/spec/react_on_rails/assets_precompile_spec.rb @@ -20,6 +20,28 @@ module ReactOnRails assets_path.join(digest_filename))).to be true end + it "creates a relative symlink" do + filename = File.basename(Tempfile.new("tempfile", assets_path)) + digest_filename = "#{filename}_digest" + AssetsPrecompile.new(assets_path: assets_path) + .symlink_file(filename, digest_filename) + + expect(File.readlink(assets_path.join(digest_filename)).to_s).to eq(filename) + expect(File.readlink(assets_path.join(digest_filename)).to_s) + .not_to eq(File.expand_path(assets_path.join(filename)).to_s) + end + + it "creates a proper symlink with spaces in path" do + filename = File.basename(Tempfile.new("temp file", assets_path)) + digest_filename = "#{filename} digest" + AssetsPrecompile.new(assets_path: assets_path) + .symlink_file(filename, digest_filename) + + expect(assets_path.join(digest_filename).lstat.symlink?).to be true + expect(File.identical?(assets_path.join(filename), + assets_path.join(digest_filename))).to be true + end + it "creates a proper symlink when nested" do Dir.mkdir assets_path.join("images") filename = "images/" + File.basename(Tempfile.new("tempfile", @@ -48,7 +70,7 @@ module ReactOnRails end context "correct nondigest filename" do - it "create valid symlink" do + it "creates valid symlink" do FileUtils.touch assets_path.join(digest_filename) checker.symlink_non_digested_assets @@ -59,7 +81,7 @@ module ReactOnRails end context "zipped nondigest filename" do - it "create valid symlink" do + it "creates valid symlink" do FileUtils.touch assets_path.join("#{digest_filename}.gz") checker.symlink_non_digested_assets