activeresource 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activeresource might be problematic. Click here for more details.
- data/CHANGELOG +7 -1
- data/lib/active_resource.rb +1 -0
- data/lib/active_resource/base.rb +2 -2
- data/lib/active_resource/http_mock.rb +75 -5
- data/lib/active_resource/version.rb +2 -2
- metadata +17 -8
data/CHANGELOG
CHANGED
data/lib/active_resource.rb
CHANGED
data/lib/active_resource/base.rb
CHANGED
@@ -589,8 +589,8 @@ module ActiveResource
|
|
589
589
|
def prefix(options={}) "#{prefix_call}" end
|
590
590
|
RUBY_EVAL
|
591
591
|
end
|
592
|
-
rescue
|
593
|
-
logger.error "Couldn't set prefix: #{
|
592
|
+
rescue Exception => e
|
593
|
+
logger.error "Couldn't set prefix: #{e}\n #{code}" if logger
|
594
594
|
raise
|
595
595
|
end
|
596
596
|
|
@@ -29,7 +29,8 @@ module ActiveResource
|
|
29
29
|
#
|
30
30
|
# In order for a mock to deliver its content, the incoming request must match by the <tt>http_method</tt>,
|
31
31
|
# +path+ and <tt>request_headers</tt>. If no match is found an InvalidRequestError exception
|
32
|
-
# will be raised
|
32
|
+
# will be raised showing you what request it could not find a response for and also what requests and response
|
33
|
+
# pairs have been recorded so you can create a new mock for that request.
|
33
34
|
#
|
34
35
|
# ==== Example
|
35
36
|
# def setup
|
@@ -97,10 +98,79 @@ module ActiveResource
|
|
97
98
|
@@responses ||= []
|
98
99
|
end
|
99
100
|
|
100
|
-
# Accepts a block which declares a set of requests and responses for the HttpMock to respond to
|
101
|
-
#
|
102
|
-
|
103
|
-
|
101
|
+
# Accepts a block which declares a set of requests and responses for the HttpMock to respond to in
|
102
|
+
# the following format:
|
103
|
+
#
|
104
|
+
# mock.http_method(path, request_headers = {}, body = nil, status = 200, response_headers = {})
|
105
|
+
#
|
106
|
+
# === Example
|
107
|
+
#
|
108
|
+
# @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
|
109
|
+
# ActiveResource::HttpMock.respond_to do |mock|
|
110
|
+
# mock.post "/people.xml", {}, @matz, 201, "Location" => "/people/1.xml"
|
111
|
+
# mock.get "/people/1.xml", {}, @matz
|
112
|
+
# mock.put "/people/1.xml", {}, nil, 204
|
113
|
+
# mock.delete "/people/1.xml", {}, nil, 200
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# Alternatively, accepts a hash of <tt>{Request => Response}</tt> pairs allowing you to generate
|
117
|
+
# these the following format:
|
118
|
+
#
|
119
|
+
# ActiveResource::Request.new(method, path, body, request_headers)
|
120
|
+
# ActiveResource::Response.new(body, status, response_headers)
|
121
|
+
#
|
122
|
+
# === Example
|
123
|
+
#
|
124
|
+
# Request.new(:#{method}, path, nil, request_headers)
|
125
|
+
#
|
126
|
+
# @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
|
127
|
+
#
|
128
|
+
# create_matz = ActiveResource::Request.new(:post, '/people.xml', @matz, {})
|
129
|
+
# created_response = ActiveResource::Response.new("", 201, {"Location" => "/people/1.xml"})
|
130
|
+
# get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
|
131
|
+
# ok_response = ActiveResource::Response.new("", 200, {})
|
132
|
+
#
|
133
|
+
# pairs = {create_matz => created_response, get_matz => ok_response}
|
134
|
+
#
|
135
|
+
# ActiveResource::HttpMock.respond_to(pairs)
|
136
|
+
#
|
137
|
+
# Note, by default, every time you call +respond_to+, any previous request and response pairs stored
|
138
|
+
# in HttpMock will be deleted giving you a clean slate to work on.
|
139
|
+
#
|
140
|
+
# If you want to override this behaviour, pass in +false+ as the last argument to +respond_to+
|
141
|
+
#
|
142
|
+
# === Example
|
143
|
+
#
|
144
|
+
# ActiveResource::HttpMock.respond_to do |mock|
|
145
|
+
# mock.send(:get, "/people/1", {}, "XML1")
|
146
|
+
# end
|
147
|
+
# ActiveResource::HttpMock.responses.length #=> 1
|
148
|
+
#
|
149
|
+
# ActiveResource::HttpMock.respond_to(false) do |mock|
|
150
|
+
# mock.send(:get, "/people/2", {}, "XML2")
|
151
|
+
# end
|
152
|
+
# ActiveResource::HttpMock.responses.length #=> 2
|
153
|
+
#
|
154
|
+
# This also works with passing in generated pairs of requests and responses, again, just pass in false
|
155
|
+
# as the last argument:
|
156
|
+
#
|
157
|
+
# === Example
|
158
|
+
#
|
159
|
+
# ActiveResource::HttpMock.respond_to do |mock|
|
160
|
+
# mock.send(:get, "/people/1", {}, "XML1")
|
161
|
+
# end
|
162
|
+
# ActiveResource::HttpMock.responses.length #=> 1
|
163
|
+
#
|
164
|
+
# get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
|
165
|
+
# ok_response = ActiveResource::Response.new("", 200, {})
|
166
|
+
#
|
167
|
+
# pairs = {get_matz => ok_response}
|
168
|
+
#
|
169
|
+
# ActiveResource::HttpMock.respond_to(pairs, false)
|
170
|
+
# ActiveResource::HttpMock.responses.length #=> 2
|
171
|
+
def respond_to(*args) #:yields: mock
|
172
|
+
pairs = args.first || {}
|
173
|
+
reset! if args.last.class != FalseClass
|
104
174
|
responses.concat pairs.to_a
|
105
175
|
if block_given?
|
106
176
|
yield Responder.new(responses)
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeresource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 3
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 3.0.
|
9
|
+
- 2
|
10
|
+
version: 3.0.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- David Heinemeier Hansson
|
@@ -14,35 +15,39 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-11-15 00:00:00 -06:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activesupport
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - "="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 3
|
29
32
|
- 0
|
30
|
-
-
|
31
|
-
version: 3.0.
|
33
|
+
- 2
|
34
|
+
version: 3.0.2
|
32
35
|
type: :runtime
|
33
36
|
version_requirements: *id001
|
34
37
|
- !ruby/object:Gem::Dependency
|
35
38
|
name: activemodel
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - "="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
41
46
|
segments:
|
42
47
|
- 3
|
43
48
|
- 0
|
44
|
-
-
|
45
|
-
version: 3.0.
|
49
|
+
- 2
|
50
|
+
version: 3.0.2
|
46
51
|
type: :runtime
|
47
52
|
version_requirements: *id002
|
48
53
|
description: REST on Rails. Wrap your RESTful web app with Ruby classes and work with them like Active Record models.
|
@@ -83,25 +88,29 @@ rdoc_options:
|
|
83
88
|
require_paths:
|
84
89
|
- lib
|
85
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
86
92
|
requirements:
|
87
93
|
- - ">="
|
88
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 57
|
89
96
|
segments:
|
90
97
|
- 1
|
91
98
|
- 8
|
92
99
|
- 7
|
93
100
|
version: 1.8.7
|
94
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
95
103
|
requirements:
|
96
104
|
- - ">="
|
97
105
|
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
98
107
|
segments:
|
99
108
|
- 0
|
100
109
|
version: "0"
|
101
110
|
requirements: []
|
102
111
|
|
103
112
|
rubyforge_project: activeresource
|
104
|
-
rubygems_version: 1.3.
|
113
|
+
rubygems_version: 1.3.7
|
105
114
|
signing_key:
|
106
115
|
specification_version: 3
|
107
116
|
summary: REST modeling framework (part of Rails).
|