diff --git a/application.rb b/application.rb index ec26041..11df8a7 100644 --- a/application.rb +++ b/application.rb @@ -25,6 +25,9 @@ # Redirect all urls on production (http://github.com/cwninja/rack-force_domain) use Rack::ForceDomain, ENV["DOMAIN"] if settings.environment != "test" + # Gzips pages + use Rack::Deflater + Compass.configuration do |config| config.project_path = File.dirname(__FILE__) config.sass_dir = 'views/stylesheets' diff --git a/spec/lib/rack_deflater_spec.rb b/spec/lib/rack_deflater_spec.rb new file mode 100644 index 0000000..2ae29a0 --- /dev/null +++ b/spec/lib/rack_deflater_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +# For gzipping pages +describe Rack::Deflater do + before do + @path = paths[:homepage] + get @path + @page_headers = last_response.headers.clone + + get @path, {}, { "HTTP_ACCEPT_ENCODING" => "gzip" } + @gzipped_page_headers = last_response.headers.clone + end + + describe "Content-Encoding" do + it "is nil for page" do + @page_headers["Content-Encoding"].should be_nil + end + + it "is 'gzip' for gzipped page" do + @gzipped_page_headers["Content-Encoding"].should == "gzip" + end + end + + describe "Content-Length" do + before { @content_length = @page_headers["Content-Length"].to_i } + + it "should be lower for gzipped page" do + expect(@gzipped_page_headers["Content-Length"].to_i).to be < @content_length + end + end + + describe "Etag" do + before { @etag = @page_headers["Etag"] } + + it "is the same for normal and gzipped page" do + @gzipped_page_headers["Etag"].should == @etag + end + end +end \ No newline at end of file