Sha256: 756809b3d0f99c3a7deab92ca72321a836578b07d5c414f85e072d851aa776a7

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

A1 = Satz.define do
  get do
    reply(read)
  end

  post do
    reply(read)
  end

  on "protected" do
    @user = auth do |user, pass|
      user == "foo" && pass == "bar"
    end

    on @user.nil? do
      res.status = 401
      reply(error: "Unauthorized")
    end

    get do
      reply(true)
    end
  end
end

setup do
  Driver.new(A1)
end

test "get" do |app|
  app.get("/")

  assert_equal 200, app.last_response.status
  assert_equal %Q(null), app.last_response.body
end

test "post" do |app|
  data = { "foo" => "bar" }.to_json

  app.post("/", data)

  assert_equal data, app.last_response.body
  assert_equal 200, app.last_response.status
end

test "auth" do |app|
  app.get("/protected")

  assert_equal %Q({"error":"Unauthorized"}), app.last_response.body
  assert_equal 401, app.last_response.status

  app.authorize("foo", "bar")

  app.get("/protected")

  assert_equal %Q(true), app.last_response.body
end

module Reverser
  def self.load(data)
    data
  end

  def self.dump(data)
    data.reverse
  end
end

Satz.serializer = Reverser

A2 = Satz.define do
  get do
    reply("hello")
  end
end

setup do
  Driver.new(A2)
end

test "get" do |app|
  app.get("/")

  assert_equal 200, app.last_response.status
  assert_equal %Q(olleh), app.last_response.body
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
satz-0.0.4 test/all.rb
satz-0.0.3 test/all.rb
satz-0.0.2 test/all.rb