Sha256: 3dad8d1f4108e8bf4ab9750e6c6a70b4b1e676f5ee55c4923feeda7416e711c4

Contents?: true

Size: 1.38 KB

Versions: 31

Compression:

Stored size: 1.38 KB

Contents

require "#{File.dirname(__FILE__)}/spec_setup"
require 'rack/cache/key'

describe 'A Rack::Cache::Key' do
  it "sorts params" do
    request = mock_request('/test?z=last&a=first')
    new_key(request).should.include('a=first&z=last')
  end

  it "includes the scheme" do
    request = mock_request(
      '/test',
      'rack.url_scheme' => 'https',
      'HTTP_HOST' => 'www2.example.org'
    )
    new_key(request).should.include('https://')
  end

  it "includes host" do
    request = mock_request('/test', "HTTP_HOST" => 'www2.example.org')
    new_key(request).should.include('www2.example.org')
  end

  it "includes path" do
    request = mock_request('/test')
    new_key(request).should.include('/test')
  end

  it "sorts the query string by key/value after decoding" do
    request = mock_request('/test?x=q&a=b&%78=c')
    new_key(request).should.match(/\?a=b&x=c&x=q$/)
  end

  it "is in order of scheme, host, path, params" do
    request = mock_request('/test?x=y', "HTTP_HOST" => 'www2.example.org')
    new_key(request).should.equal "http://www2.example.org/test?x=y"
  end

  # Helper Methods =============================================================

  define_method :mock_request do |*args|
    uri, opts = args
    env = Rack::MockRequest.env_for(uri, opts || {})
    Rack::Cache::Request.new(env)
  end

  define_method :new_key do |request|
    Rack::Cache::Key.call(request)
  end
end

Version data entries

31 entries across 31 versions & 6 rubygems

Version Path
josh-rack-cache-0.5.1 test/key_test.rb
rtomayko-rack-cache-0.3.9 test/key_test.rb
rtomayko-rack-cache-0.4 test/key_test.rb
rtomayko-rack-cache-0.5.1 test/key_test.rb
rtomayko-rack-cache-0.5 test/key_test.rb
radiant-1.0.0.rc2 vendor/rack-cache/test/key_test.rb
radiant-1.0.0.rc1 vendor/rack-cache/test/key_test.rb
rack-cache-1.0 test/key_test.rb
radiantcms-couchrest_model-0.2.4 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.2.2 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.2.1 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.2 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.1.9 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.1.8 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.1.7 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.1.6 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.1.5 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.1.3 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.1.2 vendor/rack-cache/test/key_test.rb
radiantcms-couchrest_model-0.1.1 vendor/rack-cache/test/key_test.rb