activeresource 3.0.0.rc → 3.0.0.rc2

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 CHANGED
@@ -1,3 +1,8 @@
1
+ *Rails 3.0.0 [release candidate 2] (August 23rd, 2010)*
2
+
3
+ * No material changes (see http://github.com/rails/rails/compare/v3.0.0_RC...v3.0.0_RC2 for gory details)
4
+
5
+
1
6
  *Rails 3.0.0 [release candidate] (July 26th, 2010)*
2
7
 
3
8
  * No material changes
@@ -87,7 +92,7 @@
87
92
  ActiveResource::HttpMock.respond_to do |mock|
88
93
  mock.get "/people/1.xml", {}, "<person><name>David</name></person>"
89
94
  end
90
-
95
+
91
96
  Now:
92
97
  ActiveResource::HttpMock.respond_to.get "/people/1.xml", {}, "<person><name>David</name></person>"
93
98
 
@@ -97,14 +102,14 @@
97
102
  self.site = "http://app/"
98
103
  self.format = :json
99
104
  end
100
-
105
+
101
106
  person = Person.find(1) # => GET http://app/people/1.json
102
107
  person.name = "David"
103
108
  person.save # => PUT http://app/people/1.json {name: "David"}
104
-
109
+
105
110
  Person.format = :xml
106
111
  person.name = "Mary"
107
- person.save # => PUT http://app/people/1.json <person><name>Mary</name></person>
112
+ person.save # => PUT http://app/people/1.json <person><name>Mary</name></person>
108
113
 
109
114
  * Fix reload error when path prefix is used. #8727 [Ian Warshak]
110
115
 
@@ -133,7 +138,7 @@
133
138
  class Project
134
139
  headers['X-Token'] = 'foo'
135
140
  end
136
-
141
+
137
142
  # makes the GET request with the custom X-Token header
138
143
  Project.find(:all)
139
144
 
@@ -156,7 +161,7 @@
156
161
  end
157
162
 
158
163
  assert_kind_of Highrise::Comment, Note.find(1).comments.first
159
-
164
+
160
165
 
161
166
  * Added load_attributes_from_response as a way of loading attributes from other responses than just create [David Heinemeier Hansson]
162
167
 
@@ -248,8 +253,8 @@ d
248
253
 
249
254
  * Basic validation support [Rick Olson]
250
255
 
251
- Parses the xml response of ActiveRecord::Errors#to_xml with a similar interface to ActiveRecord::Errors.
252
-
256
+ Parses the xml response of ActiveRecord::Errors#to_xml with a similar interface to ActiveRecord::Errors.
257
+
253
258
  render :xml => @person.errors.to_xml, :status => '400 Validation Error'
254
259
 
255
260
  * Deep hashes are converted into collections of resources. [Jeremy Kemper]
@@ -267,12 +272,12 @@ d
267
272
  * Add support for specifying prefixes.
268
273
  * Allow overriding of element_name, collection_name, and primary key
269
274
  * Provide simpler HTTP mock interface for testing
270
-
275
+
271
276
  # rails routing code
272
277
  map.resources :posts do |post|
273
278
  post.resources :comments
274
279
  end
275
-
280
+
276
281
  # ActiveResources
277
282
  class Post < ActiveResource::Base
278
283
  self.site = "http://37s.sunrise.i:3000/"
@@ -281,7 +286,7 @@ d
281
286
  class Comment < ActiveResource::Base
282
287
  self.site = "http://37s.sunrise.i:3000/posts/:post_id/"
283
288
  end
284
-
289
+
285
290
  @post = Post.find 5
286
291
  @comments = Comment.find :all, :post_id => @post.id
287
292
 
data/README.rdoc CHANGED
@@ -9,7 +9,7 @@ in ActionController::Resources).
9
9
 
10
10
  Active Resource attempts to provide a coherent wrapper object-relational mapping for REST
11
11
  web services. It follows the same philosophy as Active Record, in that one of its prime aims
12
- is to reduce the amount of code needed to map to these resources. This is made possible
12
+ is to reduce the amount of code needed to map to these resources. This is made possible
13
13
  by relying on a number of code- and protocol-based conventions that make it easy for Active Resource
14
14
  to infer complex relations and structures. These conventions are outlined in detail in the documentation
15
15
  for ActiveResource::Base.
@@ -34,21 +34,21 @@ lifecycle methods that operate against a persistent store.
34
34
 
35
35
  # Find a person with id = 1
36
36
  ryan = Person.find(1)
37
- Person.exists?(1) #=> true
37
+ Person.exists?(1) # => true
38
38
 
39
39
  As you can see, the methods are quite similar to Active Record's methods for dealing with database
40
40
  records. But rather than dealing directly with a database record, you're dealing with HTTP resources (which may or may not be database records).
41
41
 
42
42
  ==== Protocol
43
43
 
44
- Active Resource is built on a standard XML format for requesting and submitting resources over HTTP. It mirrors the RESTful routing
44
+ Active Resource is built on a standard XML format for requesting and submitting resources over HTTP. It mirrors the RESTful routing
45
45
  built into Action Controller but will also work with any other REST service that properly implements the protocol.
46
46
  REST uses HTTP, but unlike "typical" web applications, it makes use of all the verbs available in the HTTP specification:
47
47
 
48
48
  * GET requests are used for finding and retrieving resources.
49
49
  * POST requests are used to create new resources.
50
50
  * PUT requests are used to update existing resources.
51
- * DELETE requests are used to delete resources.
51
+ * DELETE requests are used to delete resources.
52
52
 
53
53
  For more information on how this protocol works with Active Resource, see the ActiveResource::Base documentation;
54
54
  for more general information on REST web services, see the article here[http://en.wikipedia.org/wiki/Representational_State_Transfer].
@@ -69,8 +69,8 @@ for a request for a single element, the XML of that item is expected in response
69
69
  The XML document that is received is used to build a new object of type Person, with each
70
70
  XML element becoming an attribute on the object.
71
71
 
72
- ryan.is_a? Person #=> true
73
- ryan.attribute1 #=> 'value1'
72
+ ryan.is_a? Person # => true
73
+ ryan.attribute1 # => 'value1'
74
74
 
75
75
  Any complex element (one that contains other elements) becomes its own object:
76
76
 
@@ -81,8 +81,8 @@ Any complex element (one that contains other elements) becomes its own object:
81
81
  # for GET http://api.people.com:3000/people/1.xml
82
82
  #
83
83
  ryan = Person.find(1)
84
- ryan.complex #=> <Person::Complex::xxxxx>
85
- ryan.complex.attribute2 #=> 'value2'
84
+ ryan.complex # => <Person::Complex::xxxxx>
85
+ ryan.complex.attribute2 # => 'value2'
86
86
 
87
87
  Collections can also be requested in a similar fashion
88
88
 
@@ -96,8 +96,8 @@ Collections can also be requested in a similar fashion
96
96
  # for GET http://api.people.com:3000/people.xml
97
97
  #
98
98
  people = Person.find(:all)
99
- people.first #=> <Person::xxx 'first' => 'Ryan' ...>
100
- people.last #=> <Person::xxx 'first' => 'Jim' ...>
99
+ people.first # => <Person::xxx 'first' => 'Ryan' ...>
100
+ people.last # => <Person::xxx 'first' => 'Jim' ...>
101
101
 
102
102
  ==== Create
103
103
 
@@ -111,17 +111,17 @@ as the id of the ARes object.
111
111
  # is submitted as the body on
112
112
  #
113
113
  # POST http://api.people.com:3000/people.xml
114
- #
114
+ #
115
115
  # when save is called on a new Person object. An empty response is
116
116
  # is expected with a 'Location' header value:
117
117
  #
118
118
  # Response (201): Location: http://api.people.com:3000/people/2
119
119
  #
120
120
  ryan = Person.new(:first => 'Ryan')
121
- ryan.new? #=> true
122
- ryan.save #=> true
123
- ryan.new? #=> false
124
- ryan.id #=> 2
121
+ ryan.new? # => true
122
+ ryan.save # => true
123
+ ryan.new? # => false
124
+ ryan.id # => 2
125
125
 
126
126
  ==== Update
127
127
 
@@ -139,9 +139,9 @@ server side was successful.
139
139
  # is expected with code (204)
140
140
  #
141
141
  ryan = Person.find(1)
142
- ryan.first #=> 'Ryan'
142
+ ryan.first # => 'Ryan'
143
143
  ryan.first = 'Rizzle'
144
- ryan.save #=> true
144
+ ryan.save # => true
145
145
 
146
146
  ==== Delete
147
147
 
@@ -155,10 +155,10 @@ Destruction of a resource can be invoked as a class and instance method of the r
155
155
  # is expected with response code (200)
156
156
  #
157
157
  ryan = Person.find(1)
158
- ryan.destroy #=> true
159
- ryan.exists? #=> false
160
- Person.delete(2) #=> true
161
- Person.exists?(2) #=> false
158
+ ryan.destroy # => true
159
+ ryan.exists? # => false
160
+ Person.delete(2) # => true
161
+ Person.exists?(2) # => false
162
162
 
163
163
 
164
164
  You can find more usage information in the ActiveResource::Base documentation.
@@ -1222,10 +1222,10 @@ module ActiveResource
1222
1222
  when Array
1223
1223
  resource = find_or_create_resource_for_collection(key)
1224
1224
  value.map do |attrs|
1225
- if attrs.is_a?(String) || attrs.is_a?(Numeric)
1226
- attrs.duplicable? ? attrs.dup : attrs
1227
- else
1225
+ if attrs.is_a?(Hash)
1228
1226
  resource.new(attrs)
1227
+ else
1228
+ attrs.duplicable? ? attrs.dup : attrs
1229
1229
  end
1230
1230
  end
1231
1231
  when Hash
@@ -41,7 +41,7 @@ module ActiveResource
41
41
  # mock.delete "/people/1.xml", {}, nil, 200
42
42
  # end
43
43
  # end
44
- #
44
+ #
45
45
  # def test_get_matz
46
46
  # person = Person.find(1)
47
47
  # assert_equal "Matz", person.name
@@ -77,13 +77,13 @@ module ActiveResource
77
77
  # mock.get "/people/1.xml", {}, @matz
78
78
  # end
79
79
  # end
80
- #
80
+ #
81
81
  # def test_should_request_remote_service
82
82
  # person = Person.find(1) # Call the remote service
83
- #
83
+ #
84
84
  # # This request object has the same HTTP method and path as declared by the mock
85
85
  # expected_request = ActiveResource::Request.new(:get, "/people/1.xml")
86
- #
86
+ #
87
87
  # # Assert that the mock received, and responded to, the expected request from the model
88
88
  # assert ActiveResource::HttpMock.requests.include?(expected_request)
89
89
  # end
@@ -123,7 +123,11 @@ module ActiveResource
123
123
  # def post(path, body, headers)
124
124
  # request = ActiveResource::Request.new(:post, path, body, headers)
125
125
  # self.class.requests << request
126
- # self.class.responses.assoc(request).try(:second) || raise(InvalidRequestError.new("No response recorded for #{request}"))
126
+ # if response = self.class.responses.assoc(request)
127
+ # response[1]
128
+ # else
129
+ # raise InvalidRequestError.new("No response recorded for #{request}")
130
+ # end
127
131
  # end
128
132
  module_eval <<-EOE, __FILE__, __LINE__ + 1
129
133
  def #{method}(path, #{'body, ' if has_body}headers)
@@ -6,7 +6,7 @@ module ActiveResource
6
6
  end
7
7
 
8
8
  # Active Resource validation is reported to and from this object, which is used by Base#save
9
- # to determine whether the object in a valid state to be saved. See usage example in Validations.
9
+ # to determine whether the object in a valid state to be saved. See usage example in Validations.
10
10
  class Errors < ActiveModel::Errors
11
11
  # Grabs errors from an array of messages (like ActiveRecord::Validations)
12
12
  # The second parameter directs the errors cache to be cleared (default)
@@ -20,7 +20,7 @@ module ActiveResource
20
20
  add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
21
21
  end
22
22
  end
23
-
23
+
24
24
  self[:base] << message if attr_message.nil?
25
25
  end
26
26
  end
@@ -37,15 +37,15 @@ module ActiveResource
37
37
  from_array array, save_cache
38
38
  end
39
39
  end
40
-
40
+
41
41
  # Module to support validation and errors with Active Resource objects. The module overrides
42
- # Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned
43
- # in the web service response. The module also adds an +errors+ collection that mimics the interface
42
+ # Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned
43
+ # in the web service response. The module also adds an +errors+ collection that mimics the interface
44
44
  # of the errors provided by ActiveRecord::Errors.
45
45
  #
46
46
  # ==== Example
47
47
  #
48
- # Consider a Person resource on the server requiring both a +first_name+ and a +last_name+ with a
48
+ # Consider a Person resource on the server requiring both a +first_name+ and a +last_name+ with a
49
49
  # <tt>validates_presence_of :first_name, :last_name</tt> declaration in the model:
50
50
  #
51
51
  # person = Person.new(:first_name => "Jim", :last_name => "")
@@ -55,7 +55,7 @@ module ActiveResource
55
55
  # person.errors.count # => 1
56
56
  # person.errors.full_messages # => ["Last name can't be empty"]
57
57
  # person.errors[:last_name] # => ["can't be empty"]
58
- # person.last_name = "Halpert"
58
+ # person.last_name = "Halpert"
59
59
  # person.save # => true (and person is now saved to the remote service)
60
60
  #
61
61
  module Validations
@@ -118,7 +118,7 @@ module ActiveResource
118
118
  # also any errors returned from the remote system the last time we
119
119
  # saved.
120
120
  # Remote errors can only be cleared by trying to re-save the resource.
121
- #
121
+ #
122
122
  # ==== Examples
123
123
  # my_person = Person.create(params[:person])
124
124
  # my_person.valid?
@@ -3,7 +3,7 @@ module ActiveResource
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
5
  TINY = 0
6
- BUILD = "rc"
6
+ BUILD = "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeresource
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7712042
4
+ hash: 977940607
5
5
  prerelease: true
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
9
  - 0
10
- - rc
11
- version: 3.0.0.rc
10
+ - rc2
11
+ version: 3.0.0.rc2
12
12
  platform: ruby
13
13
  authors:
14
14
  - David Heinemeier Hansson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-26 00:00:00 -05:00
19
+ date: 2010-08-23 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -27,13 +27,13 @@ dependencies:
27
27
  requirements:
28
28
  - - "="
29
29
  - !ruby/object:Gem::Version
30
- hash: 7712042
30
+ hash: 977940607
31
31
  segments:
32
32
  - 3
33
33
  - 0
34
34
  - 0
35
- - rc
36
- version: 3.0.0.rc
35
+ - rc2
36
+ version: 3.0.0.rc2
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  - !ruby/object:Gem::Dependency
@@ -44,13 +44,13 @@ dependencies:
44
44
  requirements:
45
45
  - - "="
46
46
  - !ruby/object:Gem::Version
47
- hash: 7712042
47
+ hash: 977940607
48
48
  segments:
49
49
  - 3
50
50
  - 0
51
51
  - 0
52
- - rc
53
- version: 3.0.0.rc
52
+ - rc2
53
+ version: 3.0.0.rc2
54
54
  type: :runtime
55
55
  version_requirements: *id002
56
56
  description: REST on Rails. Wrap your RESTful web app with Ruby classes and work with them like Active Record models.