options_test.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. require "#{File.dirname(__FILE__)}/spec_setup"
  2. require 'rack/cache/options'
  3. module Rack::Cache::Options
  4. option_accessor :foo
  5. end
  6. class MockOptions
  7. include Rack::Cache::Options
  8. def initialize
  9. @env = nil
  10. initialize_options
  11. end
  12. end
  13. describe 'Rack::Cache::Options' do
  14. before { @options = MockOptions.new }
  15. describe '#set' do
  16. it 'sets a Symbol option as rack-cache.symbol' do
  17. @options.set :bar, 'baz'
  18. @options.options['rack-cache.bar'].should.equal 'baz'
  19. end
  20. it 'sets a String option as string' do
  21. @options.set 'foo.bar', 'bling'
  22. @options.options['foo.bar'].should.equal 'bling'
  23. end
  24. it 'sets all key/value pairs when given a Hash' do
  25. @options.set :foo => 'bar', :bar => 'baz', 'foo.bar' => 'bling'
  26. @options.foo.should.equal 'bar'
  27. @options.options['rack-cache.bar'].should.equal 'baz'
  28. @options.options['foo.bar'].should.equal 'bling'
  29. end
  30. end
  31. it 'makes options declared with option_accessor available as attributes' do
  32. @options.set :foo, 'bar'
  33. @options.foo.should.equal 'bar'
  34. end
  35. it 'allows setting multiple options via assignment' do
  36. @options.options = { :foo => 'bar', :bar => 'baz', 'foo.bar' => 'bling' }
  37. @options.foo.should.equal 'bar'
  38. @options.options['foo.bar'].should.equal 'bling'
  39. @options.options['rack-cache.bar'].should.equal 'baz'
  40. end
  41. it "allows storing the value as a block" do
  42. block = Proc.new { "bar block" }
  43. @options.set(:foo, &block)
  44. @options.options['rack-cache.foo'].should.equal block
  45. end
  46. it 'allows the cache key generator to be configured' do
  47. @options.should.respond_to :cache_key
  48. @options.should.respond_to :cache_key=
  49. end
  50. it 'allows the meta store to be configured' do
  51. @options.should.respond_to :metastore
  52. @options.should.respond_to :metastore=
  53. @options.metastore.should.not.be.nil
  54. end
  55. it 'allows the entity store to be configured' do
  56. @options.should.respond_to :entitystore
  57. @options.should.respond_to :entitystore=
  58. @options.entitystore.should.not.be.nil
  59. end
  60. it 'allows log verbosity to be configured' do
  61. @options.should.respond_to :verbose
  62. @options.should.respond_to :verbose=
  63. @options.should.respond_to :verbose?
  64. @options.verbose.should.not.be.nil
  65. end
  66. end