Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Commit

Permalink
[#84] Add Rack::Deflater to gzip site.
Browse files Browse the repository at this point in the history
  • Loading branch information
taktran committed Apr 26, 2013
1 parent b101f06 commit aeac5b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
39 changes: 39 additions & 0 deletions spec/lib/rack_deflater_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit aeac5b2

Please sign in to comment.