test/spec_session_cookie.rb in rack-1.5.1 vs test/spec_session_cookie.rb in rack-1.5.2
- old
+ new
@@ -98,9 +98,28 @@
it 'rescues failures on decode' do
coder = Rack::Session::Cookie::Base64::Marshal.new
coder.decode('lulz').should.equal nil
end
end
+
+ describe 'JSON' do
+ it 'marshals and base64 encodes' do
+ coder = Rack::Session::Cookie::Base64::JSON.new
+ obj = %w[fuuuuu]
+ coder.encode(obj).should.equal [::Rack::Utils::OkJson.encode(obj)].pack('m')
+ end
+
+ it 'marshals and base64 decodes' do
+ coder = Rack::Session::Cookie::Base64::JSON.new
+ str = [::Rack::Utils::OkJson.encode(%w[fuuuuu])].pack('m')
+ coder.decode(str).should.equal ::Rack::Utils::OkJson.decode(str.unpack('m').first)
+ end
+
+ it 'rescues failures on decode' do
+ coder = Rack::Session::Cookie::Base64::JSON.new
+ coder.decode('lulz').should.equal nil
+ end
+ end
end
it "warns if no secret is given" do
cookie = Rack::Session::Cookie.new(incrementor)
@warnings.first.should =~ /no secret/i