fix cache_buster specs
This commit is contained in:
parent
1e62725523
commit
dce4860f91
|
@ -1,6 +1,4 @@
|
|||
class Middleman::Base
|
||||
include Middleman::Sass
|
||||
|
||||
class Middleman::Base
|
||||
after_feature_init do
|
||||
::Compass.configuration do |config|
|
||||
config.asset_cache_buster do |path, real_path|
|
||||
|
@ -31,8 +29,12 @@ class << Middleman::Base
|
|||
rescue
|
||||
end
|
||||
|
||||
real_path = File.join(self.public, prefix, path)
|
||||
http_path << "?" + File.mtime(real_path).strftime("%s") if File.readable?(real_path)
|
||||
real_path_static = File.join(self.public, prefix, path)
|
||||
real_path_dynamic = File.join(self.views, prefix, path)
|
||||
real_path_dynamic << ".sass" if File.extname(real_path_dynamic) == ".css"
|
||||
|
||||
http_path << "?" + File.mtime(real_path_static).strftime("%s") if File.readable?(real_path_static)
|
||||
http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
|
||||
http_path
|
||||
end
|
||||
end
|
||||
|
|
21
spec/cache_buster_off_spec.rb
Executable file
21
spec/cache_buster_off_spec.rb
Executable file
|
@ -0,0 +1,21 @@
|
|||
require File.join(File.dirname(__FILE__), "spec_helper")
|
||||
|
||||
describe "Cache Buster Feature in CSS" do
|
||||
before :each do
|
||||
@base = ::Middleman::Base
|
||||
@base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample")
|
||||
@base.disable :cache_buster
|
||||
end
|
||||
|
||||
it "should not append query string in CSS if off" do
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new))
|
||||
browser.get("/stylesheets/relative_assets.css")
|
||||
browser.last_response.body.should_not include("?")
|
||||
end
|
||||
|
||||
it "should not append query string in HTML if off" do
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new))
|
||||
browser.get("/cache-buster.html")
|
||||
browser.last_response.body.count("?").should == 0
|
||||
end
|
||||
end
|
21
spec/cache_buster_on_spec.rb
Executable file
21
spec/cache_buster_on_spec.rb
Executable file
|
@ -0,0 +1,21 @@
|
|||
require File.join(File.dirname(__FILE__), "spec_helper")
|
||||
|
||||
describe "Cache Buster Feature in CSS" do
|
||||
before :each do
|
||||
@base = ::Middleman::Base
|
||||
@base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample")
|
||||
@base.enable :cache_buster
|
||||
end
|
||||
|
||||
it "should append query string in CSS if on" do
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new))
|
||||
browser.get("/stylesheets/relative_assets.css")
|
||||
browser.last_response.body.should include("?")
|
||||
end
|
||||
|
||||
it "should append query string in HTML if on" do
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(@base.new))
|
||||
browser.get("/cache-buster.html")
|
||||
browser.last_response.body.count("?").should == 2
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
require File.join(File.dirname(__FILE__), "spec_helper")
|
||||
|
||||
base = ::Middleman::Base
|
||||
base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample")
|
||||
|
||||
describe "Cache Buster Feature" do
|
||||
it "should not append query string if off" do
|
||||
base.disable :cache_buster
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
|
||||
browser.get("/stylesheets/relative_assets.css")
|
||||
browser.last_response.body.should_not include("?")
|
||||
end
|
||||
|
||||
it "should append query string if on" do
|
||||
base.enable :cache_buster
|
||||
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
|
||||
browser.get("/stylesheets/relative_assets.css")
|
||||
browser.last_response.body.should include("?")
|
||||
end
|
||||
end
|
2
spec/fixtures/sample/views/cache-buster.html.haml
vendored
Normal file
2
spec/fixtures/sample/views/cache-buster.html.haml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
= stylesheet_link_tag "site.css"
|
||||
= javascript_include_tag "empty-with-include.js"
|
1
spec/fixtures/sample/views/layout.haml
vendored
1
spec/fixtures/sample/views/layout.haml
vendored
|
@ -1,6 +1,5 @@
|
|||
%html
|
||||
%head
|
||||
%link{ :href => "/stylesheets/site.css", :rel => "stylesheet", :type => "text/css" }
|
||||
%title My Sample Site
|
||||
%body
|
||||
= yield
|
Loading…
Reference in a new issue