Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug to allow filenames with spaces in assets_precompile.rb #513

Merged
merged 1 commit into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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