Skip to content

Commit

Permalink
Merge pull request #513 from dzirtusss/fix-spaces
Browse files Browse the repository at this point in the history
Fixed bug to allow filenames with spaces in assets_precompile.rb
  • Loading branch information
justin808 committed Aug 11, 2016
2 parents bf40984 + 035ecb0 commit c49f5d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/react_on_rails/assets_precompile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 24 additions & 2 deletions spec/react_on_rails/assets_precompile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit c49f5d2

Please sign in to comment.