Class: Webrat::MerbAdapter

Inherits:
Object show all
Includes:
Merb::Test::MakeRequest, MerbMultipartSupport
Defined in:
lib/webrat/merb_adapter.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MerbMultipartSupport

#multipart_post, #multipart_put, #multipart_request

Constructor Details

#initialize(context = nil) ⇒ MerbAdapter

Returns a new instance of MerbAdapter.



15
# File 'lib/webrat/merb_adapter.rb', line 15

def initialize(context=nil); end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



13
14
15
# File 'lib/webrat/merb_adapter.rb', line 13

def response
  @response
end

Instance Method Details

#delete(url, data, headers = nil) ⇒ Object



29
30
31
# File 'lib/webrat/merb_adapter.rb', line 29

def delete(url, data, headers = nil)
  do_request(url, data, headers, "DELETE")
end

#do_request(url, data, headers, method) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/webrat/merb_adapter.rb', line 41

def do_request(url, data, headers, method)
  if method == "POST" && has_file?(data)
    @response = multipart_post(url, data, :headers => headers)

  elsif method == "PUT" && has_file?(data)
    @response = multipart_put(url, data, :headers => headers)

  else
    @response = request(url,
      :params => (data && data.any?) ? data : nil,
      :headers => headers,
      :method => method)
  end
end

#get(url, data, headers = nil) ⇒ Object



17
18
19
# File 'lib/webrat/merb_adapter.rb', line 17

def get(url, data, headers = nil)
  do_request(url, data, headers, "GET")
end

#post(url, data, headers = nil) ⇒ Object



21
22
23
# File 'lib/webrat/merb_adapter.rb', line 21

def post(url, data, headers = nil)
  do_request(url, data, headers, "POST")
end

#put(url, data, headers = nil) ⇒ Object



25
26
27
# File 'lib/webrat/merb_adapter.rb', line 25

def put(url, data, headers = nil)
  do_request(url, data, headers, "PUT")
end

#response_bodyObject



33
34
35
# File 'lib/webrat/merb_adapter.rb', line 33

def response_body
  @response.body.to_s
end

#response_codeObject



37
38
39
# File 'lib/webrat/merb_adapter.rb', line 37

def response_code
  @response.status
end