Sha256: 1130c5664fa012b70c2f4e3b66db0792f8a70d0b5d5ec095cc193465a27337af

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

require File.expand_path("helper", File.dirname(__FILE__))
require "stringio"

prepare do
  Cuba.define do
    on get, "signup", param("email") do |email|
      res.write email
    end

    on get, "login", param("username", "guest") do |username|
      res.write username
    end

    on default do
      res.write "No email"
    end
  end
end

test "yields a param" do
  env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/signup",
          "SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
          "QUERY_STRING" => "email=john@doe.com" }

  _, _, resp = Cuba.call(env)

  assert_response resp, ["john@doe.com"]
end

test "doesn't yield a missing param" do
  env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/signup",
          "SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
          "QUERY_STRING" => "" }

  _, _, resp = Cuba.call(env)

  assert_response resp, ["No email"]
end

test "doesn't yield an empty param" do
  env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/signup",
          "SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
          "QUERY_STRING" => "email=" }

  _, _, resp = Cuba.call(env)

  assert_response resp, ["No email"]
end

test "yields a default param" do
  env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/login",
          "SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
          "QUERY_STRING" => "username=john" }

  _, _, resp = Cuba.call(env)

  assert_response resp, ["john"]

  env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/login",
          "SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
          "QUERY_STRING" => "" }

  _, _, resp = Cuba.call(env)

  assert_response resp, ["guest"]
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cuba-4.0.3 test/param.rb
cuba-4.0.1 test/param.rb
cuba-4.0.0 test/param.rb
cuba-3.9.3 test/param.rb
cuba-3.9.2 test/param.rb
cuba-3.9.1 test/param.rb
cuba-3.9.0 test/param.rb
cuba-3.8.1 test/param.rb
cuba-3.8.0 test/param.rb
cuba-3.7.0 test/param.rb
cuba-3.6.0 test/param.rb
cuba-3.5.0 test/param.rb