Class: Web2Go::MockRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/Web2Go/MockRequest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = 'http://localhost/', env = ENV) ⇒ MockRequest


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/Web2Go/MockRequest.rb', line 33

def initialize(url = 'http://localhost/',env=ENV)
  @server_variable = get_server_variables(url)
  @server_variable.update( env)

  @params = CGI::parse(@server_variable['QUERY_STRING'])
  @user = env['REMOTE_USER'] || env['USER'] || env['USERNAME']
  @authenticated = env.has_key?('AUTH_TYPE')
  @uploaded_files = {}
  @cookies = {} 
  @request_method = env['REQUEST_METHOD'] || 'GET'
end

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies


29
30
31
# File 'lib/Web2Go/MockRequest.rb', line 29

def cookies
  @cookies
end

#paramsObject (readonly)

Request interface


27
28
29
# File 'lib/Web2Go/MockRequest.rb', line 27

def params
  @params
end

#request_methodObject

Returns the value of attribute request_method


31
32
33
# File 'lib/Web2Go/MockRequest.rb', line 31

def request_method
  @request_method
end

#server_variableObject (readonly)

Returns the value of attribute server_variable


30
31
32
# File 'lib/Web2Go/MockRequest.rb', line 30

def server_variable
  @server_variable
end

#userObject

Returns the value of attribute user


28
29
30
# File 'lib/Web2Go/MockRequest.rb', line 28

def user
  @user
end

Instance Method Details


114
115
116
# File 'lib/Web2Go/MockRequest.rb', line 114

def add_cookie(name,value,domain=nil,expires=nil)
  @cookies[name] = MockCookie.new(name,value,domain,expires)
end

#add_parameter(name, value) ⇒ Object

Mock manipulation


97
98
99
100
101
102
103
# File 'lib/Web2Go/MockRequest.rb', line 97

def add_parameter(name,value)
  if @params.has_key?(name) then
    @params[name].push(value)
  else
    @params[name] = [ value ]
  end
end

#authenticated=(on) ⇒ Object


71
72
73
# File 'lib/Web2Go/MockRequest.rb', line 71

def authenticated=(on)
    @authenticated = on
end

#authenticated?Boolean Also known as: authenticated


65
66
67
# File 'lib/Web2Go/MockRequest.rb', line 65

def authenticated?
    @authenticated
end

92
93
94
# File 'lib/Web2Go/MockRequest.rb', line 92

def cookie(name)
  return @cookies[name]
end

#hostObject


53
54
55
# File 'lib/Web2Go/MockRequest.rb', line 53

def host
  @server_variable['SERVER_NAME']
end

#parameter(name, default_value = nil) ⇒ Object


75
76
77
78
79
80
81
82
# File 'lib/Web2Go/MockRequest.rb', line 75

def parameter(name,default_value=nil)
  value = @params[name]
  if value.nil? || value.length ==0 then
    return default_value
  else
    return value[0]
  end
end

#pathObject


49
50
51
# File 'lib/Web2Go/MockRequest.rb', line 49

def path
  @server_variable['PATH_INFO']
end

#portObject


57
58
59
# File 'lib/Web2Go/MockRequest.rb', line 57

def port
  @server_variable['SERVER_PORT']
end

#query_stringObject


61
62
63
# File 'lib/Web2Go/MockRequest.rb', line 61

def query_string
  @server_variable['QUERY_STRING']
end

#script_nameObject


45
46
47
# File 'lib/Web2Go/MockRequest.rb', line 45

def script_name
  @server_variable['SCRIPT_NAME']
end

#upload_file(name, filename, content = nil) ⇒ Object


105
106
107
108
109
110
111
112
# File 'lib/Web2Go/MockRequest.rb', line 105

def upload_file(name,filename,content=nil)
  file = MockFile.new(filename,content)
  if @uploaded_files.has_key?(name) then
    @uploaded_files[name].push(file)
  else
    @uploaded_files[name] = [ file ]
  end
end

#uploaded_file(name, pos = 0) ⇒ Object


84
85
86
87
88
89
90
# File 'lib/Web2Go/MockRequest.rb', line 84

def uploaded_file(name,pos=0)
  file = @uploaded_files[name]
  if !file.nil? then
    return file[pos]
  end
  nil
end