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
25
# 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],
    ['test/response.rack_env', :to_rack_env]
  ]
end

#from_enumObject



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

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

#from_stringObject



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

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

#process_postObject

Response intentionally left blank to test 204 support



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

def process_post
  true
end

#to_cookiesObject



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

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



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

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

#to_fiberObject



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

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

#to_io_bodyObject



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

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

#to_procObject



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

def to_proc
  proc { 'Proc response body' }
end

#to_rack_envObject



80
81
82
# File 'lib/webmachine/spec/test_resource.rb', line 80

def to_rack_env
  request.env.to_json
end

#to_request_uriObject



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

def to_request_uri
  request.uri.to_s
end

#to_stringObject



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

def to_string
  'String response body'
end