Class: MockRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/junebug/ext/mosquito.rb

Instance Method Summary collapse

Constructor Details

#initializeMockRequest

Returns a new instance of MockRequest.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/junebug/ext/mosquito.rb', line 34

def initialize
  @headers = {
    'SERVER_NAME' => 'localhost',
    'PATH_INFO' => '',
    'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060214 Camino/1.0',
    'SCRIPT_NAME' => '/',
    'SERVER_PROTOCOL' => 'HTTP/1.1',
    'HTTP_CACHE_CONTROL' => 'max-age=0',
    'HTTP_ACCEPT_LANGUAGE' => 'en,ja;q=0.9,fr;q=0.9,de;q=0.8,es;q=0.7,it;q=0.7,nl;q=0.6,sv;q=0.5,nb;q=0.5,da;q=0.4,fi;q=0.3,pt;q=0.3,zh-Hans;q=0.2,zh-Hant;q=0.1,ko;q=0.1',
    'HTTP_HOST' => 'localhost',
    'REMOTE_ADDR' => '127.0.0.1',
    'SERVER_SOFTWARE' => 'Mongrel 0.3.12.4',
    'HTTP_KEEP_ALIVE' => '300',
    'HTTP_REFERER' => 'http://localhost/',
    'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
    'HTTP_VERSION' => 'HTTP/1.1',
    'REQUEST_URI' => '/',
    'SERVER_PORT' => '80',
    'GATEWAY_INTERFACE' => 'CGI/1.2',
    'HTTP_ACCEPT' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
    'HTTP_CONNECTION' => 'keep-alive',
    'REQUEST_METHOD' => 'GET',
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Allow getters like this:

o.REQUEST_METHOD


80
81
82
83
84
85
86
# File 'lib/junebug/ext/mosquito.rb', line 80

def method_missing(method_name, *args)
  if @headers.has_key?(method_name.to_s)
    return @headers[method_name.to_s]
  else
    super(method_name, args)
  end
end

Instance Method Details

#[](key) ⇒ Object



68
69
70
# File 'lib/junebug/ext/mosquito.rb', line 68

def [](key)
  @headers[key]
end

#[]=(key, value) ⇒ Object



72
73
74
# File 'lib/junebug/ext/mosquito.rb', line 72

def []=(key, value)
  @headers[key] = value
end

#set(key, val) ⇒ Object



60
61
62
# File 'lib/junebug/ext/mosquito.rb', line 60

def set(key, val)
  @headers[key] = val
end

#to_hashObject



64
65
66
# File 'lib/junebug/ext/mosquito.rb', line 64

def to_hash
  @headers
end