Class: Test::Resource

Inherits:
Webmachine::Resource show all
Defined in:
lib/webmachine/spec/test_resource.rb

Instance Attribute Summary

Attributes inherited from Webmachine::Resource

#request, #response

Instance Method Summary collapse

Methods inherited from Webmachine::Resource

new, run

Methods included from Webmachine::Resource::Tracing

#trace?

Methods included from Webmachine::Resource::EntityTags

#weak_etag

Methods included from Webmachine::Resource::Encodings

#encode_deflate, #encode_gzip, #encode_identity

Methods included from Webmachine::Resource::Callbacks

#allow_missing_post?, #base_uri, #charsets_provided, #create_path, #delete_completed?, #delete_resource, #encodings_provided, #expires, #finish_request, #forbidden?, #generate_etag, #handle_exception, #is_authorized?, #is_conflict?, #known_content_type?, #known_methods, #language_chosen, #languages_provided, #last_modified, #malformed_request?, #moved_permanently?, #moved_temporarily?, #multiple_choices?, #options, #post_is_create?, #previously_existed?, #resource_exists?, #service_available?, #uri_too_long?, #valid_content_headers?, #valid_entity_length?, #validate_content_checksum, #variances

Instance Method Details

#allowed_methodsObject



3
4
5
# File 'lib/webmachine/spec/test_resource.rb', line 3

def allowed_methods
  ["GET", "PUT", "POST"]
end

#content_types_acceptedObject



7
8
9
10
11
12
# File 'lib/webmachine/spec/test_resource.rb', line 7

def content_types_accepted
  [
    ["test/request.stringbody", :from_string],
    ["test/request.enumbody", :from_enum]
  ]
end

#content_types_providedObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/webmachine/spec/test_resource.rb', line 14

def content_types_provided
  [
    ["test/response.stringbody", :to_string],
    ["test/response.enumbody", :to_enum],
    ["test/response.procbody", :to_proc],
    ["test/response.fiberbody", :to_fiber],
    ["test/response.iobody", :to_io_body],
    ["test/response.cookies", :to_cookies],
    ["test/response.request_uri", :to_request_uri]
  ]
end

#from_enumObject



30
31
32
33
34
35
# File 'lib/webmachine/spec/test_resource.rb', line 30

def from_enum
  response.body = "Enum: "
  request.body.each do |part|
    response.body += part
  end
end

#from_stringObject



26
27
28
# File 'lib/webmachine/spec/test_resource.rb', line 26

def from_string
  response.body = "String: #{request.body.to_s}"
end

#process_postObject

Response intentionally left blank to test 204 support



38
39
40
# File 'lib/webmachine/spec/test_resource.rb', line 38

def process_post
  true
end

#to_cookiesObject



66
67
68
69
70
71
72
73
# File 'lib/webmachine/spec/test_resource.rb', line 66

def to_cookies
  response.set_cookie("cookie", "monster")
  response.set_cookie("rodeo", "clown")
  # FIXME: Mongrel/WEBrick fail if this method returns nil
  # Might be a net/http issue. Is this a bug?
  # @see Flow#o18, Helpers#encode_body_if_set
  request.cookies["echo"] || ""
end

#to_enumObject



46
47
48
# File 'lib/webmachine/spec/test_resource.rb', line 46

def to_enum
  ["Enumerable ", "response " "body"]
end

#to_fiberObject



54
55
56
57
58
59
60
# File 'lib/webmachine/spec/test_resource.rb', line 54

def to_fiber
  Fiber.new do
    Fiber.yield "Fiber "
    Fiber.yield "response "
    "body"
  end
end

#to_io_bodyObject



62
63
64
# File 'lib/webmachine/spec/test_resource.rb', line 62

def to_io_body
  File.new(File.expand_path('../IO_response.body', __FILE__))
end

#to_procObject



50
51
52
# File 'lib/webmachine/spec/test_resource.rb', line 50

def to_proc
  Proc.new { "Proc response body" }
end

#to_request_uriObject



75
76
77
# File 'lib/webmachine/spec/test_resource.rb', line 75

def to_request_uri
  request.uri.to_s
end

#to_stringObject



42
43
44
# File 'lib/webmachine/spec/test_resource.rb', line 42

def to_string
  "String response body"
end