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

Drop trailing slash of prefix in #get_local_files #425

Merged
merged 2 commits into from
Aug 29, 2024
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
2 changes: 1 addition & 1 deletion lib/asset_sync/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_local_files

log "Using: Directory Search of #{path}/#{self.config.assets_prefix}"
Dir.chdir(path) do
to_load = self.config.assets_prefix.present? ? "#{self.config.assets_prefix}/**/**" : '**/**'
to_load = self.config.assets_prefix.present? ? File.join(self.config.assets_prefix, '/**/**') : '**/**'
Dir[to_load]
end
end
Expand Down
49 changes: 49 additions & 0 deletions spec/unit/storage_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'fileutils'

describe AssetSync::Storage do
include_context "mock Rails without_yml"
Expand Down Expand Up @@ -450,4 +451,52 @@ def check_file(file)
end
end
end

describe '#get_local_files' do
around(:each) do |example|
Dir.mktmpdir do |public_path|
@public_path = public_path
example.call
end
end

before(:each) do
@config = AssetSync::Config.new
@config.public_path = @public_path
@config.prefix = 'assets'
@storage = AssetSync::Storage.new(@config)

Dir.mkdir("#{@public_path}/assets")
end

context 'with empty directory' do
it 'has no files' do
expect(@storage.get_local_files).to eq([])
end
end

context 'with non-empty directory' do
before(:each) do
FileUtils.touch("#{@public_path}/assets/application.js")
end

it 'lists available files' do
expect(@storage.get_local_files).to eq([
'assets/application.js'
])
end

context 'with trailing slash on asset prefix' do
before(:each) do
@config.prefix = 'assets/'
end

it 'lists available files with single slashes' do
expect(@storage.get_local_files).to eq([
'assets/application.js'
])
end
end
end
end
end
Loading