key_test.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. require "#{File.dirname(__FILE__)}/spec_setup"
  2. require 'rack/cache/key'
  3. describe 'A Rack::Cache::Key' do
  4. # Helper Methods =============================================================
  5. def mock_request(*args)
  6. uri, opts = args
  7. env = Rack::MockRequest.env_for(uri, opts || {})
  8. Rack::Cache::Request.new(env)
  9. end
  10. def new_key(request)
  11. Rack::Cache::Key.call(request)
  12. end
  13. it "sorts params" do
  14. request = mock_request('/test?z=last&a=first')
  15. new_key(request).should.include('a=first&z=last')
  16. end
  17. it "includes the scheme" do
  18. request = mock_request(
  19. '/test',
  20. 'rack.url_scheme' => 'https',
  21. 'HTTP_HOST' => 'www2.example.org'
  22. )
  23. new_key(request).should.include('https://')
  24. end
  25. it "includes host" do
  26. request = mock_request('/test', "HTTP_HOST" => 'www2.example.org')
  27. new_key(request).should.include('www2.example.org')
  28. end
  29. it "includes path" do
  30. request = mock_request('/test')
  31. new_key(request).should.include('/test')
  32. end
  33. it "sorts the query string by key/value after decoding" do
  34. request = mock_request('/test?x=q&a=b&%78=c')
  35. new_key(request).should.match(/\?a=b&x=c&x=q$/)
  36. end
  37. it "is in order of scheme, host, path, params" do
  38. request = mock_request('/test?x=y', "HTTP_HOST" => 'www2.example.org')
  39. new_key(request).should.equal "http://www2.example.org/test?x=y"
  40. end
  41. end