openlogic-resourceful 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +45 -0
- data/MIT-LICENSE +21 -0
- data/Manifest +46 -0
- data/README.markdown +92 -0
- data/Rakefile +91 -0
- data/lib/resourceful.rb +27 -0
- data/lib/resourceful/abstract_form_data.rb +30 -0
- data/lib/resourceful/authentication_manager.rb +107 -0
- data/lib/resourceful/cache_manager.rb +242 -0
- data/lib/resourceful/exceptions.rb +34 -0
- data/lib/resourceful/header.rb +355 -0
- data/lib/resourceful/http_accessor.rb +103 -0
- data/lib/resourceful/memcache_cache_manager.rb +75 -0
- data/lib/resourceful/multipart_form_data.rb +46 -0
- data/lib/resourceful/net_http_adapter.rb +84 -0
- data/lib/resourceful/promiscuous_basic_authenticator.rb +18 -0
- data/lib/resourceful/request.rb +235 -0
- data/lib/resourceful/resource.rb +179 -0
- data/lib/resourceful/response.rb +221 -0
- data/lib/resourceful/simple.rb +36 -0
- data/lib/resourceful/stubbed_resource_proxy.rb +47 -0
- data/lib/resourceful/urlencoded_form_data.rb +19 -0
- data/lib/resourceful/util.rb +6 -0
- data/openlogic-resourceful.gemspec +51 -0
- data/resourceful.gemspec +51 -0
- data/spec/acceptance/authorization_spec.rb +16 -0
- data/spec/acceptance/caching_spec.rb +190 -0
- data/spec/acceptance/header_spec.rb +24 -0
- data/spec/acceptance/redirecting_spec.rb +12 -0
- data/spec/acceptance/resource_spec.rb +84 -0
- data/spec/acceptance/resourceful_spec.rb +56 -0
- data/spec/acceptance_shared_specs.rb +44 -0
- data/spec/caching_spec.rb +89 -0
- data/spec/old_acceptance_specs.rb +378 -0
- data/spec/resourceful/header_spec.rb +153 -0
- data/spec/resourceful/http_accessor_spec.rb +56 -0
- data/spec/resourceful/multipart_form_data_spec.rb +84 -0
- data/spec/resourceful/promiscuous_basic_authenticator_spec.rb +30 -0
- data/spec/resourceful/resource_spec.rb +20 -0
- data/spec/resourceful/response_spec.rb +51 -0
- data/spec/resourceful/urlencoded_form_data_spec.rb +64 -0
- data/spec/resourceful_spec.rb +79 -0
- data/spec/simple_sinatra_server.rb +74 -0
- data/spec/simple_sinatra_server_spec.rb +98 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +31 -0
- metadata +192 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'resourceful/abstract_form_data'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module Resourceful
|
5
|
+
class UrlencodedFormData < AbstractFormData
|
6
|
+
|
7
|
+
def content_type
|
8
|
+
"application/x-www-form-urlencoded"
|
9
|
+
end
|
10
|
+
|
11
|
+
# Read the form data encoded for putting on the wire.
|
12
|
+
def read
|
13
|
+
@form_data.map do |k,v|
|
14
|
+
CGI.escape(k) + '=' + CGI.escape(v)
|
15
|
+
end.join('&')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{openlogic-resourceful}
|
5
|
+
s.version = "1.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["OpenLogic"]
|
9
|
+
s.date = %q{2010-04-13}
|
10
|
+
s.description = %q{An HTTP library for Ruby that takes advantage of everything HTTP has to offer.}
|
11
|
+
s.email = %q{engteam@openlogic.com}
|
12
|
+
s.extra_rdoc_files = ["README.markdown", "lib/resourceful.rb", "lib/resourceful/abstract_form_data.rb", "lib/resourceful/authentication_manager.rb", "lib/resourceful/cache_manager.rb", "lib/resourceful/exceptions.rb", "lib/resourceful/header.rb", "lib/resourceful/http_accessor.rb", "lib/resourceful/memcache_cache_manager.rb", "lib/resourceful/multipart_form_data.rb", "lib/resourceful/net_http_adapter.rb", "lib/resourceful/promiscuous_basic_authenticator.rb", "lib/resourceful/request.rb", "lib/resourceful/resource.rb", "lib/resourceful/response.rb", "lib/resourceful/simple.rb", "lib/resourceful/stubbed_resource_proxy.rb", "lib/resourceful/urlencoded_form_data.rb", "lib/resourceful/util.rb"]
|
13
|
+
s.files = ["History.txt", "MIT-LICENSE", "Manifest", "README.markdown", "Rakefile", "lib/resourceful.rb", "lib/resourceful/abstract_form_data.rb", "lib/resourceful/authentication_manager.rb", "lib/resourceful/cache_manager.rb", "lib/resourceful/exceptions.rb", "lib/resourceful/header.rb", "lib/resourceful/http_accessor.rb", "lib/resourceful/memcache_cache_manager.rb", "lib/resourceful/multipart_form_data.rb", "lib/resourceful/net_http_adapter.rb", "lib/resourceful/promiscuous_basic_authenticator.rb", "lib/resourceful/request.rb", "lib/resourceful/resource.rb", "lib/resourceful/response.rb", "lib/resourceful/simple.rb", "lib/resourceful/stubbed_resource_proxy.rb", "lib/resourceful/urlencoded_form_data.rb", "lib/resourceful/util.rb", "openlogic-resourceful.gemspec", "resourceful.gemspec", "spec/acceptance/authorization_spec.rb", "spec/acceptance/caching_spec.rb", "spec/acceptance/header_spec.rb", "spec/acceptance/redirecting_spec.rb", "spec/acceptance/resource_spec.rb", "spec/acceptance/resourceful_spec.rb", "spec/acceptance_shared_specs.rb", "spec/caching_spec.rb", "spec/old_acceptance_specs.rb", "spec/resourceful/header_spec.rb", "spec/resourceful/http_accessor_spec.rb", "spec/resourceful/multipart_form_data_spec.rb", "spec/resourceful/promiscuous_basic_authenticator_spec.rb", "spec/resourceful/resource_spec.rb", "spec/resourceful/response_spec.rb", "spec/resourceful/urlencoded_form_data_spec.rb", "spec/resourceful_spec.rb", "spec/simple_sinatra_server.rb", "spec/simple_sinatra_server_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
|
14
|
+
s.homepage = %q{http://github.com/paul/resourceful}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Openlogic-resourceful", "--main", "README.markdown"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{openlogic-resourceful}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{An HTTP library for Ruby that takes advantage of everything HTTP has to offer.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.1.0"])
|
27
|
+
s.add_runtime_dependency(%q<httpauth>, [">= 0"])
|
28
|
+
s.add_runtime_dependency(%q<options>, [">= 2.1.1"])
|
29
|
+
s.add_development_dependency(%q<thin>, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
31
|
+
s.add_development_dependency(%q<sinatra>, [">= 0"])
|
32
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<addressable>, [">= 2.1.0"])
|
35
|
+
s.add_dependency(%q<httpauth>, [">= 0"])
|
36
|
+
s.add_dependency(%q<options>, [">= 2.1.1"])
|
37
|
+
s.add_dependency(%q<thin>, [">= 0"])
|
38
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
39
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
40
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
41
|
+
end
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<addressable>, [">= 2.1.0"])
|
44
|
+
s.add_dependency(%q<httpauth>, [">= 0"])
|
45
|
+
s.add_dependency(%q<options>, [">= 2.1.1"])
|
46
|
+
s.add_dependency(%q<thin>, [">= 0"])
|
47
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
48
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
49
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
50
|
+
end
|
51
|
+
end
|
data/resourceful.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{resourceful}
|
5
|
+
s.version = "1.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Paul Sadauskas"]
|
9
|
+
s.date = %q{2010-01-26}
|
10
|
+
s.description = %q{An HTTP library for Ruby that takes advantage of everything HTTP has to offer.}
|
11
|
+
s.email = %q{psadauskas@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.markdown", "lib/resourceful.rb", "lib/resourceful/abstract_form_data.rb", "lib/resourceful/authentication_manager.rb", "lib/resourceful/cache_manager.rb", "lib/resourceful/exceptions.rb", "lib/resourceful/header.rb", "lib/resourceful/http_accessor.rb", "lib/resourceful/memcache_cache_manager.rb", "lib/resourceful/multipart_form_data.rb", "lib/resourceful/net_http_adapter.rb", "lib/resourceful/request.rb", "lib/resourceful/resource.rb", "lib/resourceful/response.rb", "lib/resourceful/simple.rb", "lib/resourceful/stubbed_resource_proxy.rb", "lib/resourceful/urlencoded_form_data.rb", "lib/resourceful/util.rb"]
|
13
|
+
s.files = ["History.txt", "MIT-LICENSE", "Manifest", "README.markdown", "Rakefile", "lib/resourceful.rb", "lib/resourceful/abstract_form_data.rb", "lib/resourceful/authentication_manager.rb", "lib/resourceful/cache_manager.rb", "lib/resourceful/exceptions.rb", "lib/resourceful/header.rb", "lib/resourceful/http_accessor.rb", "lib/resourceful/memcache_cache_manager.rb", "lib/resourceful/multipart_form_data.rb", "lib/resourceful/net_http_adapter.rb", "lib/resourceful/request.rb", "lib/resourceful/resource.rb", "lib/resourceful/response.rb", "lib/resourceful/simple.rb", "lib/resourceful/stubbed_resource_proxy.rb", "lib/resourceful/urlencoded_form_data.rb", "lib/resourceful/util.rb", "resourceful.gemspec", "spec/acceptance/authorization_spec.rb", "spec/acceptance/caching_spec.rb", "spec/acceptance/header_spec.rb", "spec/acceptance/redirecting_spec.rb", "spec/acceptance/resource_spec.rb", "spec/acceptance/resourceful_spec.rb", "spec/acceptance_shared_specs.rb", "spec/caching_spec.rb", "spec/old_acceptance_specs.rb", "spec/resourceful/header_spec.rb", "spec/resourceful/http_accessor_spec.rb", "spec/resourceful/multipart_form_data_spec.rb", "spec/resourceful/resource_spec.rb", "spec/resourceful/response_spec.rb", "spec/resourceful/urlencoded_form_data_spec.rb", "spec/resourceful_spec.rb", "spec/simple_sinatra_server.rb", "spec/simple_sinatra_server_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
|
14
|
+
s.homepage = %q{http://github.com/paul/resourceful}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Resourceful", "--main", "README.markdown"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{resourceful}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{An HTTP library for Ruby that takes advantage of everything HTTP has to offer.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.1.0"])
|
27
|
+
s.add_runtime_dependency(%q<httpauth>, [">= 0"])
|
28
|
+
s.add_runtime_dependency(%q<options>, [">= 2.1.1"])
|
29
|
+
s.add_development_dependency(%q<thin>, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
31
|
+
s.add_development_dependency(%q<sinatra>, [">= 0"])
|
32
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<addressable>, [">= 2.1.0"])
|
35
|
+
s.add_dependency(%q<httpauth>, [">= 0"])
|
36
|
+
s.add_dependency(%q<options>, [">= 2.1.1"])
|
37
|
+
s.add_dependency(%q<thin>, [">= 0"])
|
38
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
39
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
40
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
41
|
+
end
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<addressable>, [">= 2.1.0"])
|
44
|
+
s.add_dependency(%q<httpauth>, [">= 0"])
|
45
|
+
s.add_dependency(%q<options>, [">= 2.1.1"])
|
46
|
+
s.add_dependency(%q<thin>, [">= 0"])
|
47
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
48
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
49
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
require 'resourceful'
|
4
|
+
require 'addressable/template'
|
5
|
+
|
6
|
+
describe Resourceful do
|
7
|
+
|
8
|
+
describe "caching" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
@http = Resourceful::HttpAccessor.new(:cache_manager => Resourceful::InMemoryCacheManager.new)
|
12
|
+
if ENV['SPEC_LOGGING']
|
13
|
+
@http.logger = Resourceful::StdOutLogger.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_with_errors(resource)
|
18
|
+
begin
|
19
|
+
resp = resource.get
|
20
|
+
rescue Resourceful::UnsuccessfulHttpRequestError => e
|
21
|
+
resp = e.http_response
|
22
|
+
end
|
23
|
+
resp
|
24
|
+
end
|
25
|
+
|
26
|
+
def uri_plus_params(uri, params = {})
|
27
|
+
uri = uri.is_a?(Addressable::URI) ? uri : Addressable::URI.parse(uri)
|
28
|
+
uri.query_values = params
|
29
|
+
uri
|
30
|
+
end
|
31
|
+
|
32
|
+
def uri_for_code(code, params = {})
|
33
|
+
uri = Addressable::Template.new("http://localhost:42682/code/{code}").expand("code" => code.to_s)
|
34
|
+
uri_plus_params(uri, params)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "response cacheability" do
|
38
|
+
Resourceful::Response::NORMALLY_CACHEABLE_RESPONSE_CODES.each do |code|
|
39
|
+
describe "response code #{code}" do
|
40
|
+
it "should normally be cached" do
|
41
|
+
resource = @http.resource(uri_for_code(code))
|
42
|
+
|
43
|
+
resp = get_with_errors(resource)
|
44
|
+
resp.should be_cacheable
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not be cached if Vary: *" do
|
48
|
+
resource = @http.resource(uri_for_code(200, "Vary" => "*"))
|
49
|
+
|
50
|
+
resp = get_with_errors(resource)
|
51
|
+
resp.should_not be_cacheable
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not be cached if Cache-Control: no-cache'" do
|
55
|
+
resource = @http.resource(uri_for_code(200, "Cache-Control" => "no-cache"))
|
56
|
+
|
57
|
+
resp = get_with_errors(resource)
|
58
|
+
resp.should_not be_cacheable
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# I would prefer to do all other codes, but some of them do some magic stuff (100),
|
64
|
+
# so I'll just spot check.
|
65
|
+
[201, 206, 302, 307, 404, 500].each do |code|
|
66
|
+
describe "response code #{code}" do
|
67
|
+
it "should not normally be cached" do
|
68
|
+
resource = @http.resource(uri_for_code(code))
|
69
|
+
|
70
|
+
resp = get_with_errors(resource)
|
71
|
+
resp.should_not be_cacheable
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should be cached if Cache-Control: public" do
|
75
|
+
resource = @http.resource(uri_for_code(code, "Cache-Control" => "public"))
|
76
|
+
|
77
|
+
resp = get_with_errors(resource)
|
78
|
+
resp.should be_cacheable
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should be cached if Cache-Control: private" do
|
82
|
+
resource = @http.resource(uri_for_code(code, "Cache-Control" => "private"))
|
83
|
+
|
84
|
+
resp = get_with_errors(resource)
|
85
|
+
resp.should be_cacheable
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "expiration" do
|
93
|
+
it 'should use the cached response if Expire: is in the future' do
|
94
|
+
in_the_future = (Time.now + 60).httpdate
|
95
|
+
resource = @http.resource(uri_for_code(200, "Expire" => in_the_future))
|
96
|
+
|
97
|
+
resp = resource.get
|
98
|
+
resp.should_not be_expired
|
99
|
+
|
100
|
+
resp = resource.get
|
101
|
+
resp.should be_ok
|
102
|
+
resp.should_not be_authoritative
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should revalidate the cached response if the response is expired' do
|
106
|
+
in_the_past = (Time.now - 60).httpdate
|
107
|
+
resource = @http.resource(uri_for_code(200, "Expires" => in_the_past))
|
108
|
+
|
109
|
+
resp = resource.get
|
110
|
+
resp.should be_expired
|
111
|
+
|
112
|
+
resp = resource.get
|
113
|
+
resp.should be_ok
|
114
|
+
resp.should be_authoritative
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'authoritative' do
|
119
|
+
|
120
|
+
it "should be authoritative if the response is directly from the server" do
|
121
|
+
resource = @http.resource(
|
122
|
+
uri_plus_params('http://localhost:42682/', "Cache-Control" => 'max-age=10')
|
123
|
+
)
|
124
|
+
|
125
|
+
response = resource.get
|
126
|
+
response.should be_authoritative
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should be authoritative if a cached response was revalidated with the server" do
|
130
|
+
now = Time.now.httpdate
|
131
|
+
resource = @http.resource(
|
132
|
+
uri_plus_params('http://localhost:42682/cached',
|
133
|
+
"modified" => now,
|
134
|
+
"Cache-Control" => 'max-age=0')
|
135
|
+
)
|
136
|
+
|
137
|
+
resource.get
|
138
|
+
response = resource.get("Cache-Control" => "max-age=0")
|
139
|
+
response.should be_authoritative
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should not be authoritative if the cached response was not revalidated" do
|
143
|
+
now = Time.now.httpdate
|
144
|
+
resource = @http.resource(
|
145
|
+
uri_plus_params('http://localhost:42682/cached',
|
146
|
+
"modified" => now,
|
147
|
+
"Cache-Control" => 'max-age=10')
|
148
|
+
)
|
149
|
+
|
150
|
+
resource.get
|
151
|
+
response = resource.get
|
152
|
+
response.should_not be_authoritative
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "Not Modified responses" do
|
159
|
+
before do
|
160
|
+
now = Time.now.httpdate
|
161
|
+
|
162
|
+
resource = @http.resource(
|
163
|
+
uri_plus_params('http://localhost:42682/cached',
|
164
|
+
"modified" => now,
|
165
|
+
"Cache-Control" => 'max-age=0')
|
166
|
+
)
|
167
|
+
|
168
|
+
@first_response = resource.get
|
169
|
+
@second_response = resource.get("Cache-Control" => "max-age=0") # Force revalidation
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should replace the 304 response with whats in the cache" do
|
173
|
+
@second_response.code.should == @first_response.code
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should provide a body identical to the original response" do
|
177
|
+
@second_response.body.should == @first_response.body
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should override any cached headers with new ones"
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "cache invalidation" do
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'resourceful'
|
3
|
+
|
4
|
+
describe Resourceful do
|
5
|
+
|
6
|
+
describe 'setting headers' do
|
7
|
+
before do
|
8
|
+
@http = Resourceful::HttpAccessor.new
|
9
|
+
@resource = @http.resource("http://localhost:42682/header")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should handle "Content-Type"' do
|
13
|
+
resp = @resource.post("asdf", :content_type => 'foo/bar')
|
14
|
+
|
15
|
+
header = YAML.load(resp.body)
|
16
|
+
|
17
|
+
header.should have_key('CONTENT_TYPE')
|
18
|
+
header['CONTENT_TYPE'].should == 'foo/bar'
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
require 'resourceful'
|
4
|
+
|
5
|
+
describe Resourceful do
|
6
|
+
|
7
|
+
describe "working with a resource" do
|
8
|
+
before do
|
9
|
+
@http = Resourceful::HttpAccessor.new
|
10
|
+
@resource = @http.resource('http://localhost:42682/')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should make the original uri available' do
|
14
|
+
@resource.effective_uri.should == 'http://localhost:42682/'
|
15
|
+
@resource.uri.should == 'http://localhost:42682/'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should set the user agent string on the default header' do
|
19
|
+
@resource.default_header.should have_key('User-Agent')
|
20
|
+
@resource.default_header['User-Agent'].should == Resourceful::RESOURCEFUL_USER_AGENT_TOKEN
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "GET" do
|
24
|
+
|
25
|
+
it "should be performable on a resource and return a response" do
|
26
|
+
response = @resource.get
|
27
|
+
response.should be_kind_of(Resourceful::Response)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "POST" do
|
33
|
+
|
34
|
+
it "should be performable on a resource and return a response" do
|
35
|
+
response = @resource.post
|
36
|
+
response.should be_kind_of(Resourceful::Response)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should require Content-Type be set if a body is provided" do
|
40
|
+
lambda {
|
41
|
+
@resource.post("some text")
|
42
|
+
}.should raise_error(Resourceful::MissingContentType)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "PUT" do
|
48
|
+
|
49
|
+
it "should be performable on a resource and return a response" do
|
50
|
+
response = @resource.put(nil)
|
51
|
+
response.should be_kind_of(Resourceful::Response)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should require Content-Type be set if a body is provided" do
|
55
|
+
lambda {
|
56
|
+
@resource.put("some text")
|
57
|
+
}.should raise_error(Resourceful::MissingContentType)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should require an entity-body to be set" do
|
61
|
+
lambda {
|
62
|
+
@resource.put()
|
63
|
+
}.should raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should allow the entity-body to be nil" do
|
67
|
+
lambda {
|
68
|
+
@resource.put(nil)
|
69
|
+
}.should_not raise_error(ArgumentError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "DELETE" do
|
74
|
+
|
75
|
+
it "should be performable on a resource and return a response" do
|
76
|
+
response = @resource.delete
|
77
|
+
response.should be_kind_of(Resourceful::Response)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|