diff options
| author | Jeremy Evans <code@jeremyevans.net> | 2020-01-22 15:57:38 -0800 |
|---|---|---|
| committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-01-24 12:29:31 +1300 |
| commit | 8a6cee1ebe500eedf09ebbabd5cd38b18a478c67 (patch) | |
| tree | 75eb04b219ef4d4ccf0865165c781d270e0003b8 | |
| parent | 905a83dc10c40c3fae0199918190d09f1302aba4 (diff) | |
| download | rack-8a6cee1ebe500eedf09ebbabd5cd38b18a478c67.tar.gz | |
Require rack.session entry to respond to to_hash and return Hash instance
This is already required by rack's session support, so it should
be in SPEC/Lint.
Add some more rack.session Lint tests while here.
Fixes #461
| -rw-r--r-- | SPEC | 1 | ||||
| -rw-r--r-- | lib/rack/lint.rb | 5 | ||||
| -rw-r--r-- | test/spec_lint.rb | 25 |
3 files changed, 31 insertions, 0 deletions
@@ -104,6 +104,7 @@ be implemented by the server. fetch(key, default = nil) (aliased as []); delete(key); clear; + to_hash (returning Hash instance); <tt>rack.logger</tt>:: A common object interface for logging messages. The object must implement: info(message, &block) diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb index 0cccaed2..80945c7a 100644 --- a/lib/rack/lint.rb +++ b/lib/rack/lint.rb @@ -209,6 +209,11 @@ module Rack assert("session #{session.inspect} must respond to clear") { session.respond_to?(:clear) } + + ## to_hash (returning Hash instance); + assert("session #{session.inspect} must respond to to_hash and return Hash instance") { + session.respond_to?(:to_hash) && session.to_hash.kind_of?(Hash) + } end ## <tt>rack.logger</tt>:: A common object interface for logging messages. diff --git a/test/spec_lint.rb b/test/spec_lint.rb index 408a32b7..52b329d5 100644 --- a/test/spec_lint.rb +++ b/test/spec_lint.rb @@ -75,6 +75,31 @@ describe Rack::Lint do }.must_raise(Rack::Lint::LintError). message.must_equal "session [] must respond to store and []=" + obj = {} + obj.singleton_class.send(:undef_method, :to_hash) + lambda { + Rack::Lint.new(nil).call(env("rack.session" => obj)) + }.must_raise(Rack::Lint::LintError). + message.must_equal "session {} must respond to to_hash and return Hash instance" + + obj.singleton_class.send(:undef_method, :clear) + lambda { + Rack::Lint.new(nil).call(env("rack.session" => obj)) + }.must_raise(Rack::Lint::LintError). + message.must_equal "session {} must respond to clear" + + obj.singleton_class.send(:undef_method, :delete) + lambda { + Rack::Lint.new(nil).call(env("rack.session" => obj)) + }.must_raise(Rack::Lint::LintError). + message.must_equal "session {} must respond to delete" + + obj.singleton_class.send(:undef_method, :fetch) + lambda { + Rack::Lint.new(nil).call(env("rack.session" => obj)) + }.must_raise(Rack::Lint::LintError). + message.must_equal "session {} must respond to fetch and []" + lambda { Rack::Lint.new(nil).call(env("rack.logger" => [])) }.must_raise(Rack::Lint::LintError). |
