2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to
5 | deal in the Software without restriction, including without limitation the
6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 | sell copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 | THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/KNOWN-ISSUES:
--------------------------------------------------------------------------------
1 | = Known issues with Rack and Web servers
2 |
3 | * Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your
4 | FastCGI app at "/". This can be fixed by using this middleware:
5 |
6 | class LighttpdScriptNameFix
7 | def initialize(app)
8 | @app = app
9 | end
10 |
11 | def call(env)
12 | env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s
13 | env["SCRIPT_NAME"] = ""
14 | @app.call(env)
15 | end
16 | end
17 |
18 | Of course, use this only when your app runs at "/".
19 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/example/lobster.ru:
--------------------------------------------------------------------------------
1 | require 'rack/lobster'
2 |
3 | use Rack::ShowExceptions
4 | run Rack::Lobster.new
5 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/example/protectedlobster.rb:
--------------------------------------------------------------------------------
1 | require 'rack'
2 | require 'rack/lobster'
3 |
4 | lobster = Rack::Lobster.new
5 |
6 | protected_lobster = Rack::Auth::Basic.new(lobster) do |username, password|
7 | 'secret' == password
8 | end
9 |
10 | protected_lobster.realm = 'Lobster 2.0'
11 |
12 | pretty_protected_lobster = Rack::ShowStatus.new(Rack::ShowExceptions.new(protected_lobster))
13 |
14 | Rack::Handler::WEBrick.run pretty_protected_lobster, :Port => 9292
15 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/example/protectedlobster.ru:
--------------------------------------------------------------------------------
1 | require 'rack/lobster'
2 |
3 | use Rack::ShowExceptions
4 | use Rack::Auth::Basic, "Lobster 2.0" do |username, password|
5 | 'secret' == password
6 | end
7 |
8 | run Rack::Lobster.new
9 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/adapter/camping.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | module Adapter
3 | class Camping
4 | def initialize(app)
5 | @app = app
6 | end
7 |
8 | def call(env)
9 | env["PATH_INFO"] ||= ""
10 | env["SCRIPT_NAME"] ||= ""
11 | controller = @app.run(env['rack.input'], env)
12 | h = controller.headers
13 | h.each_pair do |k,v|
14 | if v.kind_of? URI
15 | h[k] = v.to_s
16 | end
17 | end
18 | [controller.status, controller.headers, [controller.body.to_s]]
19 | end
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/auth/abstract/handler.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | module Auth
3 | # Rack::Auth::AbstractHandler implements common authentication functionality.
4 | #
5 | # +realm+ should be set for all handlers.
6 |
7 | class AbstractHandler
8 |
9 | attr_accessor :realm
10 |
11 | def initialize(app, realm=nil, &authenticator)
12 | @app, @realm, @authenticator = app, realm, authenticator
13 | end
14 |
15 |
16 | private
17 |
18 | def unauthorized(www_authenticate = challenge)
19 | return [ 401,
20 | { 'Content-Type' => 'text/plain',
21 | 'Content-Length' => '0',
22 | 'WWW-Authenticate' => www_authenticate.to_s },
23 | []
24 | ]
25 | end
26 |
27 | def bad_request
28 | return [ 400,
29 | { 'Content-Type' => 'text/plain',
30 | 'Content-Length' => '0' },
31 | []
32 | ]
33 | end
34 |
35 | end
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/auth/abstract/request.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | module Auth
3 | class AbstractRequest
4 |
5 | def initialize(env)
6 | @env = env
7 | end
8 |
9 | def provided?
10 | !authorization_key.nil?
11 | end
12 |
13 | def parts
14 | @parts ||= @env[authorization_key].split(' ', 2)
15 | end
16 |
17 | def scheme
18 | @scheme ||= parts.first.downcase.to_sym
19 | end
20 |
21 | def params
22 | @params ||= parts.last
23 | end
24 |
25 |
26 | private
27 |
28 | AUTHORIZATION_KEYS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION']
29 |
30 | def authorization_key
31 | @authorization_key ||= AUTHORIZATION_KEYS.detect { |key| @env.has_key?(key) }
32 | end
33 |
34 | end
35 |
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/auth/basic.rb:
--------------------------------------------------------------------------------
1 | require 'rack/auth/abstract/handler'
2 | require 'rack/auth/abstract/request'
3 |
4 | module Rack
5 | module Auth
6 | # Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617.
7 | #
8 | # Initialize with the Rack application that you want protecting,
9 | # and a block that checks if a username and password pair are valid.
10 | #
11 | # See also: example/protectedlobster.rb
12 |
13 | class Basic < AbstractHandler
14 |
15 | def call(env)
16 | auth = Basic::Request.new(env)
17 |
18 | return unauthorized unless auth.provided?
19 |
20 | return bad_request unless auth.basic?
21 |
22 | if valid?(auth)
23 | env['REMOTE_USER'] = auth.username
24 |
25 | return @app.call(env)
26 | end
27 |
28 | unauthorized
29 | end
30 |
31 |
32 | private
33 |
34 | def challenge
35 | 'Basic realm="%s"' % realm
36 | end
37 |
38 | def valid?(auth)
39 | @authenticator.call(*auth.credentials)
40 | end
41 |
42 | class Request < Auth::AbstractRequest
43 | def basic?
44 | :basic == scheme
45 | end
46 |
47 | def credentials
48 | @credentials ||= params.unpack("m*").first.split(/:/, 2)
49 | end
50 |
51 | def username
52 | credentials.first
53 | end
54 | end
55 |
56 | end
57 | end
58 | end
59 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/auth/digest/nonce.rb:
--------------------------------------------------------------------------------
1 | require 'digest/md5'
2 |
3 | module Rack
4 | module Auth
5 | module Digest
6 | # Rack::Auth::Digest::Nonce is the default nonce generator for the
7 | # Rack::Auth::Digest::MD5 authentication handler.
8 | #
9 | # +private_key+ needs to set to a constant string.
10 | #
11 | # +time_limit+ can be optionally set to an integer (number of seconds),
12 | # to limit the validity of the generated nonces.
13 |
14 | class Nonce
15 |
16 | class << self
17 | attr_accessor :private_key, :time_limit
18 | end
19 |
20 | def self.parse(string)
21 | new(*string.unpack("m*").first.split(' ', 2))
22 | end
23 |
24 | def initialize(timestamp = Time.now, given_digest = nil)
25 | @timestamp, @given_digest = timestamp.to_i, given_digest
26 | end
27 |
28 | def to_s
29 | [([ @timestamp, digest ] * ' ')].pack("m*").strip
30 | end
31 |
32 | def digest
33 | ::Digest::MD5.hexdigest([ @timestamp, self.class.private_key ] * ':')
34 | end
35 |
36 | def valid?
37 | digest == @given_digest
38 | end
39 |
40 | def stale?
41 | !self.class.time_limit.nil? && (@timestamp - Time.now.to_i) < self.class.time_limit
42 | end
43 |
44 | def fresh?
45 | !stale?
46 | end
47 |
48 | end
49 | end
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/auth/digest/params.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | module Auth
3 | module Digest
4 | class Params < Hash
5 |
6 | def self.parse(str)
7 | split_header_value(str).inject(new) do |header, param|
8 | k, v = param.split('=', 2)
9 | header[k] = dequote(v)
10 | header
11 | end
12 | end
13 |
14 | def self.dequote(str) # From WEBrick::HTTPUtils
15 | ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup
16 | ret.gsub!(/\\(.)/, "\\1")
17 | ret
18 | end
19 |
20 | def self.split_header_value(str)
21 | str.scan( /(\w+\=(?:"[^\"]+"|[^,]+))/n ).collect{ |v| v[0] }
22 | end
23 |
24 | def initialize
25 | super
26 |
27 | yield self if block_given?
28 | end
29 |
30 | def [](k)
31 | super k.to_s
32 | end
33 |
34 | def []=(k, v)
35 | super k.to_s, v.to_s
36 | end
37 |
38 | UNQUOTED = ['qop', 'nc', 'stale']
39 |
40 | def to_s
41 | inject([]) do |parts, (k, v)|
42 | parts << "#{k}=" + (UNQUOTED.include?(k) ? v.to_s : quote(v))
43 | parts
44 | end.join(', ')
45 | end
46 |
47 | def quote(str) # From WEBrick::HTTPUtils
48 | '"' << str.gsub(/[\\\"]/o, "\\\1") << '"'
49 | end
50 |
51 | end
52 | end
53 | end
54 | end
55 |
56 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/auth/digest/request.rb:
--------------------------------------------------------------------------------
1 | require 'rack/auth/abstract/request'
2 | require 'rack/auth/digest/params'
3 | require 'rack/auth/digest/nonce'
4 |
5 | module Rack
6 | module Auth
7 | module Digest
8 | class Request < Auth::AbstractRequest
9 |
10 | def method
11 | @env['rack.methodoverride.original_method'] || @env['REQUEST_METHOD']
12 | end
13 |
14 | def digest?
15 | :digest == scheme
16 | end
17 |
18 | def correct_uri?
19 | (@env['SCRIPT_NAME'].to_s + @env['PATH_INFO'].to_s) == uri
20 | end
21 |
22 | def nonce
23 | @nonce ||= Nonce.parse(params['nonce'])
24 | end
25 |
26 | def params
27 | @params ||= Params.parse(parts.last)
28 | end
29 |
30 | def method_missing(sym)
31 | if params.has_key? key = sym.to_s
32 | return params[key]
33 | end
34 | super
35 | end
36 |
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/builder.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | # Rack::Builder implements a small DSL to iteratively construct Rack
3 | # applications.
4 | #
5 | # Example:
6 | #
7 | # app = Rack::Builder.new {
8 | # use Rack::CommonLogger
9 | # use Rack::ShowExceptions
10 | # map "/lobster" do
11 | # use Rack::Lint
12 | # run Rack::Lobster.new
13 | # end
14 | # }
15 | #
16 | # Or
17 | #
18 | # app = Rack::Builder.app do
19 | # use Rack::CommonLogger
20 | # lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'OK'] }
21 | # end
22 | #
23 | # +use+ adds a middleware to the stack, +run+ dispatches to an application.
24 | # You can use +map+ to construct a Rack::URLMap in a convenient way.
25 |
26 | class Builder
27 | def initialize(&block)
28 | @ins = []
29 | instance_eval(&block) if block_given?
30 | end
31 |
32 | def self.app(&block)
33 | self.new(&block).to_app
34 | end
35 |
36 | def use(middleware, *args, &block)
37 | @ins << lambda { |app| middleware.new(app, *args, &block) }
38 | end
39 |
40 | def run(app)
41 | @ins << app #lambda { |nothing| app }
42 | end
43 |
44 | def map(path, &block)
45 | if @ins.last.kind_of? Hash
46 | @ins.last[path] = self.class.new(&block).to_app
47 | else
48 | @ins << {}
49 | map(path, &block)
50 | end
51 | end
52 |
53 | def to_app
54 | @ins[-1] = Rack::URLMap.new(@ins.last) if Hash === @ins.last
55 | inner_app = @ins.last
56 | @ins[0...-1].reverse.inject(inner_app) { |a, e| e.call(a) }
57 | end
58 |
59 | def call(env)
60 | to_app.call(env)
61 | end
62 | end
63 | end
64 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/cascade.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | # Rack::Cascade tries an request on several apps, and returns the
3 | # first response that is not 404 (or in a list of configurable
4 | # status codes).
5 |
6 | class Cascade
7 | attr_reader :apps
8 |
9 | def initialize(apps, catch=404)
10 | @apps = apps
11 | @catch = [*catch]
12 | end
13 |
14 | def call(env)
15 | status = headers = body = nil
16 | raise ArgumentError, "empty cascade" if @apps.empty?
17 | @apps.each { |app|
18 | begin
19 | status, headers, body = app.call(env)
20 | break unless @catch.include?(status.to_i)
21 | end
22 | }
23 | [status, headers, body]
24 | end
25 |
26 | def add app
27 | @apps << app
28 | end
29 |
30 | def include? app
31 | @apps.include? app
32 | end
33 |
34 | alias_method :<<, :add
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/chunked.rb:
--------------------------------------------------------------------------------
1 | require 'rack/utils'
2 |
3 | module Rack
4 |
5 | # Middleware that applies chunked transfer encoding to response bodies
6 | # when the response does not include a Content-Length header.
7 | class Chunked
8 | include Rack::Utils
9 |
10 | def initialize(app)
11 | @app = app
12 | end
13 |
14 | def call(env)
15 | status, headers, body = @app.call(env)
16 | headers = HeaderHash.new(headers)
17 |
18 | if env['HTTP_VERSION'] == 'HTTP/1.0' ||
19 | STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
20 | headers['Content-Length'] ||
21 | headers['Transfer-Encoding']
22 | [status, headers.to_hash, body]
23 | else
24 | dup.chunk(status, headers, body)
25 | end
26 | end
27 |
28 | def chunk(status, headers, body)
29 | @body = body
30 | headers.delete('Content-Length')
31 | headers['Transfer-Encoding'] = 'chunked'
32 | [status, headers.to_hash, self]
33 | end
34 |
35 | def each
36 | term = "\r\n"
37 | @body.each do |chunk|
38 | size = bytesize(chunk)
39 | next if size == 0
40 | yield [size.to_s(16), term, chunk, term].join
41 | end
42 | yield ["0", term, "", term].join
43 | end
44 |
45 | def close
46 | @body.close if @body.respond_to?(:close)
47 | end
48 | end
49 | end
50 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/commonlogger.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | # Rack::CommonLogger forwards every request to an +app+ given, and
3 | # logs a line in the Apache common log format to the +logger+, or
4 | # rack.errors by default.
5 |
6 | class CommonLogger
7 | def initialize(app, logger=nil)
8 | @app = app
9 | @logger = logger
10 | end
11 |
12 | def call(env)
13 | dup._call(env)
14 | end
15 |
16 | def _call(env)
17 | @env = env
18 | @logger ||= self
19 | @time = Time.now
20 | @status, @header, @body = @app.call(env)
21 | [@status, @header, self]
22 | end
23 |
24 | def close
25 | @body.close if @body.respond_to? :close
26 | end
27 |
28 | # By default, log to rack.errors.
29 | def <<(str)
30 | @env["rack.errors"].write(str)
31 | @env["rack.errors"].flush
32 | end
33 |
34 | def each
35 | length = 0
36 | @body.each { |part|
37 | length += part.size
38 | yield part
39 | }
40 |
41 | @now = Time.now
42 |
43 | # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
44 | # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -
45 | # %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
46 | @logger << %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n} %
47 | [
48 | @env['HTTP_X_FORWARDED_FOR'] || @env["REMOTE_ADDR"] || "-",
49 | @env["REMOTE_USER"] || "-",
50 | @now.strftime("%d/%b/%Y %H:%M:%S"),
51 | @env["REQUEST_METHOD"],
52 | @env["PATH_INFO"],
53 | @env["QUERY_STRING"].empty? ? "" : "?"+@env["QUERY_STRING"],
54 | @env["HTTP_VERSION"],
55 | @status.to_s[0..3],
56 | (length.zero? ? "-" : length.to_s),
57 | @now - @time
58 | ]
59 | end
60 | end
61 | end
62 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/conditionalget.rb:
--------------------------------------------------------------------------------
1 | require 'rack/utils'
2 |
3 | module Rack
4 |
5 | # Middleware that enables conditional GET using If-None-Match and
6 | # If-Modified-Since. The application should set either or both of the
7 | # Last-Modified or Etag response headers according to RFC 2616. When
8 | # either of the conditions is met, the response body is set to be zero
9 | # length and the response status is set to 304 Not Modified.
10 | #
11 | # Applications that defer response body generation until the body's each
12 | # message is received will avoid response body generation completely when
13 | # a conditional GET matches.
14 | #
15 | # Adapted from Michael Klishin's Merb implementation:
16 | # http://github.com/wycats/merb-core/tree/master/lib/merb-core/rack/middleware/conditional_get.rb
17 | class ConditionalGet
18 | def initialize(app)
19 | @app = app
20 | end
21 |
22 | def call(env)
23 | return @app.call(env) unless %w[GET HEAD].include?(env['REQUEST_METHOD'])
24 |
25 | status, headers, body = @app.call(env)
26 | headers = Utils::HeaderHash.new(headers)
27 | if etag_matches?(env, headers) || modified_since?(env, headers)
28 | status = 304
29 | headers.delete('Content-Type')
30 | headers.delete('Content-Length')
31 | body = []
32 | end
33 | [status, headers, body]
34 | end
35 |
36 | private
37 | def etag_matches?(env, headers)
38 | etag = headers['Etag'] and etag == env['HTTP_IF_NONE_MATCH']
39 | end
40 |
41 | def modified_since?(env, headers)
42 | last_modified = headers['Last-Modified'] and
43 | last_modified == env['HTTP_IF_MODIFIED_SINCE']
44 | end
45 | end
46 |
47 | end
48 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/content_length.rb:
--------------------------------------------------------------------------------
1 | require 'rack/utils'
2 |
3 | module Rack
4 | # Sets the Content-Length header on responses with fixed-length bodies.
5 | class ContentLength
6 | include Rack::Utils
7 |
8 | def initialize(app)
9 | @app = app
10 | end
11 |
12 | def call(env)
13 | status, headers, body = @app.call(env)
14 | headers = HeaderHash.new(headers)
15 |
16 | if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
17 | !headers['Content-Length'] &&
18 | !headers['Transfer-Encoding'] &&
19 | (body.respond_to?(:to_ary) || body.respond_to?(:to_str))
20 |
21 | body = [body] if body.respond_to?(:to_str) # rack 0.4 compat
22 | length = body.to_ary.inject(0) { |len, part| len + bytesize(part) }
23 | headers['Content-Length'] = length.to_s
24 | end
25 |
26 | [status, headers, body]
27 | end
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/content_type.rb:
--------------------------------------------------------------------------------
1 | require 'rack/utils'
2 |
3 | module Rack
4 |
5 | # Sets the Content-Type header on responses which don't have one.
6 | #
7 | # Builder Usage:
8 | # use Rack::ContentType, "text/plain"
9 | #
10 | # When no content type argument is provided, "text/html" is assumed.
11 | class ContentType
12 | def initialize(app, content_type = "text/html")
13 | @app, @content_type = app, content_type
14 | end
15 |
16 | def call(env)
17 | status, headers, body = @app.call(env)
18 | headers = Utils::HeaderHash.new(headers)
19 | headers['Content-Type'] ||= @content_type
20 | [status, headers.to_hash, body]
21 | end
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/file.rb:
--------------------------------------------------------------------------------
1 | require 'time'
2 | require 'rack/utils'
3 | require 'rack/mime'
4 |
5 | module Rack
6 | # Rack::File serves files below the +root+ given, according to the
7 | # path info of the Rack request.
8 | #
9 | # Handlers can detect if bodies are a Rack::File, and use mechanisms
10 | # like sendfile on the +path+.
11 |
12 | class File
13 | attr_accessor :root
14 | attr_accessor :path
15 |
16 | alias :to_path :path
17 |
18 | def initialize(root)
19 | @root = root
20 | end
21 |
22 | def call(env)
23 | dup._call(env)
24 | end
25 |
26 | F = ::File
27 |
28 | def _call(env)
29 | @path_info = Utils.unescape(env["PATH_INFO"])
30 | return forbidden if @path_info.include? ".."
31 |
32 | @path = F.join(@root, @path_info)
33 |
34 | begin
35 | if F.file?(@path) && F.readable?(@path)
36 | serving
37 | else
38 | raise Errno::EPERM
39 | end
40 | rescue SystemCallError
41 | not_found
42 | end
43 | end
44 |
45 | def forbidden
46 | body = "Forbidden\n"
47 | [403, {"Content-Type" => "text/plain",
48 | "Content-Length" => body.size.to_s},
49 | [body]]
50 | end
51 |
52 | # NOTE:
53 | # We check via File::size? whether this file provides size info
54 | # via stat (e.g. /proc files often don't), otherwise we have to
55 | # figure it out by reading the whole file into memory. And while
56 | # we're at it we also use this as body then.
57 |
58 | def serving
59 | if size = F.size?(@path)
60 | body = self
61 | else
62 | body = [F.read(@path)]
63 | size = Utils.bytesize(body.first)
64 | end
65 |
66 | [200, {
67 | "Last-Modified" => F.mtime(@path).httpdate,
68 | "Content-Type" => Mime.mime_type(F.extname(@path), 'text/plain'),
69 | "Content-Length" => size.to_s
70 | }, body]
71 | end
72 |
73 | def not_found
74 | body = "File not found: #{@path_info}\n"
75 | [404, {"Content-Type" => "text/plain",
76 | "Content-Length" => body.size.to_s},
77 | [body]]
78 | end
79 |
80 | def each
81 | F.open(@path, "rb") { |file|
82 | while part = file.read(8192)
83 | yield part
84 | end
85 | }
86 | end
87 | end
88 | end
89 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/handler/cgi.rb:
--------------------------------------------------------------------------------
1 | require 'rack/content_length'
2 |
3 | module Rack
4 | module Handler
5 | class CGI
6 | def self.run(app, options=nil)
7 | serve app
8 | end
9 |
10 | def self.serve(app)
11 | app = ContentLength.new(app)
12 |
13 | env = ENV.to_hash
14 | env.delete "HTTP_CONTENT_LENGTH"
15 |
16 | env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
17 |
18 | env.update({"rack.version" => [0,1],
19 | "rack.input" => $stdin,
20 | "rack.errors" => $stderr,
21 |
22 | "rack.multithread" => false,
23 | "rack.multiprocess" => true,
24 | "rack.run_once" => true,
25 |
26 | "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
27 | })
28 |
29 | env["QUERY_STRING"] ||= ""
30 | env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
31 | env["REQUEST_PATH"] ||= "/"
32 |
33 | status, headers, body = app.call(env)
34 | begin
35 | send_headers status, headers
36 | send_body body
37 | ensure
38 | body.close if body.respond_to? :close
39 | end
40 | end
41 |
42 | def self.send_headers(status, headers)
43 | STDOUT.print "Status: #{status}\r\n"
44 | headers.each { |k, vs|
45 | vs.split("\n").each { |v|
46 | STDOUT.print "#{k}: #{v}\r\n"
47 | }
48 | }
49 | STDOUT.print "\r\n"
50 | STDOUT.flush
51 | end
52 |
53 | def self.send_body(body)
54 | body.each { |part|
55 | STDOUT.print part
56 | STDOUT.flush
57 | }
58 | end
59 | end
60 | end
61 | end
62 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/handler/evented_mongrel.rb:
--------------------------------------------------------------------------------
1 | require 'swiftcore/evented_mongrel'
2 |
3 | module Rack
4 | module Handler
5 | class EventedMongrel < Handler::Mongrel
6 | end
7 | end
8 | end
9 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/handler/lsws.rb:
--------------------------------------------------------------------------------
1 | require 'lsapi'
2 | require 'rack/content_length'
3 |
4 | module Rack
5 | module Handler
6 | class LSWS
7 | def self.run(app, options=nil)
8 | while LSAPI.accept != nil
9 | serve app
10 | end
11 | end
12 | def self.serve(app)
13 | app = Rack::ContentLength.new(app)
14 |
15 | env = ENV.to_hash
16 | env.delete "HTTP_CONTENT_LENGTH"
17 | env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
18 | env.update({"rack.version" => [0,1],
19 | "rack.input" => StringIO.new($stdin.read.to_s),
20 | "rack.errors" => $stderr,
21 | "rack.multithread" => false,
22 | "rack.multiprocess" => true,
23 | "rack.run_once" => false,
24 | "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
25 | })
26 | env["QUERY_STRING"] ||= ""
27 | env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
28 | env["REQUEST_PATH"] ||= "/"
29 | status, headers, body = app.call(env)
30 | begin
31 | send_headers status, headers
32 | send_body body
33 | ensure
34 | body.close if body.respond_to? :close
35 | end
36 | end
37 | def self.send_headers(status, headers)
38 | print "Status: #{status}\r\n"
39 | headers.each { |k, vs|
40 | vs.split("\n").each { |v|
41 | print "#{k}: #{v}\r\n"
42 | }
43 | }
44 | print "\r\n"
45 | STDOUT.flush
46 | end
47 | def self.send_body(body)
48 | body.each { |part|
49 | print part
50 | STDOUT.flush
51 | }
52 | end
53 | end
54 | end
55 | end
56 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/handler/scgi.rb:
--------------------------------------------------------------------------------
1 | require 'scgi'
2 | require 'stringio'
3 | require 'rack/content_length'
4 | require 'rack/chunked'
5 |
6 | module Rack
7 | module Handler
8 | class SCGI < ::SCGI::Processor
9 | attr_accessor :app
10 |
11 | def self.run(app, options=nil)
12 | new(options.merge(:app=>app,
13 | :host=>options[:Host],
14 | :port=>options[:Port],
15 | :socket=>options[:Socket])).listen
16 | end
17 |
18 | def initialize(settings = {})
19 | @app = Rack::Chunked.new(Rack::ContentLength.new(settings[:app]))
20 | @log = Object.new
21 | def @log.info(*args); end
22 | def @log.error(*args); end
23 | super(settings)
24 | end
25 |
26 | def process_request(request, input_body, socket)
27 | env = {}.replace(request)
28 | env.delete "HTTP_CONTENT_TYPE"
29 | env.delete "HTTP_CONTENT_LENGTH"
30 | env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2)
31 | env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
32 | env["PATH_INFO"] = env["REQUEST_PATH"]
33 | env["QUERY_STRING"] ||= ""
34 | env["SCRIPT_NAME"] = ""
35 | env.update({"rack.version" => [0,1],
36 | "rack.input" => StringIO.new(input_body),
37 | "rack.errors" => $stderr,
38 |
39 | "rack.multithread" => true,
40 | "rack.multiprocess" => true,
41 | "rack.run_once" => false,
42 |
43 | "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
44 | })
45 | status, headers, body = app.call(env)
46 | begin
47 | socket.write("Status: #{status}\r\n")
48 | headers.each do |k, vs|
49 | vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")}
50 | end
51 | socket.write("\r\n")
52 | body.each {|s| socket.write(s)}
53 | ensure
54 | body.close if body.respond_to? :close
55 | end
56 | end
57 | end
58 | end
59 | end
60 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/handler/swiftiplied_mongrel.rb:
--------------------------------------------------------------------------------
1 | require 'swiftcore/swiftiplied_mongrel'
2 |
3 | module Rack
4 | module Handler
5 | class SwiftipliedMongrel < Handler::Mongrel
6 | end
7 | end
8 | end
9 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/handler/thin.rb:
--------------------------------------------------------------------------------
1 | require "thin"
2 | require "rack/content_length"
3 | require "rack/chunked"
4 |
5 | module Rack
6 | module Handler
7 | class Thin
8 | def self.run(app, options={})
9 | app = Rack::Chunked.new(Rack::ContentLength.new(app))
10 | server = ::Thin::Server.new(options[:Host] || '0.0.0.0',
11 | options[:Port] || 8080,
12 | app)
13 | yield server if block_given?
14 | server.start
15 | end
16 | end
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/handler/webrick.rb:
--------------------------------------------------------------------------------
1 | require 'webrick'
2 | require 'stringio'
3 | require 'rack/content_length'
4 |
5 | module Rack
6 | module Handler
7 | class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet
8 | def self.run(app, options={})
9 | server = ::WEBrick::HTTPServer.new(options)
10 | server.mount "/", Rack::Handler::WEBrick, app
11 | trap(:INT) { server.shutdown }
12 | yield server if block_given?
13 | server.start
14 | end
15 |
16 | def initialize(server, app)
17 | super server
18 | @app = Rack::ContentLength.new(app)
19 | end
20 |
21 | def service(req, res)
22 | env = req.meta_vars
23 | env.delete_if { |k, v| v.nil? }
24 |
25 | env.update({"rack.version" => [0,1],
26 | "rack.input" => StringIO.new(req.body.to_s),
27 | "rack.errors" => $stderr,
28 |
29 | "rack.multithread" => true,
30 | "rack.multiprocess" => false,
31 | "rack.run_once" => false,
32 |
33 | "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
34 | })
35 |
36 | env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
37 | env["QUERY_STRING"] ||= ""
38 | env["REQUEST_PATH"] ||= "/"
39 | if env["PATH_INFO"] == ""
40 | env.delete "PATH_INFO"
41 | else
42 | path, n = req.request_uri.path, env["SCRIPT_NAME"].length
43 | env["PATH_INFO"] = path[n, path.length-n]
44 | end
45 |
46 | status, headers, body = @app.call(env)
47 | begin
48 | res.status = status.to_i
49 | headers.each { |k, vs|
50 | if k.downcase == "set-cookie"
51 | res.cookies.concat vs.split("\n")
52 | else
53 | vs.split("\n").each { |v|
54 | res[k] = v
55 | }
56 | end
57 | }
58 | body.each { |part|
59 | res.body << part
60 | }
61 | ensure
62 | body.close if body.respond_to? :close
63 | end
64 | end
65 | end
66 | end
67 | end
68 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/head.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 |
3 | class Head
4 | def initialize(app)
5 | @app = app
6 | end
7 |
8 | def call(env)
9 | status, headers, body = @app.call(env)
10 |
11 | if env["REQUEST_METHOD"] == "HEAD"
12 | [status, headers, []]
13 | else
14 | [status, headers, body]
15 | end
16 | end
17 | end
18 |
19 | end
20 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/lobster.rb:
--------------------------------------------------------------------------------
1 | require 'zlib'
2 |
3 | require 'rack/request'
4 | require 'rack/response'
5 |
6 | module Rack
7 | # Paste has a Pony, Rack has a Lobster!
8 | class Lobster
9 | LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2
10 | P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0
11 | t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ
12 | I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])
13 |
14 | LambdaLobster = lambda { |env|
15 | if env["QUERY_STRING"].include?("flip")
16 | lobster = LobsterString.split("\n").
17 | map { |line| line.ljust(42).reverse }.
18 | join("\n")
19 | href = "?"
20 | else
21 | lobster = LobsterString
22 | href = "?flip"
23 | end
24 |
25 | content = ["Lobstericious!",
26 | "", lobster, "
",
27 | "flip!"]
28 | length = content.inject(0) { |a,e| a+e.size }.to_s
29 | [200, {"Content-Type" => "text/html", "Content-Length" => length}, content]
30 | }
31 |
32 | def call(env)
33 | req = Request.new(env)
34 | if req.GET["flip"] == "left"
35 | lobster = LobsterString.split("\n").
36 | map { |line| line.ljust(42).reverse }.
37 | join("\n")
38 | href = "?flip=right"
39 | elsif req.GET["flip"] == "crash"
40 | raise "Lobster crashed"
41 | else
42 | lobster = LobsterString
43 | href = "?flip=left"
44 | end
45 |
46 | res = Response.new
47 | res.write "Lobstericious!"
48 | res.write ""
49 | res.write lobster
50 | res.write "
"
51 | res.write "flip!
"
52 | res.write "crash!
"
53 | res.finish
54 | end
55 |
56 | end
57 | end
58 |
59 | if $0 == __FILE__
60 | require 'rack'
61 | require 'rack/showexceptions'
62 | Rack::Handler::WEBrick.run \
63 | Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)),
64 | :Port => 9292
65 | end
66 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/lock.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | class Lock
3 | FLAG = 'rack.multithread'.freeze
4 |
5 | def initialize(app, lock = Mutex.new)
6 | @app, @lock = app, lock
7 | end
8 |
9 | def call(env)
10 | old, env[FLAG] = env[FLAG], false
11 | @lock.synchronize { @app.call(env) }
12 | ensure
13 | env[FLAG] = old
14 | end
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/methodoverride.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | class MethodOverride
3 | HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
4 |
5 | METHOD_OVERRIDE_PARAM_KEY = "_method".freeze
6 | HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze
7 |
8 | def initialize(app)
9 | @app = app
10 | end
11 |
12 | def call(env)
13 | if env["REQUEST_METHOD"] == "POST"
14 | req = Request.new(env)
15 | method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
16 | env[HTTP_METHOD_OVERRIDE_HEADER]
17 | method = method.to_s.upcase
18 | if HTTP_METHODS.include?(method)
19 | env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
20 | env["REQUEST_METHOD"] = method
21 | end
22 | end
23 |
24 | @app.call(env)
25 | end
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/recursive.rb:
--------------------------------------------------------------------------------
1 | require 'uri'
2 |
3 | module Rack
4 | # Rack::ForwardRequest gets caught by Rack::Recursive and redirects
5 | # the current request to the app at +url+.
6 | #
7 | # raise ForwardRequest.new("/not-found")
8 | #
9 |
10 | class ForwardRequest < Exception
11 | attr_reader :url, :env
12 |
13 | def initialize(url, env={})
14 | @url = URI(url)
15 | @env = env
16 |
17 | @env["PATH_INFO"] = @url.path
18 | @env["QUERY_STRING"] = @url.query if @url.query
19 | @env["HTTP_HOST"] = @url.host if @url.host
20 | @env["HTTP_PORT"] = @url.port if @url.port
21 | @env["rack.url_scheme"] = @url.scheme if @url.scheme
22 |
23 | super "forwarding to #{url}"
24 | end
25 | end
26 |
27 | # Rack::Recursive allows applications called down the chain to
28 | # include data from other applications (by using
29 | # rack['rack.recursive.include'][...] or raise a
30 | # ForwardRequest to redirect internally.
31 |
32 | class Recursive
33 | def initialize(app)
34 | @app = app
35 | end
36 |
37 | def call(env)
38 | @script_name = env["SCRIPT_NAME"]
39 | @app.call(env.merge('rack.recursive.include' => method(:include)))
40 | rescue ForwardRequest => req
41 | call(env.merge(req.env))
42 | end
43 |
44 | def include(env, path)
45 | unless path.index(@script_name) == 0 && (path[@script_name.size] == ?/ ||
46 | path[@script_name.size].nil?)
47 | raise ArgumentError, "can only include below #{@script_name}, not #{path}"
48 | end
49 |
50 | env = env.merge("PATH_INFO" => path, "SCRIPT_NAME" => @script_name,
51 | "REQUEST_METHOD" => "GET",
52 | "CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "",
53 | "rack.input" => StringIO.new(""))
54 | @app.call(env)
55 | end
56 | end
57 | end
58 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/static.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 |
3 | # The Rack::Static middleware intercepts requests for static files
4 | # (javascript files, images, stylesheets, etc) based on the url prefixes
5 | # passed in the options, and serves them using a Rack::File object. This
6 | # allows a Rack stack to serve both static and dynamic content.
7 | #
8 | # Examples:
9 | # use Rack::Static, :urls => ["/media"]
10 | # will serve all requests beginning with /media from the "media" folder
11 | # located in the current directory (ie media/*).
12 | #
13 | # use Rack::Static, :urls => ["/css", "/images"], :root => "public"
14 | # will serve all requests beginning with /css or /images from the folder
15 | # "public" in the current directory (ie public/css/* and public/images/*)
16 |
17 | class Static
18 |
19 | def initialize(app, options={})
20 | @app = app
21 | @urls = options[:urls] || ["/favicon.ico"]
22 | root = options[:root] || Dir.pwd
23 | @file_server = Rack::File.new(root)
24 | end
25 |
26 | def call(env)
27 | path = env["PATH_INFO"]
28 | can_serve = @urls.any? { |url| path.index(url) == 0 }
29 |
30 | if can_serve
31 | @file_server.call(env)
32 | else
33 | @app.call(env)
34 | end
35 | end
36 |
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/lib/rack/urlmap.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | # Rack::URLMap takes a hash mapping urls or paths to apps, and
3 | # dispatches accordingly. Support for HTTP/1.1 host names exists if
4 | # the URLs start with http:// or https://.
5 | #
6 | # URLMap modifies the SCRIPT_NAME and PATH_INFO such that the part
7 | # relevant for dispatch is in the SCRIPT_NAME, and the rest in the
8 | # PATH_INFO. This should be taken care of when you need to
9 | # reconstruct the URL in order to create links.
10 | #
11 | # URLMap dispatches in such a way that the longest paths are tried
12 | # first, since they are most specific.
13 |
14 | class URLMap
15 | def initialize(map = {})
16 | remap(map)
17 | end
18 |
19 | def remap(map)
20 | @mapping = map.map { |location, app|
21 | if location =~ %r{\Ahttps?://(.*?)(/.*)}
22 | host, location = $1, $2
23 | else
24 | host = nil
25 | end
26 |
27 | unless location[0] == ?/
28 | raise ArgumentError, "paths need to start with /"
29 | end
30 | location = location.chomp('/')
31 |
32 | [host, location, app]
33 | }.sort_by { |(h, l, a)| [h ? -h.size : (-1.0 / 0.0), -l.size] } # Longest path first
34 | end
35 |
36 | def call(env)
37 | path = env["PATH_INFO"].to_s.squeeze("/")
38 | script_name = env['SCRIPT_NAME']
39 | hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT')
40 | @mapping.each { |host, location, app|
41 | next unless (hHost == host || sName == host \
42 | || (host.nil? && (hHost == sName || hHost == sName+':'+sPort)))
43 | next unless location == path[0, location.size]
44 | next unless path[location.size] == nil || path[location.size] == ?/
45 |
46 | return app.call(
47 | env.merge(
48 | 'SCRIPT_NAME' => (script_name + location),
49 | 'PATH_INFO' => path[location.size..-1]))
50 | }
51 | [404, {"Content-Type" => "text/plain"}, ["Not Found: #{path}"]]
52 | end
53 | end
54 | end
55 |
56 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/cgi/lighttpd.conf:
--------------------------------------------------------------------------------
1 | server.modules = ("mod_fastcgi", "mod_cgi")
2 | server.document-root = "."
3 | server.errorlog = "lighttpd.errors"
4 | server.port = 9203
5 |
6 | server.event-handler = "select"
7 |
8 | cgi.assign = ("/test" => "",
9 | # ".ru" => ""
10 | )
11 |
12 | fastcgi.server = ("test.fcgi" => ("localhost" =>
13 | ("min-procs" => 1,
14 | "socket" => "/tmp/rack-test-fcgi",
15 | "bin-path" => "test.fcgi")),
16 | "test.ru" => ("localhost" =>
17 | ("min-procs" => 1,
18 | "socket" => "/tmp/rack-test-ru-fcgi",
19 | "bin-path" => "test.ru")),
20 | )
21 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/cgi/test:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # -*- ruby -*-
3 |
4 | $: << File.join(File.dirname(__FILE__), "..", "..", "lib")
5 |
6 | require 'rack'
7 | require '../testrequest'
8 |
9 | Rack::Handler::CGI.run(Rack::Lint.new(TestRequest.new))
10 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/cgi/test.fcgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # -*- ruby -*-
3 |
4 | $:.unshift '../../lib'
5 | require 'rack'
6 | require '../testrequest'
7 |
8 | Rack::Handler::FastCGI.run(Rack::Lint.new(TestRequest.new))
9 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/cgi/test.ru:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ../../bin/rackup
2 | #\ -E deployment -I ../../lib
3 | # -*- ruby -*-
4 |
5 | require '../testrequest'
6 |
7 | run TestRequest.new
8 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/multipart/binary:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ehsanul/Sinatra-Authlogic-Template/3c43548960d34f39d35d7102ba422f26e282586f/vendor/rack-1.0.0/test/multipart/binary
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/multipart/empty:
--------------------------------------------------------------------------------
1 | --AaB03x
2 | Content-Disposition: form-data; name="submit-name"
3 |
4 | Larry
5 | --AaB03x
6 | Content-Disposition: form-data; name="files"; filename="file1.txt"
7 | Content-Type: text/plain
8 |
9 |
10 | --AaB03x--
11 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/multipart/ie:
--------------------------------------------------------------------------------
1 | --AaB03x
2 | Content-Disposition: form-data; name="files"; filename="C:\Documents and Settings\Administrator\Desktop\file1.txt"
3 | Content-Type: text/plain
4 |
5 | contents
6 | --AaB03x--
7 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/multipart/nested:
--------------------------------------------------------------------------------
1 | --AaB03x
2 | Content-Disposition: form-data; name="foo[submit-name]"
3 |
4 | Larry
5 | --AaB03x
6 | Content-Disposition: form-data; name="foo[files]"; filename="file1.txt"
7 | Content-Type: text/plain
8 |
9 | contents
10 | --AaB03x--
11 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/multipart/none:
--------------------------------------------------------------------------------
1 | --AaB03x
2 | Content-Disposition: form-data; name="submit-name"
3 |
4 | Larry
5 | --AaB03x
6 | Content-Disposition: form-data; name="files"; filename=""
7 |
8 |
9 | --AaB03x--
10 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/multipart/text:
--------------------------------------------------------------------------------
1 | --AaB03x
2 | Content-Disposition: form-data; name="submit-name"
3 |
4 | Larry
5 | --AaB03x
6 | Content-Disposition: form-data; name="files"; filename="file1.txt"
7 | Content-Type: text/plain
8 |
9 | contents
10 | --AaB03x--
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_auth_basic.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/auth/basic'
4 | require 'rack/mock'
5 |
6 | context 'Rack::Auth::Basic' do
7 |
8 | def realm
9 | 'WallysWorld'
10 | end
11 |
12 | def unprotected_app
13 | lambda { |env| [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ] }
14 | end
15 |
16 | def protected_app
17 | app = Rack::Auth::Basic.new(unprotected_app) { |username, password| 'Boss' == username }
18 | app.realm = realm
19 | app
20 | end
21 |
22 | setup do
23 | @request = Rack::MockRequest.new(protected_app)
24 | end
25 |
26 | def request_with_basic_auth(username, password, &block)
27 | request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block
28 | end
29 |
30 | def request(headers = {})
31 | yield @request.get('/', headers)
32 | end
33 |
34 | def assert_basic_auth_challenge(response)
35 | response.should.be.a.client_error
36 | response.status.should.equal 401
37 | response.should.include 'WWW-Authenticate'
38 | response.headers['WWW-Authenticate'].should =~ /Basic realm="#{Regexp.escape(realm)}"/
39 | response.body.should.be.empty
40 | end
41 |
42 | specify 'should challenge correctly when no credentials are specified' do
43 | request do |response|
44 | assert_basic_auth_challenge response
45 | end
46 | end
47 |
48 | specify 'should rechallenge if incorrect credentials are specified' do
49 | request_with_basic_auth 'joe', 'password' do |response|
50 | assert_basic_auth_challenge response
51 | end
52 | end
53 |
54 | specify 'should return application output if correct credentials are specified' do
55 | request_with_basic_auth 'Boss', 'password' do |response|
56 | response.status.should.equal 200
57 | response.body.to_s.should.equal 'Hi Boss'
58 | end
59 | end
60 |
61 | specify 'should return 400 Bad Request if different auth scheme used' do
62 | request 'HTTP_AUTHORIZATION' => 'Digest params' do |response|
63 | response.should.be.a.client_error
64 | response.status.should.equal 400
65 | response.should.not.include 'WWW-Authenticate'
66 | end
67 | end
68 |
69 | specify 'realm as optional constructor arg' do
70 | app = Rack::Auth::Basic.new(unprotected_app, realm) { true }
71 | assert_equal realm, app.realm
72 | end
73 | end
74 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_camping.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 | require 'stringio'
3 | require 'uri'
4 |
5 | begin
6 | require 'rack/mock'
7 |
8 | $-w, w = nil, $-w # yuck
9 | require 'camping'
10 | require 'rack/adapter/camping'
11 |
12 | Camping.goes :CampApp
13 | module CampApp
14 | module Controllers
15 | class HW < R('/')
16 | def get
17 | @headers["X-Served-By"] = URI("http://rack.rubyforge.org")
18 | "Camping works!"
19 | end
20 |
21 | def post
22 | "Data: #{input.foo}"
23 | end
24 | end
25 | end
26 | end
27 | $-w = w
28 |
29 | context "Rack::Adapter::Camping" do
30 | specify "works with GET" do
31 | res = Rack::MockRequest.new(Rack::Adapter::Camping.new(CampApp)).
32 | get("/")
33 |
34 | res.should.be.ok
35 | res["Content-Type"].should.equal "text/html"
36 | res["X-Served-By"].should.equal "http://rack.rubyforge.org"
37 |
38 | res.body.should.equal "Camping works!"
39 | end
40 |
41 | specify "works with POST" do
42 | res = Rack::MockRequest.new(Rack::Adapter::Camping.new(CampApp)).
43 | post("/", :input => "foo=bar")
44 |
45 | res.should.be.ok
46 | res.body.should.equal "Data: bar"
47 | end
48 | end
49 | rescue LoadError
50 | $stderr.puts "Skipping Rack::Adapter::Camping tests (Camping is required). `gem install camping` and try again."
51 | end
52 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_cascade.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/cascade'
4 | require 'rack/mock'
5 |
6 | require 'rack/urlmap'
7 | require 'rack/file'
8 |
9 | context "Rack::Cascade" do
10 | docroot = File.expand_path(File.dirname(__FILE__))
11 | app1 = Rack::File.new(docroot)
12 |
13 | app2 = Rack::URLMap.new("/crash" => lambda { |env| raise "boom" })
14 |
15 | app3 = Rack::URLMap.new("/foo" => lambda { |env|
16 | [200, { "Content-Type" => "text/plain"}, [""]]})
17 |
18 | specify "should dispatch onward on 404 by default" do
19 | cascade = Rack::Cascade.new([app1, app2, app3])
20 | Rack::MockRequest.new(cascade).get("/cgi/test").should.be.ok
21 | Rack::MockRequest.new(cascade).get("/foo").should.be.ok
22 | Rack::MockRequest.new(cascade).get("/toobad").should.be.not_found
23 | Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.forbidden
24 | end
25 |
26 | specify "should dispatch onward on whatever is passed" do
27 | cascade = Rack::Cascade.new([app1, app2, app3], [404, 403])
28 | Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.not_found
29 | end
30 |
31 | specify "should fail if empty" do
32 | lambda { Rack::MockRequest.new(Rack::Cascade.new([])).get("/") }.
33 | should.raise(ArgumentError)
34 | end
35 |
36 | specify "should append new app" do
37 | cascade = Rack::Cascade.new([], [404, 403])
38 | lambda { Rack::MockRequest.new(cascade).get('/cgi/test') }.
39 | should.raise(ArgumentError)
40 | cascade << app2
41 | Rack::MockRequest.new(cascade).get('/cgi/test').should.be.not_found
42 | Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.not_found
43 | cascade << app1
44 | Rack::MockRequest.new(cascade).get('/cgi/test').should.be.ok
45 | Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.forbidden
46 | Rack::MockRequest.new(cascade).get('/foo').should.be.not_found
47 | cascade << app3
48 | Rack::MockRequest.new(cascade).get('/foo').should.be.ok
49 | end
50 | end
51 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_commonlogger.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 | require 'stringio'
3 |
4 | require 'rack/commonlogger'
5 | require 'rack/lobster'
6 | require 'rack/mock'
7 |
8 | context "Rack::CommonLogger" do
9 | app = lambda { |env|
10 | [200,
11 | {"Content-Type" => "text/html"},
12 | ["foo"]]}
13 |
14 | specify "should log to rack.errors by default" do
15 | log = StringIO.new
16 | res = Rack::MockRequest.new(Rack::CommonLogger.new(app)).get("/")
17 |
18 | res.errors.should.not.be.empty
19 | res.errors.should =~ /GET /
20 | res.errors.should =~ / 200 / # status
21 | res.errors.should =~ / 3 / # length
22 | end
23 |
24 | specify "should log to anything with <<" do
25 | log = ""
26 | res = Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/")
27 |
28 | log.should =~ /GET /
29 | log.should =~ / 200 / # status
30 | log.should =~ / 3 / # length
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_conditionalget.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 | require 'time'
3 |
4 | require 'rack/mock'
5 | require 'rack/conditionalget'
6 |
7 | context "Rack::ConditionalGet" do
8 | specify "should set a 304 status and truncate body when If-Modified-Since hits" do
9 | timestamp = Time.now.httpdate
10 | app = Rack::ConditionalGet.new(lambda { |env|
11 | [200, {'Last-Modified'=>timestamp}, ['TEST']] })
12 |
13 | response = Rack::MockRequest.new(app).
14 | get("/", 'HTTP_IF_MODIFIED_SINCE' => timestamp)
15 |
16 | response.status.should.equal 304
17 | response.body.should.be.empty
18 | end
19 |
20 | specify "should set a 304 status and truncate body when If-None-Match hits" do
21 | app = Rack::ConditionalGet.new(lambda { |env|
22 | [200, {'Etag'=>'1234'}, ['TEST']] })
23 |
24 | response = Rack::MockRequest.new(app).
25 | get("/", 'HTTP_IF_NONE_MATCH' => '1234')
26 |
27 | response.status.should.equal 304
28 | response.body.should.be.empty
29 | end
30 |
31 | specify "should not affect non-GET/HEAD requests" do
32 | app = Rack::ConditionalGet.new(lambda { |env|
33 | [200, {'Etag'=>'1234'}, ['TEST']] })
34 |
35 | response = Rack::MockRequest.new(app).
36 | post("/", 'HTTP_IF_NONE_MATCH' => '1234')
37 |
38 | response.status.should.equal 200
39 | response.body.should.equal 'TEST'
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_content_length.rb:
--------------------------------------------------------------------------------
1 | require 'rack/mock'
2 | require 'rack/content_length'
3 |
4 | context "Rack::ContentLength" do
5 | specify "sets Content-Length on String bodies if none is set" do
6 | app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
7 | response = Rack::ContentLength.new(app).call({})
8 | response[1]['Content-Length'].should.equal '13'
9 | end
10 |
11 | specify "sets Content-Length on Array bodies if none is set" do
12 | app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
13 | response = Rack::ContentLength.new(app).call({})
14 | response[1]['Content-Length'].should.equal '13'
15 | end
16 |
17 | specify "does not set Content-Length on variable length bodies" do
18 | body = lambda { "Hello World!" }
19 | def body.each ; yield call ; end
20 |
21 | app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
22 | response = Rack::ContentLength.new(app).call({})
23 | response[1]['Content-Length'].should.be.nil
24 | end
25 |
26 | specify "does not change Content-Length if it is already set" do
27 | app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] }
28 | response = Rack::ContentLength.new(app).call({})
29 | response[1]['Content-Length'].should.equal '1'
30 | end
31 |
32 | specify "does not set Content-Length on 304 responses" do
33 | app = lambda { |env| [304, {'Content-Type' => 'text/plain'}, []] }
34 | response = Rack::ContentLength.new(app).call({})
35 | response[1]['Content-Length'].should.equal nil
36 | end
37 |
38 | specify "does not set Content-Length when Transfer-Encoding is chunked" do
39 | app = lambda { |env| [200, {'Transfer-Encoding' => 'chunked'}, []] }
40 | response = Rack::ContentLength.new(app).call({})
41 | response[1]['Content-Length'].should.equal nil
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_content_type.rb:
--------------------------------------------------------------------------------
1 | require 'rack/mock'
2 | require 'rack/content_type'
3 |
4 | context "Rack::ContentType" do
5 | specify "sets Content-Type to default text/html if none is set" do
6 | app = lambda { |env| [200, {}, "Hello, World!"] }
7 | status, headers, body = Rack::ContentType.new(app).call({})
8 | headers['Content-Type'].should.equal 'text/html'
9 | end
10 |
11 | specify "sets Content-Type to chosen default if none is set" do
12 | app = lambda { |env| [200, {}, "Hello, World!"] }
13 | status, headers, body =
14 | Rack::ContentType.new(app, 'application/octet-stream').call({})
15 | headers['Content-Type'].should.equal 'application/octet-stream'
16 | end
17 |
18 | specify "does not change Content-Type if it is already set" do
19 | app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] }
20 | status, headers, body = Rack::ContentType.new(app).call({})
21 | headers['Content-Type'].should.equal 'foo/bar'
22 | end
23 |
24 | specify "case insensitive detection of Content-Type" do
25 | app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] }
26 | status, headers, body = Rack::ContentType.new(app).call({})
27 | headers.to_a.select { |k,v| k.downcase == "content-type" }.
28 | should.equal [["CONTENT-Type","foo/bar"]]
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_directory.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/directory'
4 | require 'rack/lint'
5 |
6 | require 'rack/mock'
7 |
8 | context "Rack::Directory" do
9 | DOCROOT = File.expand_path(File.dirname(__FILE__))
10 | FILE_CATCH = proc{|env| [200, {'Content-Type'=>'text/plain', "Content-Length" => "7"}, ['passed!']] }
11 | app = Rack::Directory.new DOCROOT, FILE_CATCH
12 |
13 | specify "serves directory indices" do
14 | res = Rack::MockRequest.new(Rack::Lint.new(app)).
15 | get("/cgi/")
16 |
17 | res.should.be.ok
18 | res.should =~ //
19 | end
20 |
21 | specify "passes to app if file found" do
22 | res = Rack::MockRequest.new(Rack::Lint.new(app)).
23 | get("/cgi/test")
24 |
25 | res.should.be.ok
26 | res.should =~ /passed!/
27 | end
28 |
29 | specify "serves uri with URL encoded filenames" do
30 | res = Rack::MockRequest.new(Rack::Lint.new(app)).
31 | get("/%63%67%69/") # "/cgi/test"
32 |
33 | res.should.be.ok
34 | res.should =~ //
35 |
36 | res = Rack::MockRequest.new(Rack::Lint.new(app)).
37 | get("/cgi/%74%65%73%74") # "/cgi/test"
38 |
39 | res.should.be.ok
40 | res.should =~ /passed!/
41 | end
42 |
43 | specify "does not allow directory traversal" do
44 | res = Rack::MockRequest.new(Rack::Lint.new(app)).
45 | get("/cgi/../test")
46 |
47 | res.should.be.forbidden
48 |
49 | res = Rack::MockRequest.new(Rack::Lint.new(app)).
50 | get("/cgi/%2E%2E/test")
51 |
52 | res.should.be.forbidden
53 | end
54 |
55 | specify "404s if it can't find the file" do
56 | res = Rack::MockRequest.new(Rack::Lint.new(app)).
57 | get("/cgi/blubb")
58 |
59 | res.should.be.not_found
60 | end
61 | end
62 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_file.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/file'
4 | require 'rack/lint'
5 |
6 | require 'rack/mock'
7 |
8 | context "Rack::File" do
9 | DOCROOT = File.expand_path(File.dirname(__FILE__))
10 |
11 | specify "serves files" do
12 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
13 | get("/cgi/test")
14 |
15 | res.should.be.ok
16 | res.should =~ /ruby/
17 | end
18 |
19 | specify "sets Last-Modified header" do
20 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
21 | get("/cgi/test")
22 |
23 | path = File.join(DOCROOT, "/cgi/test")
24 |
25 | res.should.be.ok
26 | res["Last-Modified"].should.equal File.mtime(path).httpdate
27 | end
28 |
29 | specify "serves files with URL encoded filenames" do
30 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
31 | get("/cgi/%74%65%73%74") # "/cgi/test"
32 |
33 | res.should.be.ok
34 | res.should =~ /ruby/
35 | end
36 |
37 | specify "does not allow directory traversal" do
38 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
39 | get("/cgi/../test")
40 |
41 | res.should.be.forbidden
42 | end
43 |
44 | specify "does not allow directory traversal with encoded periods" do
45 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
46 | get("/%2E%2E/README")
47 |
48 | res.should.be.forbidden
49 | end
50 |
51 | specify "404s if it can't find the file" do
52 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
53 | get("/cgi/blubb")
54 |
55 | res.should.be.not_found
56 | end
57 |
58 | specify "detects SystemCallErrors" do
59 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))).
60 | get("/cgi")
61 |
62 | res.should.be.not_found
63 | end
64 |
65 | specify "returns bodies that respond to #to_path" do
66 | env = Rack::MockRequest.env_for("/cgi/test")
67 | status, headers, body = Rack::File.new(DOCROOT).call(env)
68 |
69 | path = File.join(DOCROOT, "/cgi/test")
70 |
71 | status.should.equal 200
72 | body.should.respond_to :to_path
73 | body.to_path.should.equal path
74 | end
75 | end
76 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_handler.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/handler'
4 |
5 | class Rack::Handler::Lobster; end
6 | class RockLobster; end
7 |
8 | context "Rack::Handler" do
9 | specify "has registered default handlers" do
10 | Rack::Handler.get('cgi').should.equal Rack::Handler::CGI
11 | Rack::Handler.get('fastcgi').should.equal Rack::Handler::FastCGI
12 | Rack::Handler.get('mongrel').should.equal Rack::Handler::Mongrel
13 | Rack::Handler.get('webrick').should.equal Rack::Handler::WEBrick
14 | end
15 |
16 | specify "handler that doesn't exist should raise a NameError" do
17 | lambda {
18 | Rack::Handler.get('boom')
19 | }.should.raise(NameError)
20 | end
21 |
22 | specify "should get unregistered, but already required, handler by name" do
23 | Rack::Handler.get('Lobster').should.equal Rack::Handler::Lobster
24 | end
25 |
26 | specify "should register custom handler" do
27 | Rack::Handler.register('rock_lobster', 'RockLobster')
28 | Rack::Handler.get('rock_lobster').should.equal RockLobster
29 | end
30 |
31 | specify "should not need registration for properly coded handlers even if not already required" do
32 | begin
33 | $:.push "test/unregistered_handler"
34 | Rack::Handler.get('Unregistered').should.equal Rack::Handler::Unregistered
35 | lambda {
36 | Rack::Handler.get('UnRegistered')
37 | }.should.raise(NameError)
38 | Rack::Handler.get('UnregisteredLongOne').should.equal Rack::Handler::UnregisteredLongOne
39 | ensure
40 | $:.delete "test/unregistered_handler"
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_head.rb:
--------------------------------------------------------------------------------
1 | require 'rack/head'
2 | require 'rack/mock'
3 |
4 | context "Rack::Head" do
5 | def test_response(headers = {})
6 | app = lambda { |env| [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] }
7 | request = Rack::MockRequest.env_for("/", headers)
8 | response = Rack::Head.new(app).call(request)
9 |
10 | return response
11 | end
12 |
13 | specify "passes GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do
14 | %w[GET POST PUT DELETE OPTIONS TRACE].each do |type|
15 | resp = test_response("REQUEST_METHOD" => type)
16 |
17 | resp[0].should.equal(200)
18 | resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
19 | resp[2].should.equal(["foo"])
20 | end
21 | end
22 |
23 | specify "removes body from HEAD requests" do
24 | resp = test_response("REQUEST_METHOD" => "HEAD")
25 |
26 | resp[0].should.equal(200)
27 | resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
28 | resp[2].should.equal([])
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_lobster.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/lobster'
4 | require 'rack/mock'
5 |
6 | context "Rack::Lobster::LambdaLobster" do
7 | specify "should be a single lambda" do
8 | Rack::Lobster::LambdaLobster.should.be.kind_of Proc
9 | end
10 |
11 | specify "should look like a lobster" do
12 | res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/")
13 | res.should.be.ok
14 | res.body.should.include "(,(,,(,,,("
15 | res.body.should.include "?flip"
16 | end
17 |
18 | specify "should be flippable" do
19 | res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/?flip")
20 | res.should.be.ok
21 | res.body.should.include "(,,,(,,(,("
22 | end
23 | end
24 |
25 | context "Rack::Lobster" do
26 | specify "should look like a lobster" do
27 | res = Rack::MockRequest.new(Rack::Lobster.new).get("/")
28 | res.should.be.ok
29 | res.body.should.include "(,(,,(,,,("
30 | res.body.should.include "?flip"
31 | res.body.should.include "crash"
32 | end
33 |
34 | specify "should be flippable" do
35 | res = Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=left")
36 | res.should.be.ok
37 | res.body.should.include "(,,,(,,(,("
38 | end
39 |
40 | specify "should provide crashing for testing purposes" do
41 | lambda {
42 | Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=crash")
43 | }.should.raise
44 | end
45 | end
46 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_lock.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/mock'
4 | require 'rack/lock'
5 |
6 | context "Rack::Lock" do
7 | class Lock
8 | attr_reader :synchronized
9 |
10 | def initialize
11 | @synchronized = false
12 | end
13 |
14 | def synchronize
15 | @synchronized = true
16 | yield
17 | end
18 | end
19 |
20 | specify "should call synchronize on lock" do
21 | lock = Lock.new
22 | env = Rack::MockRequest.env_for("/")
23 | app = Rack::Lock.new(lambda { |env| }, lock)
24 | lock.synchronized.should.equal false
25 | app.call(env)
26 | lock.synchronized.should.equal true
27 | end
28 |
29 | specify "should set multithread flag to false" do
30 | app = Rack::Lock.new(lambda { |env| env['rack.multithread'] })
31 | app.call(Rack::MockRequest.env_for("/")).should.equal false
32 | end
33 |
34 | specify "should reset original multithread flag when exiting lock" do
35 | app = Rack::Lock.new(lambda { |env| env })
36 | app.call(Rack::MockRequest.env_for("/"))['rack.multithread'].should.equal true
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_methodoverride.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/mock'
4 | require 'rack/methodoverride'
5 | require 'stringio'
6 |
7 | context "Rack::MethodOverride" do
8 | specify "should not affect GET requests" do
9 | env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET")
10 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
11 | req = app.call(env)
12 |
13 | req.env["REQUEST_METHOD"].should.equal "GET"
14 | end
15 |
16 | specify "_method parameter should modify REQUEST_METHOD for POST requests" do
17 | env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put")
18 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
19 | req = app.call(env)
20 |
21 | req.env["REQUEST_METHOD"].should.equal "PUT"
22 | end
23 |
24 | specify "X-HTTP-Method-Override header should modify REQUEST_METHOD for POST requests" do
25 | env = Rack::MockRequest.env_for("/",
26 | :method => "POST",
27 | "HTTP_X_HTTP_METHOD_OVERRIDE" => "PUT"
28 | )
29 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
30 | req = app.call(env)
31 |
32 | req.env["REQUEST_METHOD"].should.equal "PUT"
33 | end
34 |
35 | specify "should not modify REQUEST_METHOD if the method is unknown" do
36 | env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo")
37 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
38 | req = app.call(env)
39 |
40 | req.env["REQUEST_METHOD"].should.equal "POST"
41 | end
42 |
43 | specify "should not modify REQUEST_METHOD when _method is nil" do
44 | env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar")
45 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
46 | req = app.call(env)
47 |
48 | req.env["REQUEST_METHOD"].should.equal "POST"
49 | end
50 |
51 | specify "should store the original REQUEST_METHOD prior to overriding" do
52 | env = Rack::MockRequest.env_for("/",
53 | :method => "POST",
54 | :input => "_method=options")
55 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
56 | req = app.call(env)
57 |
58 | req.env["rack.methodoverride.original_method"].should.equal "POST"
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_showexceptions.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/showexceptions'
4 | require 'rack/mock'
5 |
6 | context "Rack::ShowExceptions" do
7 | specify "catches exceptions" do
8 | res = nil
9 | req = Rack::MockRequest.new(Rack::ShowExceptions.new(lambda { |env|
10 | raise RuntimeError
11 | }))
12 | lambda {
13 | res = req.get("/")
14 | }.should.not.raise
15 | res.should.be.a.server_error
16 | res.status.should.equal 500
17 |
18 | res.should =~ /RuntimeError/
19 | res.should =~ /ShowExceptions/
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/spec_rack_static.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 |
3 | require 'rack/static'
4 | require 'rack/mock'
5 |
6 | class DummyApp
7 | def call(env)
8 | [200, {}, ["Hello World"]]
9 | end
10 | end
11 |
12 | context "Rack::Static" do
13 | root = File.expand_path(File.dirname(__FILE__))
14 | OPTIONS = {:urls => ["/cgi"], :root => root}
15 |
16 | setup do
17 | @request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
18 | end
19 |
20 | specify "serves files" do
21 | res = @request.get("/cgi/test")
22 | res.should.be.ok
23 | res.body.should =~ /ruby/
24 | end
25 |
26 | specify "404s if url root is known but it can't find the file" do
27 | res = @request.get("/cgi/foo")
28 | res.should.be.not_found
29 | end
30 |
31 | specify "calls down the chain if url root is not known" do
32 | res = @request.get("/something/else")
33 | res.should.be.ok
34 | res.body.should == "Hello World"
35 | end
36 |
37 | end
38 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/testrequest.rb:
--------------------------------------------------------------------------------
1 | require 'yaml'
2 | require 'net/http'
3 |
4 | class TestRequest
5 | def call(env)
6 | status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200
7 | env["test.postdata"] = env["rack.input"].read
8 | body = env.to_yaml
9 | size = body.respond_to?(:bytesize) ? body.bytesize : body.size
10 | [status, {"Content-Type" => "text/yaml", "Content-Length" => size.to_s}, [body]]
11 | end
12 |
13 | module Helpers
14 | attr_reader :status, :response
15 |
16 | def GET(path, header={})
17 | Net::HTTP.start(@host, @port) { |http|
18 | user = header.delete(:user)
19 | passwd = header.delete(:passwd)
20 |
21 | get = Net::HTTP::Get.new(path, header)
22 | get.basic_auth user, passwd if user && passwd
23 | http.request(get) { |response|
24 | @status = response.code.to_i
25 | @response = YAML.load(response.body)
26 | }
27 | }
28 | end
29 |
30 | def POST(path, formdata={}, header={})
31 | Net::HTTP.start(@host, @port) { |http|
32 | user = header.delete(:user)
33 | passwd = header.delete(:passwd)
34 |
35 | post = Net::HTTP::Post.new(path, header)
36 | post.form_data = formdata
37 | post.basic_auth user, passwd if user && passwd
38 | http.request(post) { |response|
39 | @status = response.code.to_i
40 | @response = YAML.load(response.body)
41 | }
42 | }
43 | end
44 | end
45 | end
46 |
47 | class StreamingRequest
48 | def self.call(env)
49 | [200, {"Content-Type" => "text/plain"}, new]
50 | end
51 |
52 | def each
53 | yield "hello there!\n"
54 | sleep 5
55 | yield "that is all.\n"
56 | end
57 | end
58 |
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/unregistered_handler/rack/handler/unregistered.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | module Handler
3 | # this class doesn't do anything, we're just seeing if we get it.
4 | class Unregistered
5 | end
6 | end
7 | end
--------------------------------------------------------------------------------
/vendor/rack-1.0.0/test/unregistered_handler/rack/handler/unregistered_long_one.rb:
--------------------------------------------------------------------------------
1 | module Rack
2 | module Handler
3 | # this class doesn't do anything, we're just seeing if we get it.
4 | class UnregisteredLongOne
5 | end
6 | end
7 | end
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2007, 2008, 2009 Blake Mizerany
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/compat_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | context "Compat" do
4 | setup do
5 | Sinatra.application = nil
6 | @app = Sinatra.application
7 | end
8 |
9 | specify "makes EventContext available" do
10 | assert_same Sinatra::Default, Sinatra::EventContext
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/custom_error_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | context "Custom Errors" do
4 |
5 | setup do
6 | Sinatra.application = nil
7 | end
8 |
9 | specify "override the default 404" do
10 |
11 | get_it '/'
12 | should.be.not_found
13 | body.should.equal 'Not Found
'
14 |
15 | error Sinatra::NotFound do
16 | 'Custom 404'
17 | end
18 |
19 | get_it '/'
20 | should.be.not_found
21 | body.should.equal 'Custom 404'
22 |
23 | end
24 |
25 | specify "override the default 500" do
26 | Sinatra.application.options.raise_errors = false
27 |
28 | get '/' do
29 | raise 'asdf'
30 | end
31 |
32 | get_it '/'
33 | status.should.equal 500
34 | body.should.equal 'Internal Server Error
'
35 |
36 |
37 | error do
38 | 'Custom 500 for ' + request.env['sinatra.error'].message
39 | end
40 |
41 | get_it '/'
42 |
43 | get_it '/'
44 | status.should.equal 500
45 | body.should.equal 'Custom 500 for asdf'
46 |
47 | Sinatra.application.options.raise_errors = true
48 | end
49 |
50 | class UnmappedError < RuntimeError; end
51 |
52 | specify "should bring unmapped error back to the top" do
53 | get '/' do
54 | raise UnmappedError, 'test'
55 | end
56 |
57 | assert_raises(UnmappedError) do
58 | get_it '/'
59 | end
60 | end
61 |
62 | end
63 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/filter_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | context "before filters" do
4 |
5 | setup do
6 | Sinatra.application = nil
7 | @app = Sinatra.application
8 | end
9 |
10 | specify "should be executed in the order defined" do
11 | invoked = 0x0
12 | @app.before { invoked = 0x01 }
13 | @app.before { invoked |= 0x02 }
14 | @app.get('/') { 'Hello World' }
15 | get_it '/'
16 | should.be.ok
17 | body.should.be == 'Hello World'
18 | invoked.should.be == 0x03
19 | end
20 |
21 | specify "should be capable of modifying the request" do
22 | @app.get('/foo') { 'foo' }
23 | @app.get('/bar') { 'bar' }
24 | @app.before { request.path_info = '/bar' }
25 | get_it '/foo'
26 | should.be.ok
27 | body.should.be == 'bar'
28 | end
29 |
30 | end
31 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/helper.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'mocha'
3 |
4 | # disable warnings in compat specs.
5 | $VERBOSE = nil
6 |
7 | $:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"
8 |
9 | ENV['RACK_ENV'] ||= 'test'
10 |
11 | require 'sinatra'
12 | require 'sinatra/test'
13 | require 'sinatra/test/unit'
14 | require 'sinatra/test/spec'
15 |
16 | module Sinatra::Test
17 | # we need to remove the new test helper methods since they conflict with
18 | # the top-level methods of the same name.
19 | %w(get head post put delete).each do |verb|
20 | remove_method verb
21 | end
22 | include Sinatra::Delegator
23 | end
24 |
25 | class Test::Unit::TestCase
26 | include Sinatra::Test
27 |
28 | PASSTHROUGH_EXCEPTIONS = [] unless const_defined?(:PASSTHROUGH_EXCEPTIONS)
29 |
30 | def setup
31 | @app = lambda { |env| Sinatra::Application.call(env) }
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/mapped_error_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | class FooError < RuntimeError; end
4 |
5 | context "Mapped errors" do
6 |
7 | setup do
8 | Sinatra.application = nil
9 | Sinatra.application.options.raise_errors = false
10 | end
11 |
12 | specify "are rescued and run in context" do
13 |
14 | error FooError do
15 | 'MAPPED ERROR!'
16 | end
17 |
18 | get '/' do
19 | raise FooError
20 | end
21 |
22 | get_it '/'
23 |
24 | should.be.server_error
25 | body.should.equal 'MAPPED ERROR!'
26 |
27 | end
28 |
29 | specify "renders empty if no each method on result" do
30 |
31 | error FooError do
32 | nil
33 | end
34 |
35 | get '/' do
36 | raise FooError
37 | end
38 |
39 | get_it '/'
40 |
41 | should.be.server_error
42 | body.should.be.empty
43 |
44 | end
45 |
46 | specify "doesn't override status if set" do
47 |
48 | error FooError do
49 | status(200)
50 | end
51 |
52 | get '/' do
53 | raise FooError
54 | end
55 |
56 | get_it '/'
57 |
58 | should.be.ok
59 |
60 | end
61 |
62 | specify "raises errors when the raise_errors option is set" do
63 | Sinatra.application.options.raise_errors = true
64 | error FooError do
65 | end
66 | get '/' do
67 | raise FooError
68 | end
69 | assert_raises(FooError) { get_it('/') }
70 | end
71 |
72 | end
73 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/pipeline_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | class UpcaseMiddleware
4 | def initialize(app, *args, &block)
5 | @app = app
6 | @args = args
7 | @block = block
8 | end
9 | def call(env)
10 | env['PATH_INFO'] = env['PATH_INFO'].to_s.upcase
11 | @app.call(env)
12 | end
13 | end
14 |
15 | context "Middleware Pipelines" do
16 |
17 | setup do
18 | Sinatra.application = nil
19 | @app = Sinatra.application
20 | end
21 |
22 | teardown do
23 | Sinatra.application = nil
24 | end
25 |
26 | specify "should add middleware with use" do
27 | block = Proc.new { |env| }
28 | @app.use UpcaseMiddleware
29 | @app.use UpcaseMiddleware, "foo", "bar"
30 | @app.use UpcaseMiddleware, "foo", "bar", &block
31 | @app.send(:middleware).should.include([UpcaseMiddleware, [], nil])
32 | @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], nil])
33 | @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], block])
34 | end
35 |
36 | specify "should run middleware added with use" do
37 | get('/foo') { "FAIL!" }
38 | get('/FOO') { "PASS!" }
39 | use UpcaseMiddleware
40 | get_it '/foo'
41 | should.be.ok
42 | body.should.equal "PASS!"
43 | end
44 |
45 | end
46 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/public/foo.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/sass_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | context "Sass" do
4 |
5 | setup do
6 | Sinatra.application = nil
7 | end
8 |
9 | context "Templates (in general)" do
10 |
11 | setup do
12 | Sinatra.application = nil
13 | end
14 |
15 | specify "are read from files if Symbols" do
16 |
17 | get '/from_file' do
18 | sass :foo, :views_directory => File.dirname(__FILE__) + "/views"
19 | end
20 |
21 | get_it '/from_file'
22 | should.be.ok
23 | body.should.equal "#sass {\n background_color: #FFF; }\n"
24 |
25 | end
26 |
27 | specify "raise an error if template not found" do
28 | get '/' do
29 | sass :not_found
30 | end
31 |
32 | lambda { get_it '/' }.should.raise(Errno::ENOENT)
33 | end
34 |
35 | specify "ignore default layout file with .sass extension" do
36 | get '/' do
37 | sass :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
38 | end
39 |
40 | get_it '/'
41 | should.be.ok
42 | body.should.equal "#sass {\n background_color: #FFF; }\n"
43 | end
44 |
45 | specify "ignore explicitly specified layout file" do
46 | get '/' do
47 | sass :foo, :layout => :layout, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
48 | end
49 |
50 | get_it '/'
51 | should.be.ok
52 | body.should.equal "#sass {\n background_color: #FFF; }\n"
53 | end
54 |
55 | it "passes :sass option to the Sass engine" do
56 | get '/' do
57 | sass "#sass\n :background-color #FFF\n :color #000\n", :sass => {:style => :compact}
58 | end
59 |
60 | get_it '/'
61 | should.be.ok
62 | body.should.equal "#sass { background-color: #FFF; color: #000; }\n"
63 | end
64 |
65 | end
66 |
67 | end
68 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/sessions_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | context "Sessions" do
4 |
5 | setup { Sinatra.application = nil }
6 |
7 | specify "should be off by default" do
8 | get '/asdf' do
9 | session[:test] = true
10 | "asdf"
11 | end
12 |
13 | get '/test' do
14 | session[:test] == true ? "true" : "false"
15 | end
16 |
17 | get_it '/asdf', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
18 | assert ok?
19 | assert !include?('Set-Cookie')
20 | end
21 |
22 | specify "should be able to store data accross requests" do
23 | set_option :sessions, true
24 | set_option :environment, :not_test # necessary because sessions are disabled
25 |
26 | get '/foo' do
27 | session[:test] = true
28 | "asdf"
29 | end
30 |
31 | get '/bar' do
32 | session[:test] == true ? "true" : "false"
33 | end
34 |
35 | get_it '/foo', :env => { :host => 'foo.sinatrarb.com' }
36 | assert ok?
37 | assert include?('Set-Cookie')
38 |
39 | set_option :environment, :test
40 | end
41 |
42 | end
43 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/sym_params_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | context "Symbol Params" do
4 |
5 | setup do
6 | Sinatra.application = nil
7 | end
8 |
9 | specify "should be accessable as Strings or Symbols" do
10 | get '/' do
11 | params[:foo] + params['foo']
12 | end
13 |
14 | get_it '/', :foo => "X"
15 | assert_equal('XX', body)
16 | end
17 |
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/template_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | context "Templates" do
4 |
5 | specify "are read from files if Symbols" do
6 |
7 | get '/from_file' do
8 | @name = 'Alena'
9 | erb :foo, :views_directory => File.dirname(__FILE__) + "/views"
10 | end
11 |
12 | get_it '/from_file'
13 |
14 | body.should.equal 'You rock Alena!'
15 |
16 | end
17 |
18 | specify "use layout.ext by default if available" do
19 |
20 | get '/layout_from_file' do
21 | erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
22 | end
23 |
24 | get_it '/layout_from_file'
25 | should.be.ok
26 | body.should.equal "x This is foo! x \n"
27 |
28 | end
29 |
30 | end
31 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/use_in_file_templates_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | context "Rendering in file templates" do
4 |
5 | setup do
6 | Sinatra.application = nil
7 | use_in_file_templates!
8 | end
9 |
10 | specify "should set template" do
11 | assert Sinatra.application.templates[:foo]
12 | end
13 |
14 | specify "should set layout" do
15 | assert Sinatra.application.templates[:layout]
16 | end
17 |
18 | specify "should render without layout if specified" do
19 | get '/' do
20 | haml :foo, :layout => false
21 | end
22 |
23 | get_it '/'
24 | assert_equal "this is foo\n", body
25 | end
26 |
27 | specify "should render with layout if specified" do
28 | get '/' do
29 | haml :foo
30 | end
31 |
32 | get_it '/'
33 | assert_equal "X\nthis is foo\nX\n", body
34 | end
35 |
36 | end
37 |
38 | __END__
39 |
40 | @@ foo
41 | this is foo
42 |
43 | @@ layout
44 | X
45 | = yield
46 | X
47 |
48 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/foo.builder:
--------------------------------------------------------------------------------
1 | xml.exclaim "You rock #{@name}!"
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/foo.erb:
--------------------------------------------------------------------------------
1 | You rock <%= @name %>!
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/foo.haml:
--------------------------------------------------------------------------------
1 | == You rock #{@name}!
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/foo.sass:
--------------------------------------------------------------------------------
1 | #sass
2 | :background_color #FFF
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/foo_layout.erb:
--------------------------------------------------------------------------------
1 | <%= @title %>
2 | Hi <%= yield %>
3 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/foo_layout.haml:
--------------------------------------------------------------------------------
1 | == #{@title}
2 | == Hi #{yield}
3 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/layout_test/foo.builder:
--------------------------------------------------------------------------------
1 | xml.this "is foo!"
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/layout_test/foo.erb:
--------------------------------------------------------------------------------
1 | This is foo!
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/layout_test/foo.haml:
--------------------------------------------------------------------------------
1 | This is foo!
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/layout_test/foo.sass:
--------------------------------------------------------------------------------
1 | #sass
2 | :background_color #FFF
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/layout_test/layout.builder:
--------------------------------------------------------------------------------
1 | xml.layout do
2 | xml << yield
3 | end
4 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/layout_test/layout.erb:
--------------------------------------------------------------------------------
1 | x <%= yield %> x
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/layout_test/layout.haml:
--------------------------------------------------------------------------------
1 | == x #{yield} x
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/layout_test/layout.sass:
--------------------------------------------------------------------------------
1 | b0rked!
2 | = yield
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/no_layout/no_layout.builder:
--------------------------------------------------------------------------------
1 | xml.foo "No Layout!"
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/compat/views/no_layout/no_layout.haml:
--------------------------------------------------------------------------------
1 | %h1 No Layout!
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/lib/sinatra.rb:
--------------------------------------------------------------------------------
1 | libdir = File.dirname(__FILE__)
2 | $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3 |
4 | require 'sinatra/base'
5 | require 'sinatra/main'
6 | require 'sinatra/compat'
7 |
8 | use_in_file_templates!
9 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/lib/sinatra/images/404.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ehsanul/Sinatra-Authlogic-Template/3c43548960d34f39d35d7102ba422f26e282586f/vendor/sinatra-0.9.4/lib/sinatra/images/404.png
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/lib/sinatra/images/500.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ehsanul/Sinatra-Authlogic-Template/3c43548960d34f39d35d7102ba422f26e282586f/vendor/sinatra-0.9.4/lib/sinatra/images/500.png
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/lib/sinatra/main.rb:
--------------------------------------------------------------------------------
1 | require 'sinatra/base'
2 |
3 | module Sinatra
4 | class Default < Base
5 |
6 | # we assume that the first file that requires 'sinatra' is the
7 | # app_file. all other path related options are calculated based
8 | # on this path by default.
9 | set :app_file, caller_files.first || $0
10 |
11 | set :run, Proc.new { $0 == app_file }
12 |
13 | if run? && ARGV.any?
14 | require 'optparse'
15 | OptionParser.new { |op|
16 | op.on('-x') { set :lock, true }
17 | op.on('-e env') { |val| set :environment, val.to_sym }
18 | op.on('-s server') { |val| set :server, val }
19 | op.on('-p port') { |val| set :port, val.to_i }
20 | }.parse!(ARGV.dup)
21 | end
22 | end
23 | end
24 |
25 | include Sinatra::Delegator
26 |
27 | def mime(ext, type)
28 | ext = ".#{ext}" unless ext.to_s[0] == ?.
29 | Rack::Mime::MIME_TYPES[ext.to_s] = type
30 | end
31 |
32 | at_exit do
33 | raise $! if $!
34 | Sinatra::Application.run! if Sinatra::Application.run?
35 | end
36 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/lib/sinatra/test/bacon.rb:
--------------------------------------------------------------------------------
1 | require 'bacon'
2 | require 'sinatra/test'
3 |
4 | Sinatra::Test.deprecate('Bacon')
5 |
6 | Sinatra::Default.set(
7 | :environment => :test,
8 | :run => false,
9 | :raise_errors => true,
10 | :logging => false
11 | )
12 |
13 | module Sinatra::Test
14 | def should
15 | @response.should
16 | end
17 | end
18 |
19 | Bacon::Context.send(:include, Sinatra::Test)
20 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/lib/sinatra/test/rspec.rb:
--------------------------------------------------------------------------------
1 | require 'sinatra/test'
2 | require 'sinatra/test/unit'
3 | require 'spec'
4 | require 'spec/interop/test'
5 |
6 | Sinatra::Test.deprecate('RSpec')
7 |
8 | Sinatra::Default.set(
9 | :environment => :test,
10 | :run => false,
11 | :raise_errors => true,
12 | :logging => false
13 | )
14 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/lib/sinatra/test/spec.rb:
--------------------------------------------------------------------------------
1 | require 'test/spec'
2 | require 'sinatra/test'
3 | require 'sinatra/test/unit'
4 |
5 | Sinatra::Test.deprecate('test/spec')
6 |
7 | module Sinatra::Test
8 | def should
9 | @response.should
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/lib/sinatra/test/unit.rb:
--------------------------------------------------------------------------------
1 | require 'sinatra/test'
2 | require 'test/unit'
3 |
4 | Sinatra::Test.deprecate('test/unit')
5 |
6 | Test::Unit::TestCase.send :include, Sinatra::Test
7 |
8 | Sinatra::Default.set(
9 | :environment => :test,
10 | :run => false,
11 | :raise_errors => true,
12 | :logging => false
13 | )
14 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/builder_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 | require 'builder'
3 |
4 | class BuilderTest < Test::Unit::TestCase
5 | def builder_app(&block)
6 | mock_app {
7 | set :views, File.dirname(__FILE__) + '/views'
8 | get '/', &block
9 | }
10 | get '/'
11 | end
12 |
13 | it 'renders inline Builder strings' do
14 | builder_app { builder 'xml.instruct!' }
15 | assert ok?
16 | assert_equal %{\n}, body
17 | end
18 |
19 | it 'renders inline blocks' do
20 | builder_app {
21 | @name = "Frank & Mary"
22 | builder do |xml|
23 | xml.couple @name
24 | end
25 | }
26 | assert ok?
27 | assert_equal "Frank & Mary\n", body
28 | end
29 |
30 | it 'renders .builder files in views path' do
31 | builder_app {
32 | @name = "Blue"
33 | builder :hello
34 | }
35 | assert ok?
36 | assert_equal %(You're my boy, Blue!\n), body
37 | end
38 |
39 | it "renders with inline layouts" do
40 | mock_app {
41 | layout do
42 | %(xml.layout { xml << yield })
43 | end
44 | get('/') { builder %(xml.em 'Hello World') }
45 | }
46 | get '/'
47 | assert ok?
48 | assert_equal "\nHello World\n\n", body
49 | end
50 |
51 | it "renders with file layouts" do
52 | builder_app {
53 | builder %(xml.em 'Hello World'), :layout => :layout2
54 | }
55 | assert ok?
56 | assert_equal "\nHello World\n\n", body
57 | end
58 |
59 | it "raises error if template not found" do
60 | mock_app {
61 | get('/') { builder :no_such_template }
62 | }
63 | assert_raise(Errno::ENOENT) { get('/') }
64 | end
65 | end
66 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/contest.rb:
--------------------------------------------------------------------------------
1 | require "test/unit"
2 |
3 | # Test::Unit loads a default test if the suite is empty, and the only
4 | # purpose of that test is to fail. As having empty contexts is a common
5 | # practice, we decided to overwrite TestSuite#empty? in order to
6 | # allow them. Having a failure when no tests have been defined seems
7 | # counter-intuitive.
8 | class Test::Unit::TestSuite
9 | unless method_defined?(:empty?)
10 | def empty?
11 | false
12 | end
13 | end
14 | end
15 |
16 | # We added setup, test and context as class methods, and the instance
17 | # method setup now iterates on the setup blocks. Note that all setup
18 | # blocks must be defined with the block syntax. Adding a setup instance
19 | # method defeats the purpose of this library.
20 | class Test::Unit::TestCase
21 | def self.setup(&block)
22 | setup_blocks << block
23 | end
24 |
25 | def setup
26 | self.class.setup_blocks.each do |block|
27 | instance_eval(&block)
28 | end
29 | end
30 |
31 | def self.context(name, &block)
32 | subclass = Class.new(self.superclass)
33 | subclass.setup_blocks.unshift(*setup_blocks)
34 | subclass.class_eval(&block)
35 | const_set(context_name(name), subclass)
36 | end
37 |
38 | def self.test(name, &block)
39 | define_method(test_name(name), &block)
40 | end
41 |
42 | class << self
43 | alias_method :should, :test
44 | alias_method :describe, :context
45 | end
46 |
47 | private
48 |
49 | def self.setup_blocks
50 | @setup_blocks ||= []
51 | end
52 |
53 | def self.context_name(name)
54 | "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
55 | end
56 |
57 | def self.test_name(name)
58 | "test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym
59 | end
60 |
61 | def self.sanitize_name(name)
62 | name.gsub(/\W+/, ' ').strip
63 | end
64 | end
65 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/data/reload_app_file.rb:
--------------------------------------------------------------------------------
1 | $reload_count += 1
2 |
3 | $reload_app.get('/') { 'Hello from reload file' }
4 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/erb_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | class ERBTest < Test::Unit::TestCase
4 | def erb_app(&block)
5 | mock_app {
6 | set :views, File.dirname(__FILE__) + '/views'
7 | get '/', &block
8 | }
9 | get '/'
10 | end
11 |
12 | it 'renders inline ERB strings' do
13 | erb_app { erb '<%= 1 + 1 %>' }
14 | assert ok?
15 | assert_equal '2', body
16 | end
17 |
18 | it 'renders .erb files in views path' do
19 | erb_app { erb :hello }
20 | assert ok?
21 | assert_equal "Hello World\n", body
22 | end
23 |
24 | it 'takes a :locals option' do
25 | erb_app {
26 | locals = {:foo => 'Bar'}
27 | erb '<%= foo %>', :locals => locals
28 | }
29 | assert ok?
30 | assert_equal 'Bar', body
31 | end
32 |
33 | it "renders with inline layouts" do
34 | mock_app {
35 | layout { 'THIS. IS. <%= yield.upcase %>!' }
36 | get('/') { erb 'Sparta' }
37 | }
38 | get '/'
39 | assert ok?
40 | assert_equal 'THIS. IS. SPARTA!', body
41 | end
42 |
43 | it "renders with file layouts" do
44 | erb_app {
45 | erb 'Hello World', :layout => :layout2
46 | }
47 | assert ok?
48 | assert_equal "ERB Layout!\nHello World\n", body
49 | end
50 |
51 | it "renders erb with blocks" do
52 | mock_app {
53 | def container
54 | @_out_buf << "THIS."
55 | yield
56 | @_out_buf << "SPARTA!"
57 | end
58 | def is; "IS." end
59 | get '/' do
60 | erb '<% container do %> <%= is %> <% end %>'
61 | end
62 | }
63 | get '/'
64 | assert ok?
65 | assert_equal 'THIS. IS. SPARTA!', body
66 | end
67 |
68 | it "can be used in a nested fashion for partials and whatnot" do
69 | mock_app {
70 | template(:inner) { "<%= 'hi' %>" }
71 | template(:outer) { "<%= erb :inner %>" }
72 | get '/' do
73 | erb :outer
74 | end
75 | }
76 |
77 | get '/'
78 | assert ok?
79 | assert_equal 'hi', body
80 | end
81 | end
82 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/helper.rb:
--------------------------------------------------------------------------------
1 | ENV['RACK_ENV'] = 'test'
2 |
3 | begin
4 | require 'rack'
5 | rescue LoadError
6 | require 'rubygems'
7 | require 'rack'
8 | end
9 |
10 | testdir = File.dirname(__FILE__)
11 | $LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
12 |
13 | libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
14 | $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
15 |
16 | require 'contest'
17 | require 'rack/test'
18 | require 'sinatra/base'
19 |
20 | class Sinatra::Base
21 | # Allow assertions in request context
22 | include Test::Unit::Assertions
23 | end
24 |
25 | Sinatra::Base.set :environment, :test
26 |
27 | class Test::Unit::TestCase
28 | include Rack::Test::Methods
29 |
30 | class << self
31 | alias_method :it, :test
32 | end
33 |
34 | alias_method :response, :last_response
35 |
36 | setup do
37 | Sinatra::Base.set :environment, :test
38 | end
39 |
40 | # Sets up a Sinatra::Base subclass defined with the block
41 | # given. Used in setup or individual spec methods to establish
42 | # the application.
43 | def mock_app(base=Sinatra::Base, &block)
44 | @app = Sinatra.new(base, &block)
45 | end
46 |
47 | def app
48 | Rack::Lint.new(@app)
49 | end
50 |
51 | def body
52 | response.body.to_s
53 | end
54 |
55 | # Delegate other missing methods to response.
56 | def method_missing(name, *args, &block)
57 | if response && response.respond_to?(name)
58 | response.send(name, *args, &block)
59 | else
60 | super
61 | end
62 | end
63 |
64 | # Also check response since we delegate there.
65 | def respond_to?(symbol, include_private=false)
66 | super || (response && response.respond_to?(symbol, include_private))
67 | end
68 |
69 | # Do not output warnings for the duration of the block.
70 | def silence_warnings
71 | $VERBOSE, v = nil, $VERBOSE
72 | yield
73 | ensure
74 | $VERBOSE = v
75 | end
76 | end
77 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/middleware_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | class MiddlewareTest < Test::Unit::TestCase
4 | setup do
5 | @app = mock_app(Sinatra::Default) {
6 | get '/*' do
7 | response.headers['X-Tests'] = env['test.ran'].
8 | map { |n| n.split('::').last }.
9 | join(', ')
10 | env['PATH_INFO']
11 | end
12 | }
13 | end
14 |
15 | class MockMiddleware < Struct.new(:app)
16 | def call(env)
17 | (env['test.ran'] ||= []) << self.class.to_s
18 | app.call(env)
19 | end
20 | end
21 |
22 | class UpcaseMiddleware < MockMiddleware
23 | def call(env)
24 | env['PATH_INFO'] = env['PATH_INFO'].upcase
25 | super
26 | end
27 | end
28 |
29 | it "is added with Sinatra::Application.use" do
30 | @app.use UpcaseMiddleware
31 | get '/hello-world'
32 | assert ok?
33 | assert_equal '/HELLO-WORLD', body
34 | end
35 |
36 | class DowncaseMiddleware < MockMiddleware
37 | def call(env)
38 | env['PATH_INFO'] = env['PATH_INFO'].downcase
39 | super
40 | end
41 | end
42 |
43 | it "runs in the order defined" do
44 | @app.use UpcaseMiddleware
45 | @app.use DowncaseMiddleware
46 | get '/Foo'
47 | assert_equal "/foo", body
48 | assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
49 | end
50 |
51 | it "resets the prebuilt pipeline when new middleware is added" do
52 | @app.use UpcaseMiddleware
53 | get '/Foo'
54 | assert_equal "/FOO", body
55 | @app.use DowncaseMiddleware
56 | get '/Foo'
57 | assert_equal '/foo', body
58 | assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
59 | end
60 |
61 | it "works when app is used as middleware" do
62 | @app.use UpcaseMiddleware
63 | @app = @app.new
64 | get '/Foo'
65 | assert_equal "/FOO", body
66 | assert_equal "UpcaseMiddleware", response['X-Tests']
67 | end
68 | end
69 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/request_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | class RequestTest < Test::Unit::TestCase
4 | it 'responds to #user_agent' do
5 | request = Sinatra::Request.new({'HTTP_USER_AGENT' => 'Test'})
6 | assert request.respond_to?(:user_agent)
7 | assert_equal 'Test', request.user_agent
8 | end
9 |
10 | it 'parses POST params when Content-Type is form-dataish' do
11 | request = Sinatra::Request.new(
12 | 'REQUEST_METHOD' => 'PUT',
13 | 'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
14 | 'rack.input' => StringIO.new('foo=bar')
15 | )
16 | assert_equal 'bar', request.params['foo']
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/response_test.rb:
--------------------------------------------------------------------------------
1 | # encoding: utf-8
2 |
3 | require File.dirname(__FILE__) + '/helper'
4 |
5 | class ResponseTest < Test::Unit::TestCase
6 | setup do
7 | @response = Sinatra::Response.new
8 | end
9 |
10 | it "initializes with 200, text/html, and empty body" do
11 | assert_equal 200, @response.status
12 | assert_equal 'text/html', @response['Content-Type']
13 | assert_equal [], @response.body
14 | end
15 |
16 | it 'uses case insensitive headers' do
17 | @response['content-type'] = 'application/foo'
18 | assert_equal 'application/foo', @response['Content-Type']
19 | assert_equal 'application/foo', @response['CONTENT-TYPE']
20 | end
21 |
22 | it 'writes to body' do
23 | @response.body = 'Hello'
24 | @response.write ' World'
25 | assert_equal 'Hello World', @response.body
26 | end
27 |
28 | [204, 304].each do |status_code|
29 | it "removes the Content-Type header and body when response status is #{status_code}" do
30 | @response.status = status_code
31 | @response.body = ['Hello World']
32 | assert_equal [status_code, {}, []], @response.finish
33 | end
34 | end
35 |
36 | it 'Calculates the Content-Length using the bytesize of the body' do
37 | @response.body = ['Hello', 'World!', '✈']
38 | status, headers, body = @response.finish
39 | assert_equal '14', headers['Content-Length']
40 | assert_equal @response.body, body
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/result_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | class ResultTest < Test::Unit::TestCase
4 | it "sets response.body when result is a String" do
5 | mock_app {
6 | get '/' do
7 | 'Hello World'
8 | end
9 | }
10 |
11 | get '/'
12 | assert ok?
13 | assert_equal 'Hello World', body
14 | end
15 |
16 | it "sets response.body when result is an Array of Strings" do
17 | mock_app {
18 | get '/' do
19 | ['Hello', 'World']
20 | end
21 | }
22 |
23 | get '/'
24 | assert ok?
25 | assert_equal 'HelloWorld', body
26 | end
27 |
28 | it "sets response.body when result responds to #each" do
29 | mock_app {
30 | get '/' do
31 | res = lambda { 'Hello World' }
32 | def res.each ; yield call ; end
33 | res
34 | end
35 | }
36 |
37 | get '/'
38 | assert ok?
39 | assert_equal 'Hello World', body
40 | end
41 |
42 | it "sets response.body to [] when result is nil" do
43 | mock_app {
44 | get '/' do
45 | nil
46 | end
47 | }
48 |
49 | get '/'
50 | assert ok?
51 | assert_equal '', body
52 | end
53 |
54 | it "sets status, headers, and body when result is a Rack response tuple" do
55 | mock_app {
56 | get '/' do
57 | [205, {'Content-Type' => 'foo/bar'}, 'Hello World']
58 | end
59 | }
60 |
61 | get '/'
62 | assert_equal 205, status
63 | assert_equal 'foo/bar', response['Content-Type']
64 | assert_equal 'Hello World', body
65 | end
66 |
67 | it "sets status and body when result is a two-tuple" do
68 | mock_app {
69 | get '/' do
70 | [409, 'formula of']
71 | end
72 | }
73 |
74 | get '/'
75 | assert_equal 409, status
76 | assert_equal 'formula of', body
77 | end
78 |
79 | it "raises a TypeError when result is a non two or three tuple Array" do
80 | mock_app {
81 | get '/' do
82 | [409, 'formula of', 'something else', 'even more']
83 | end
84 | }
85 |
86 | assert_raise(TypeError) { get '/' }
87 | end
88 |
89 | it "sets status when result is a Fixnum status code" do
90 | mock_app {
91 | get('/') { 205 }
92 | }
93 |
94 | get '/'
95 | assert_equal 205, status
96 | assert_equal '', body
97 | end
98 | end
99 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/route_added_hook_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | module RouteAddedTest
4 | @routes, @procs = [], []
5 | def self.routes ; @routes ; end
6 | def self.procs ; @procs ; end
7 | def self.route_added(verb, path, proc)
8 | @routes << [verb, path]
9 | @procs << proc
10 | end
11 | end
12 |
13 | class RouteAddedHookTest < Test::Unit::TestCase
14 | setup {
15 | RouteAddedTest.routes.clear
16 | RouteAddedTest.procs.clear
17 | }
18 |
19 | it "should be notified of an added route" do
20 | mock_app(Class.new(Sinatra::Base)) {
21 | register RouteAddedTest
22 | get('/') {}
23 | }
24 |
25 | assert_equal [["GET", "/"], ["HEAD", "/"]],
26 | RouteAddedTest.routes
27 | end
28 |
29 | it "should include hooks from superclass" do
30 | a = Class.new(Class.new(Sinatra::Base))
31 | b = Class.new(a)
32 |
33 | a.register RouteAddedTest
34 | b.class_eval { post("/sub_app_route") {} }
35 |
36 | assert_equal [["POST", "/sub_app_route"]],
37 | RouteAddedTest.routes
38 | end
39 |
40 | it "should only run once per extension" do
41 | mock_app(Class.new(Sinatra::Base)) {
42 | register RouteAddedTest
43 | register RouteAddedTest
44 | get('/') {}
45 | }
46 |
47 | assert_equal [["GET", "/"], ["HEAD", "/"]],
48 | RouteAddedTest.routes
49 | end
50 |
51 | it "should pass route blocks as an argument" do
52 | mock_app(Class.new(Sinatra::Base)) {
53 | register RouteAddedTest
54 | get('/') {}
55 | }
56 |
57 | assert_kind_of Proc, RouteAddedTest.procs.first
58 | end
59 | end
60 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/server_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | module Rack::Handler
4 | class Mock
5 | extend Test::Unit::Assertions
6 |
7 | def self.run(app, options={})
8 | assert(app < Sinatra::Base)
9 | assert_equal 9001, options[:Port]
10 | assert_equal 'foo.local', options[:Host]
11 | yield new
12 | end
13 |
14 | def stop
15 | end
16 | end
17 |
18 | register 'mock', 'Rack::Handler::Mock'
19 | end
20 |
21 | class ServerTest < Test::Unit::TestCase
22 | setup do
23 | mock_app {
24 | set :server, 'mock'
25 | set :host, 'foo.local'
26 | set :port, 9001
27 | }
28 | $stdout = File.open('/dev/null', 'wb')
29 | end
30 |
31 | def teardown
32 | $stdout = STDOUT
33 | end
34 |
35 | it "locates the appropriate Rack handler and calls ::run" do
36 | @app.run!
37 | end
38 |
39 | it "sets options on the app before running" do
40 | @app.run! :sessions => true
41 | assert @app.sessions?
42 | end
43 |
44 | it "falls back on the next server handler when not found" do
45 | @app.run! :server => %w[foo bar mock]
46 | end
47 | end
48 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/sinatra_test.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/helper'
2 |
3 | class SinatraTest < Test::Unit::TestCase
4 | it 'creates a new Sinatra::Base subclass on new' do
5 | app =
6 | Sinatra.new do
7 | get '/' do
8 | 'Hello World'
9 | end
10 | end
11 | assert_same Sinatra::Base, app.superclass
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/error.builder:
--------------------------------------------------------------------------------
1 | xml.error do
2 | raise "goodbye"
3 | end
4 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/error.erb:
--------------------------------------------------------------------------------
1 | Hello <%= 'World' %>
2 | <% raise 'Goodbye' unless defined?(french) && french %>
3 | <% raise 'Au revoir' if defined?(french) && french %>
4 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/error.haml:
--------------------------------------------------------------------------------
1 | %h1 Hello From Haml
2 | = raise 'goodbye' unless defined?(french) && french
3 | = raise 'au revoir' if defined?(french) && french
4 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/error.sass:
--------------------------------------------------------------------------------
1 | #sass
2 | +argle-bargle
3 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/foo/hello.test:
--------------------------------------------------------------------------------
1 | from another views directory
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/hello.builder:
--------------------------------------------------------------------------------
1 | xml.exclaim "You're my boy, #{@name}!"
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/hello.erb:
--------------------------------------------------------------------------------
1 | Hello <%= 'World' %>
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/hello.haml:
--------------------------------------------------------------------------------
1 | %h1 Hello From Haml
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/hello.sass:
--------------------------------------------------------------------------------
1 | #sass
2 | :background-color #FFF
3 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/hello.test:
--------------------------------------------------------------------------------
1 | Hello World!
2 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/layout2.builder:
--------------------------------------------------------------------------------
1 | xml.layout do
2 | xml << yield
3 | end
4 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/layout2.erb:
--------------------------------------------------------------------------------
1 | ERB Layout!
2 | <%= yield %>
3 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/layout2.haml:
--------------------------------------------------------------------------------
1 | %h1 HAML Layout!
2 | %p= yield
3 |
--------------------------------------------------------------------------------
/vendor/sinatra-0.9.4/test/views/layout2.test:
--------------------------------------------------------------------------------
1 | Layout 2!
2 |
--------------------------------------------------------------------------------
/views/activate.haml:
--------------------------------------------------------------------------------
1 | Select a password and activate your account below.
2 | %br/
3 | %br/
4 | %form{ :method => "post", :action => '/activate' }
5 | Password:
6 | %input{ :type => 'text', :size => 20, :name => 'password' }
7 | %br/
8 | Confirm Password:
9 | %input{ :type => 'text', :size => 20, :name => 'password_confirmation' }
10 | %br/
11 | %input{ :type => 'hidden', :value => @user.perishable_token, :name => 'token' }
12 | %input{ :type => 'submit', :value => 'Activate' }
13 |
--------------------------------------------------------------------------------
/views/forgot_password.haml:
--------------------------------------------------------------------------------
1 | = "Forgot your password? Enter your email address, and we'll email you a link to reset your password."
2 | %br/
3 | %br/
4 | %form{:method => "post"}
5 | Email:
6 | %br/
7 | %input{:type=>'text', :size=>20, :name=>'email'}
8 | %br/
9 | %input{:type=>'submit', :value=>'Email me'}
10 |
11 |
--------------------------------------------------------------------------------
/views/index.haml:
--------------------------------------------------------------------------------
1 | Home page
2 | %br/
3 | You're
4 | = current_user ? "logged in" : "not logged in"
5 |
--------------------------------------------------------------------------------
/views/layout.haml:
--------------------------------------------------------------------------------
1 | !!!
2 | %html
3 | %head
4 |
5 |
6 | %body
7 | = link 'Home', '/'
8 | - if current_user
9 | = link 'Logout', '/logout'
10 | - else
11 | = link 'Signup', '/signup'
12 | = link 'Login', '/login'
13 | = link 'Show', '/show'
14 | = link 'Restricted', '/restricted'
15 | %br/
16 | %br/
17 | - if msg = notice
18 | = msg
19 | %br/
20 | %br/
21 | #container
22 | = yield
23 |
--------------------------------------------------------------------------------
/views/login.haml:
--------------------------------------------------------------------------------
1 | Login
2 | %br/
3 | %br/
4 | %form{:method => "post"}
5 | Email:
6 | %input{:type=>'text', :size=>20, :name=>'user[email]'}
7 | %br/
8 | Password:
9 | %input{:type=>'password', :size=>20, :name=>'user[password]'}
10 | %br/
11 | Remember Me
12 | %input{:type=>'checkbox', :value => '1', :name => 'user[remember_me]'}
13 | %br/
14 | %input{:type=>'submit', :value=>'Login'}
15 | %br/
16 | %br/
17 | = link('Forgot your password?', '/forgot-password')
--------------------------------------------------------------------------------
/views/resend_activation.haml:
--------------------------------------------------------------------------------
1 | Resend Activation
2 | %br/
3 | %br/
4 | %form{:method => "post"}
5 | Email:
6 | %br/
7 | %input{:type=>'text', :size=>20, :name=>'email'}
8 | %br/
9 | %input{:type=>'submit', :value=>'Resend Activation Email'}
10 |
--------------------------------------------------------------------------------
/views/reset_password.haml:
--------------------------------------------------------------------------------
1 | Reset Password
2 | %br/
3 | %br/
4 | %form{ :method => "post", :action => '/reset_password' }
5 | Password:
6 | %input{ :type => 'text', :size => 20, :name => 'password' }
7 | %br/
8 | Confirm Password:
9 | %input{ :type => 'text', :size => 20, :name => 'password_confirmation' }
10 | %br/
11 | %input{ :type => 'hidden', :value => @user.perishable_token, :name => 'token' }
12 | %input{ :type => 'submit', :value => 'Reset' }
13 |
--------------------------------------------------------------------------------
/views/show.haml:
--------------------------------------------------------------------------------
1 | Email:
2 | = @user.email
3 | %br/
4 | Login count:
5 | = @user.login_count
6 | %br/
7 | Last request at:
8 | = @user.last_request_at
9 | %br/
10 | Last login at:
11 | = @user.last_login_at
12 | %br/
13 | Current login at:
14 | = @user.current_login_at
15 | %br/
16 | Last login ip:
17 | = @user.last_login_ip
18 | %br/
19 | Current login ip:
20 | = @user.current_login_ip
21 |
22 |
--------------------------------------------------------------------------------
/views/signup.haml:
--------------------------------------------------------------------------------
1 | Sign up
2 | %br/
3 | %br/
4 | %form{:method => "post"}
5 | Email:
6 | %br/
7 | %input{:type=>'text', :size=>20, :name=>'email'}
8 | %br/
9 | %input{:type=>'submit', :value=>'Sign up'}
10 |
--------------------------------------------------------------------------------