metropolis.git  about / heads / tags
key-value store for Rack
blob 8c89375e5cfaa1aa32e451ade62e7538547ba849 935 bytes (raw)
$ git show HEAD:test/test_hash.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
# -*- encoding: binary -*-
require './test/rack_read_write.rb'
$-w = true
require 'metropolis'

class Test_Hash < Test::Unit::TestCase
  attr_reader :tmp, :o, :uri
  include TestRackReadWrite

  def setup
    @tmp = Tempfile.new('hash')
    File.unlink(@tmp)
    @uri = "hash://#{@tmp.path}"
    @app_opts = { :uri => @uri }
  end

  def teardown
    @tmp.close!
  end

  def test_marshalled
    File.open(@tmp, "wb") { |fp| fp.write(Marshal.dump({"x" => "y"})) }
    app = Metropolis.new(@app_opts.merge(:readonly => true))
    o = { :lint => true, :fatal => true }
    req = Rack::MockRequest.new(app)

    r = req.put("/x", o.merge(:input=>"ASDF"))
    assert_equal 403, r.status

    r = req.get("/x")
    assert_equal 200, r.status
    assert_equal "y", r.body

    r = req.request("HEAD", "/x", {})
    assert_equal 200, r.status
    assert_equal "", r.body

    r = req.delete("/x", {})
    assert_equal 403, r.status
  end
end

git clone https://yhbt.net/metropolis.git