Permalink
Browse files

Also need to make the source object always overwrite the file when ca…

…ching

* don't care if the file already exists or not
* if the request makes it this far then rack-less needs to update the cached file regardless
  • Loading branch information...
1 parent e11f9c4 commit d2a084116202f86b04b694a02783a69b0a118a72 @kellyredding committed Dec 9, 2011
Showing with 13 additions and 5 deletions.
  1. +3 −5 lib/rack/less/source.rb
  2. +10 −0 test/source_test.rb
View
@@ -53,7 +53,7 @@ def compiled
:filename => File.basename(file_path)
}
less = File.send(File.respond_to?(:binread) ? :binread : :read, file_path.to_s)
- Less::Parser.new(opts).parse(less).to_css(:compress => !!@compress)
+ Less::Parser.new(opts).parse(less).to_css(:compress => compress?)
end.join("\n")
compiled_css = case @compress
@@ -69,11 +69,9 @@ def compiled
compiled_css
end
- if cache? && !File.exists?(cf = File.join(@cache, "#{@css_resource}.css"))
+ if cache? && (cf = File.join(@cache, "#{@css_resource}.css"))
FileUtils.mkdir_p(File.dirname(cf))
- File.open(cf, "w") do |file|
- file.write(compiled_css)
- end
+ File.open(cf, "w") { |file| file.write(compiled_css) }
end
compiled_css
View
@@ -138,6 +138,15 @@ class SourceCachingTests < SourceTests
:cache => @cache
}).to_css
@cached_file = File.join(@cache, "normal.css")
+ @cached_file_time = File.mtime(@cached_file)
+ # shall wait some time to get a new mtime - sorry for letting you wait
+ sleep 2
+
+ Rack::Less::Source.new('normal', {
+ :folder => @source_folder,
+ :cache => @cache
+ }).to_css
+ @updated_cached_file_time = File.mtime(@cached_file)
end
teardown do
if File.exists?(File.dirname(@cache))
@@ -149,6 +158,7 @@ class SourceCachingTests < SourceTests
assert File.exists?(@cache), 'the cache folder does not exist'
assert File.exists?(@cached_file), 'the css was not cached to a file'
assert_equal @expected.strip, File.read(@cached_file).strip, "the compiled css is incorrect"
+ assert @cached_file_time < @updated_cached_file_time, 'the cached file was not updated ' + @cached_file_time.to_s + ' >= ' + @updated_cached_file_time.to_s
end
end

0 comments on commit d2a0841

Please sign in to comment.