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
# 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],
    ["test/response.cookies", :to_cookies]
  ]
end

#from_enumObject


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

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

#from_stringObject


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

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

#process_postObject

Response intentionally left blank to test 204 support


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

def process_post
  true
end

#to_cookiesObject


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

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?
  request.cookies["echo"] || ""
end

#to_enumObject


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

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

#to_fiberObject


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

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

#to_ioObject


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

def to_io
  StringIO.new("IO response body")
end

#to_procObject


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

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

#to_stringObject


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

def to_string
  "String response body"
end