Skip to content

Commit

Permalink
CacheBustingFilter: better handling of dots in file names
Browse files Browse the repository at this point in the history
  • Loading branch information
James A. Rosen committed Mar 27, 2012
1 parent fd11d96 commit ba0b8a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rake-pipeline-web-filters/cache_buster_filter.rb
Expand Up @@ -25,7 +25,8 @@ def initialize(&key_generator)
key_generator ||= DEFAULT_KEY_GENERATOR key_generator ||= DEFAULT_KEY_GENERATOR
output_name_generator = proc { |path, file| output_name_generator = proc { |path, file|
parts = path.split('.') parts = path.split('.')
parts[0] << "-#{key_generator.call(file)}" index_to_modify = parts.length > 1 ? -2 : -1
parts[index_to_modify] << "-#{key_generator.call(file)}"
parts.join('.') parts.join('.')
} }
super(&output_name_generator) super(&output_name_generator)
Expand Down
33 changes: 33 additions & 0 deletions spec/cache_buster_filter_spec.rb
Expand Up @@ -69,4 +69,37 @@ def setup_filter(filter)
end end


end end

describe 'for an input file with multiple dots' do
let(:input_file) {
MemoryFileWrapper.new '/path/to/input', 'my.text.file.txt', 'UTF-8', content
}

let(:output_file) {
MemoryFileWrapper.new output_root, "my.text.file-foo.txt", 'UTF-8'
}

subject { setup_filter(CacheBusterFilter.new() { 'foo' }) }

it 'appends the busting key to the penultimate part' do
subject.output_files.should == [ output_file ]
end
end

describe 'for an input file with no dots' do
let(:input_file) {
MemoryFileWrapper.new '/path/to/input', 'my_text_file', 'UTF-8', content
}

let(:output_file) {
MemoryFileWrapper.new output_root, "my_text_file-foo", 'UTF-8'
}

subject { setup_filter(CacheBusterFilter.new() { 'foo' }) }

it 'appends the busting key to the end of the filename' do
subject.output_files.should == [ output_file ]
end
end

end end

0 comments on commit ba0b8a0

Please sign in to comment.