activeresource 3.1.0.beta1 → 3.1.0.rc1

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,15 +1,47 @@
1
1
  *Rails 3.1.0 (unreleased)*
2
2
 
3
- * No changes
3
+ * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set `self.format = :xml` in the class. eg.
4
+
5
+ class User < ActiveResource::Base
6
+ self.format = :xml
7
+ end
8
+
9
+
10
+ *Rails 3.0.7 (April 18, 2011)*
11
+
12
+ * No changes.
13
+
14
+
15
+ *Rails 3.0.6 (April 5, 2011)
16
+
17
+ * No changes.
18
+
19
+
20
+ *Rails 3.0.5 (February 26, 2011)*
4
21
 
5
- *Rails 3.0.2 (unreleased)*
22
+ * No changes.
23
+
24
+
25
+ *Rails 3.0.4 (February 8, 2011)*
26
+
27
+ * No changes.
28
+
29
+
30
+ *Rails 3.0.3 (November 16, 2010)*
31
+
32
+ * No changes.
33
+
34
+
35
+ *Rails 3.0.2 (November 15, 2010)*
6
36
 
7
37
  * No changes
8
38
 
39
+
9
40
  *Rails 3.0.1 (October 15, 2010)*
10
41
 
11
42
  * No Changes, just a version bump.
12
43
 
44
+
13
45
  *Rails 3.0.0 (August 29, 2010)*
14
46
 
15
47
  * JSON: set Base.include_root_in_json = true to include a root value in the JSON: {"post": {"title": ...}}. Mirrors the Active Record option. [Santiago Pastorino]
@@ -67,14 +99,14 @@
67
99
  * Ruby 1.9 compatibility. [Jeremy Kemper]
68
100
 
69
101
 
70
- *2.0.2* (December 16th, 2007)
102
+ *2.0.2 (December 16th, 2007)*
71
103
 
72
104
  * Added more specific exceptions for 400, 401, and 403 (all descending from ClientError so existing rescues will work) #10326 [trek]
73
105
 
74
106
  * Correct empty response handling. #10445 [seangeo]
75
107
 
76
108
 
77
- *2.0.1* (December 7th, 2007)
109
+ *2.0.1 (December 7th, 2007)*
78
110
 
79
111
  * Don't cache net/http object so that ActiveResource is more thread-safe. Closes #10142 [kou]
80
112
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2006 David Heinemeier Hansson
2
+ # Copyright (c) 2006-2011 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -3,7 +3,6 @@ require 'active_support/core_ext/class/attribute_accessors'
3
3
  require 'active_support/core_ext/class/attribute'
4
4
  require 'active_support/core_ext/hash/indifferent_access'
5
5
  require 'active_support/core_ext/kernel/reporting'
6
- require 'active_support/core_ext/module/attr_accessor_with_default'
7
6
  require 'active_support/core_ext/module/delegation'
8
7
  require 'active_support/core_ext/module/aliasing'
9
8
  require 'active_support/core_ext/object/blank'
@@ -81,19 +80,19 @@ module ActiveResource
81
80
  # <tt>post</tt>, <tt>put</tt> and <tt>\delete</tt> methods where you can specify a custom REST method
82
81
  # name to invoke.
83
82
  #
84
- # # POST to the custom 'register' REST method, i.e. POST /people/new/register.xml.
83
+ # # POST to the custom 'register' REST method, i.e. POST /people/new/register.json.
85
84
  # Person.new(:name => 'Ryan').post(:register)
86
85
  # # => { :id => 1, :name => 'Ryan', :position => 'Clerk' }
87
86
  #
88
- # # PUT an update by invoking the 'promote' REST method, i.e. PUT /people/1/promote.xml?position=Manager.
87
+ # # PUT an update by invoking the 'promote' REST method, i.e. PUT /people/1/promote.json?position=Manager.
89
88
  # Person.find(1).put(:promote, :position => 'Manager')
90
89
  # # => { :id => 1, :name => 'Ryan', :position => 'Manager' }
91
90
  #
92
- # # GET all the positions available, i.e. GET /people/positions.xml.
91
+ # # GET all the positions available, i.e. GET /people/positions.json.
93
92
  # Person.get(:positions)
94
93
  # # => [{:name => 'Manager'}, {:name => 'Clerk'}]
95
94
  #
96
- # # DELETE to 'fire' a person, i.e. DELETE /people/1/fire.xml.
95
+ # # DELETE to 'fire' a person, i.e. DELETE /people/1/fire.json.
97
96
  # Person.find(1).delete(:fire)
98
97
  #
99
98
  # For more information on using custom REST methods, see the
@@ -164,7 +163,7 @@ module ActiveResource
164
163
  # response code will be returned from the server which will raise an ActiveResource::ResourceNotFound
165
164
  # exception.
166
165
  #
167
- # # GET http://api.people.com:3000/people/999.xml
166
+ # # GET http://api.people.com:3000/people/999.json
168
167
  # ryan = Person.find(999) # 404, raises ActiveResource::ResourceNotFound
169
168
  #
170
169
  #
@@ -218,7 +217,7 @@ module ActiveResource
218
217
  # ryan.save # => false
219
218
  #
220
219
  # # When
221
- # # PUT http://api.people.com:3000/people/1.xml
220
+ # # PUT http://api.people.com:3000/people/1.json
222
221
  # # or
223
222
  # # PUT http://api.people.com:3000/people/1.json
224
223
  # # is requested with invalid values, the response is:
@@ -489,7 +488,7 @@ module ActiveResource
489
488
  # Person.format = ActiveResource::Formats::XmlFormat
490
489
  # Person.find(1) # => GET /people/1.xml
491
490
  #
492
- # Default format is <tt>:xml</tt>.
491
+ # Default format is <tt>:json</tt>.
493
492
  def format=(mime_type_reference_or_format)
494
493
  format = mime_type_reference_or_format.is_a?(Symbol) ?
495
494
  ActiveResource::Formats[mime_type_reference_or_format] : mime_type_reference_or_format
@@ -498,9 +497,9 @@ module ActiveResource
498
497
  connection.format = format if site
499
498
  end
500
499
 
501
- # Returns the current format, default is ActiveResource::Formats::XmlFormat.
500
+ # Returns the current format, default is ActiveResource::Formats::JsonFormat.
502
501
  def format
503
- self._format || ActiveResource::Formats::XmlFormat
502
+ self._format || ActiveResource::Formats::JsonFormat
504
503
  end
505
504
 
506
505
  # Sets the number of seconds after which requests to the REST API should time out.
@@ -565,12 +564,25 @@ module ActiveResource
565
564
  @headers ||= {}
566
565
  end
567
566
 
568
- attr_accessor_with_default(:element_name) { model_name.element } #:nodoc:
569
- attr_accessor_with_default(:collection_name) { ActiveSupport::Inflector.pluralize(element_name) } #:nodoc:
567
+ attr_writer :element_name
568
+
569
+ def element_name
570
+ @element_name ||= model_name.element
571
+ end
572
+
573
+ attr_writer :collection_name
574
+
575
+ def collection_name
576
+ @collection_name ||= ActiveSupport::Inflector.pluralize(element_name)
577
+ end
578
+
579
+ attr_writer :primary_key
570
580
 
571
- attr_accessor_with_default(:primary_key, 'id') #:nodoc:
581
+ def primary_key
582
+ @primary_key ||= 'id'
583
+ end
572
584
 
573
- # Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>)
585
+ # Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>)
574
586
  # This method is regenerated at runtime based on what the \prefix is set to.
575
587
  def prefix(options={})
576
588
  default = site.path
@@ -587,7 +599,7 @@ module ActiveResource
587
599
  prefix_source
588
600
  end
589
601
 
590
- # Sets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>).
602
+ # Sets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>).
591
603
  # Default value is <tt>site.path</tt>.
592
604
  def prefix=(value = '/')
593
605
  # Replace :placeholders with '#{embedded options[:lookups]}'
@@ -618,21 +630,21 @@ module ActiveResource
618
630
  #
619
631
  # ==== Options
620
632
  # +prefix_options+ - A \hash to add a \prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
621
- # would yield a URL like <tt>/accounts/19/purchases.xml</tt>).
633
+ # would yield a URL like <tt>/accounts/19/purchases.json</tt>).
622
634
  # +query_options+ - A \hash to add items to the query string for the request.
623
635
  #
624
636
  # ==== Examples
625
637
  # Post.element_path(1)
626
- # # => /posts/1.xml
638
+ # # => /posts/1.json
627
639
  #
628
640
  # Comment.element_path(1, :post_id => 5)
629
- # # => /posts/5/comments/1.xml
641
+ # # => /posts/5/comments/1.json
630
642
  #
631
643
  # Comment.element_path(1, :post_id => 5, :active => 1)
632
- # # => /posts/5/comments/1.xml?active=1
644
+ # # => /posts/5/comments/1.json?active=1
633
645
  #
634
646
  # Comment.element_path(1, {:post_id => 5}, {:active => 1})
635
- # # => /posts/5/comments/1.xml?active=1
647
+ # # => /posts/5/comments/1.json?active=1
636
648
  #
637
649
  def element_path(id, prefix_options = {}, query_options = nil)
638
650
  check_prefix_options(prefix_options)
@@ -645,14 +657,14 @@ module ActiveResource
645
657
  #
646
658
  # ==== Options
647
659
  # * +prefix_options+ - A hash to add a prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
648
- # would yield a URL like <tt>/accounts/19/purchases/new.xml</tt>).
660
+ # would yield a URL like <tt>/accounts/19/purchases/new.json</tt>).
649
661
  #
650
662
  # ==== Examples
651
663
  # Post.new_element_path
652
- # # => /posts/new.xml
664
+ # # => /posts/new.json
653
665
  #
654
666
  # Comment.collection_path(:post_id => 5)
655
- # # => /posts/5/comments/new.xml
667
+ # # => /posts/5/comments/new.json
656
668
  def new_element_path(prefix_options = {})
657
669
  "#{prefix(prefix_options)}#{collection_name}/new.#{format.extension}"
658
670
  end
@@ -662,21 +674,21 @@ module ActiveResource
662
674
  #
663
675
  # ==== Options
664
676
  # * +prefix_options+ - A hash to add a prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
665
- # would yield a URL like <tt>/accounts/19/purchases.xml</tt>).
677
+ # would yield a URL like <tt>/accounts/19/purchases.json</tt>).
666
678
  # * +query_options+ - A hash to add items to the query string for the request.
667
679
  #
668
680
  # ==== Examples
669
681
  # Post.collection_path
670
- # # => /posts.xml
682
+ # # => /posts.json
671
683
  #
672
684
  # Comment.collection_path(:post_id => 5)
673
- # # => /posts/5/comments.xml
685
+ # # => /posts/5/comments.json
674
686
  #
675
687
  # Comment.collection_path(:post_id => 5, :active => 1)
676
- # # => /posts/5/comments.xml?active=1
688
+ # # => /posts/5/comments.json?active=1
677
689
  #
678
690
  # Comment.collection_path({:post_id => 5}, {:active => 1})
679
- # # => /posts/5/comments.xml?active=1
691
+ # # => /posts/5/comments.json?active=1
680
692
  #
681
693
  def collection_path(prefix_options = {}, query_options = nil)
682
694
  check_prefix_options(prefix_options)
@@ -745,34 +757,34 @@ module ActiveResource
745
757
  #
746
758
  # ==== Examples
747
759
  # Person.find(1)
748
- # # => GET /people/1.xml
760
+ # # => GET /people/1.json
749
761
  #
750
762
  # Person.find(:all)
751
- # # => GET /people.xml
763
+ # # => GET /people.json
752
764
  #
753
765
  # Person.find(:all, :params => { :title => "CEO" })
754
- # # => GET /people.xml?title=CEO
766
+ # # => GET /people.json?title=CEO
755
767
  #
756
768
  # Person.find(:first, :from => :managers)
757
- # # => GET /people/managers.xml
769
+ # # => GET /people/managers.json
758
770
  #
759
771
  # Person.find(:last, :from => :managers)
760
- # # => GET /people/managers.xml
772
+ # # => GET /people/managers.json
761
773
  #
762
- # Person.find(:all, :from => "/companies/1/people.xml")
763
- # # => GET /companies/1/people.xml
774
+ # Person.find(:all, :from => "/companies/1/people.json")
775
+ # # => GET /companies/1/people.json
764
776
  #
765
777
  # Person.find(:one, :from => :leader)
766
- # # => GET /people/leader.xml
778
+ # # => GET /people/leader.json
767
779
  #
768
780
  # Person.find(:all, :from => :developers, :params => { :language => 'ruby' })
769
- # # => GET /people/developers.xml?language=ruby
781
+ # # => GET /people/developers.json?language=ruby
770
782
  #
771
- # Person.find(:one, :from => "/companies/1/manager.xml")
772
- # # => GET /companies/1/manager.xml
783
+ # Person.find(:one, :from => "/companies/1/manager.json")
784
+ # # => GET /companies/1/manager.json
773
785
  #
774
786
  # StreetAddress.find(1, :params => { :person_id => 1 })
775
- # # => GET /people/1/street_addresses/1.xml
787
+ # # => GET /people/1/street_addresses/1.json
776
788
  #
777
789
  # == Failure or missing data
778
790
  # A failure to find the requested object raises a ResourceNotFound
@@ -833,7 +845,7 @@ module ActiveResource
833
845
  # my_event = Event.find(:first) # let's assume this is event with ID 7
834
846
  # Event.delete(my_event.id) # sends DELETE /events/7
835
847
  #
836
- # # Let's assume a request to events/5/cancel.xml
848
+ # # Let's assume a request to events/5/cancel.json
837
849
  # Event.delete(params[:id]) # sends DELETE /events/5
838
850
  def delete(id, options = {})
839
851
  connection.delete(element_path(id, options))
@@ -1121,7 +1133,7 @@ module ActiveResource
1121
1133
 
1122
1134
  # Saves (+POST+) or \updates (+PUT+) a resource. Delegates to +create+ if the object is \new,
1123
1135
  # +update+ if it exists. If the response to the \save includes a body, it will be assumed that this body
1124
- # is XML for the final object as it looked after the \save (which would include attributes like +created_at+
1136
+ # is Json for the final object as it looked after the \save (which would include attributes like +created_at+
1125
1137
  # that weren't part of the original submit).
1126
1138
  #
1127
1139
  # ==== Examples
@@ -1232,9 +1244,16 @@ module ActiveResource
1232
1244
  # your_supplier = Supplier.new
1233
1245
  # your_supplier.load(my_attrs)
1234
1246
  # your_supplier.save
1235
- def load(attributes)
1247
+ def load(attributes, remove_root = false)
1236
1248
  raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
1237
1249
  @prefix_options, attributes = split_options(attributes)
1250
+
1251
+ if attributes.keys.size == 1
1252
+ remove_root = self.class.element_name == attributes.keys.first.to_s
1253
+ end
1254
+
1255
+ attributes = Formats.remove_root(attributes) if remove_root
1256
+
1238
1257
  attributes.each do |key, value|
1239
1258
  @attributes[key.to_s] =
1240
1259
  case value
@@ -1285,7 +1304,7 @@ module ActiveResource
1285
1304
  # resource's attributes, the full body of the request will still be sent
1286
1305
  # in the save request to the remote service.
1287
1306
  def update_attributes(attributes)
1288
- load(attributes) && save
1307
+ load(attributes, false) && save
1289
1308
  end
1290
1309
 
1291
1310
  # For checking <tt>respond_to?</tt> without searching the attributes (which is faster).
@@ -1339,7 +1358,7 @@ module ActiveResource
1339
1358
 
1340
1359
  def load_attributes_from_response(response)
1341
1360
  if !response['Content-Length'].blank? && response['Content-Length'] != "0" && !response.body.nil? && response.body.strip.size > 0
1342
- load(self.class.format.decode(response.body))
1361
+ load(self.class.format.decode(response.body), true)
1343
1362
  @persisted = true
1344
1363
  end
1345
1364
  end
@@ -30,7 +30,7 @@ module ActiveResource
30
30
 
31
31
  # The +site+ parameter is required and will set the +site+
32
32
  # attribute to the URI for the remote resource service.
33
- def initialize(site, format = ActiveResource::Formats::XmlFormat)
33
+ def initialize(site, format = ActiveResource::Formats::JsonFormat)
34
34
  raise ArgumentError, 'Missing site URI' unless site
35
35
  @user = @password = nil
36
36
  self.site = site
@@ -11,10 +11,10 @@ module ActiveResource
11
11
  #
12
12
  # This route set creates routes for the following HTTP requests:
13
13
  #
14
- # POST /people/new/register.xml # PeopleController.register
15
- # PUT /people/1/promote.xml # PeopleController.promote with :id => 1
16
- # DELETE /people/1/deactivate.xml # PeopleController.deactivate with :id => 1
17
- # GET /people/active.xml # PeopleController.active
14
+ # POST /people/new/register.json # PeopleController.register
15
+ # PUT /people/1/promote.json # PeopleController.promote with :id => 1
16
+ # DELETE /people/1/deactivate.json # PeopleController.deactivate with :id => 1
17
+ # GET /people/active.json # PeopleController.active
18
18
  #
19
19
  # Using this module, Active Resource can use these custom REST methods just like the
20
20
  # standard methods.
@@ -23,13 +23,13 @@ module ActiveResource
23
23
  # self.site = "http://37s.sunrise.i:3000"
24
24
  # end
25
25
  #
26
- # Person.new(:name => 'Ryan).post(:register) # POST /people/new/register.xml
26
+ # Person.new(:name => 'Ryan).post(:register) # POST /people/new/register.json
27
27
  # # => { :id => 1, :name => 'Ryan' }
28
28
  #
29
- # Person.find(1).put(:promote, :position => 'Manager') # PUT /people/1/promote.xml
30
- # Person.find(1).delete(:deactivate) # DELETE /people/1/deactivate.xml
29
+ # Person.find(1).put(:promote, :position => 'Manager') # PUT /people/1/promote.json
30
+ # Person.find(1).delete(:deactivate) # DELETE /people/1/deactivate.json
31
31
  #
32
- # Person.get(:active) # GET /people/active.xml
32
+ # Person.get(:active) # GET /people/active.json
33
33
  # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]
34
34
  #
35
35
  module CustomMethods
@@ -41,10 +41,10 @@ module ActiveResource
41
41
 
42
42
  # Invokes a GET to a given custom REST method. For example:
43
43
  #
44
- # Person.get(:active) # GET /people/active.xml
44
+ # Person.get(:active) # GET /people/active.json
45
45
  # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]
46
46
  #
47
- # Person.get(:active, :awesome => true) # GET /people/active.xml?awesome=true
47
+ # Person.get(:active, :awesome => true) # GET /people/active.json?awesome=true
48
48
  # # => [{:id => 1, :name => 'Ryan'}]
49
49
  #
50
50
  # Note: the objects returned from this method are not automatically converted
@@ -54,7 +54,9 @@ module ActiveResource
54
54
  #
55
55
  # Person.find(:all, :from => :active)
56
56
  def get(custom_method_name, options = {})
57
- format.decode(connection.get(custom_method_collection_url(custom_method_name, options), headers).body)
57
+ hashified = format.decode(connection.get(custom_method_collection_url(custom_method_name, options), headers).body)
58
+ derooted = Formats.remove_root(hashified)
59
+ derooted.is_a?(Array) ? derooted.map { |e| Formats.remove_root(e) } : derooted
58
60
  end
59
61
 
60
62
  def post(custom_method_name, options = {}, body = '')
@@ -10,5 +10,13 @@ module ActiveResource
10
10
  def self.[](mime_type_reference)
11
11
  ActiveResource::Formats.const_get(ActiveSupport::Inflector.camelize(mime_type_reference.to_s) + "Format")
12
12
  end
13
+
14
+ def self.remove_root(data)
15
+ if data.is_a?(Hash) && data.keys.size == 1
16
+ data.values.first
17
+ else
18
+ data
19
+ end
20
+ end
13
21
  end
14
22
  end
@@ -18,7 +18,7 @@ module ActiveResource
18
18
  end
19
19
 
20
20
  def decode(json)
21
- ActiveSupport::JSON.decode(json)
21
+ Formats.remove_root(ActiveSupport::JSON.decode(json))
22
22
  end
23
23
  end
24
24
  end
@@ -18,19 +18,8 @@ module ActiveResource
18
18
  end
19
19
 
20
20
  def decode(xml)
21
- from_xml_data(Hash.from_xml(xml))
21
+ Formats.remove_root(Hash.from_xml(xml))
22
22
  end
23
-
24
- private
25
- # Manipulate from_xml Hash, because xml_simple is not exactly what we
26
- # want for Active Resource.
27
- def from_xml_data(data)
28
- if data.is_a?(Hash) && data.keys.size == 1
29
- data.values.first
30
- else
31
- data
32
- end
33
- end
34
23
  end
35
24
  end
36
25
  end
@@ -20,10 +20,10 @@ module ActiveResource
20
20
  # * <tt>path</tt> - A string, starting with a "/", defining the URI that is expected to be
21
21
  # called.
22
22
  # * <tt>request_headers</tt> - Headers that are expected along with the request. This argument uses a
23
- # hash format, such as <tt>{ "Content-Type" => "application/xml" }</tt>. This mock will only trigger
23
+ # hash format, such as <tt>{ "Content-Type" => "application/json" }</tt>. This mock will only trigger
24
24
  # if your tests sends a request with identical headers.
25
25
  # * <tt>body</tt> - The data to be returned. This should be a string of Active Resource parseable content,
26
- # such as XML.
26
+ # such as Json.
27
27
  # * <tt>status</tt> - The HTTP response code, as an integer, to return with the response.
28
28
  # * <tt>response_headers</tt> - Headers to be returned with the response. Uses the same hash format as
29
29
  # <tt>request_headers</tt> listed above.
@@ -35,12 +35,12 @@ module ActiveResource
35
35
  #
36
36
  # ==== Example
37
37
  # def setup
38
- # @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
38
+ # @matz = { :person => { :id => 1, :name => "Matz" } }.to_json
39
39
  # ActiveResource::HttpMock.respond_to do |mock|
40
- # mock.post "/people.xml", {}, @matz, 201, "Location" => "/people/1.xml"
41
- # mock.get "/people/1.xml", {}, @matz
42
- # mock.put "/people/1.xml", {}, nil, 204
43
- # mock.delete "/people/1.xml", {}, nil, 200
40
+ # mock.post "/people.json", {}, @matz, 201, "Location" => "/people/1.json"
41
+ # mock.get "/people/1.json", {}, @matz
42
+ # mock.put "/people/1.json", {}, nil, 204
43
+ # mock.delete "/people/1.json", {}, nil, 200
44
44
  # end
45
45
  # end
46
46
  #
@@ -85,9 +85,9 @@ module ActiveResource
85
85
  #
86
86
  # ==== Example
87
87
  # def setup
88
- # @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
88
+ # @matz = { :person => { :id => 1, :name => "Matz" } }.to_json
89
89
  # ActiveResource::HttpMock.respond_to do |mock|
90
- # mock.get "/people/1.xml", {}, @matz
90
+ # mock.get "/people/1.json", {}, @matz
91
91
  # end
92
92
  # end
93
93
  #
@@ -95,7 +95,7 @@ module ActiveResource
95
95
  # person = Person.find(1) # Call the remote service
96
96
  #
97
97
  # # This request object has the same HTTP method and path as declared by the mock
98
- # expected_request = ActiveResource::Request.new(:get, "/people/1.xml")
98
+ # expected_request = ActiveResource::Request.new(:get, "/people/1.json")
99
99
  #
100
100
  # # Assert that the mock received, and responded to, the expected request from the model
101
101
  # assert ActiveResource::HttpMock.requests.include?(expected_request)
@@ -117,12 +117,12 @@ module ActiveResource
117
117
  #
118
118
  # === Example
119
119
  #
120
- # @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
120
+ # @matz = { :person => { :id => 1, :name => "Matz" } }.to_json
121
121
  # ActiveResource::HttpMock.respond_to do |mock|
122
- # mock.post "/people.xml", {}, @matz, 201, "Location" => "/people/1.xml"
123
- # mock.get "/people/1.xml", {}, @matz
124
- # mock.put "/people/1.xml", {}, nil, 204
125
- # mock.delete "/people/1.xml", {}, nil, 200
122
+ # mock.post "/people.json", {}, @matz, 201, "Location" => "/people/1.json"
123
+ # mock.get "/people/1.json", {}, @matz
124
+ # mock.put "/people/1.json", {}, nil, 204
125
+ # mock.delete "/people/1.json", {}, nil, 200
126
126
  # end
127
127
  #
128
128
  # Alternatively, accepts a hash of <tt>{Request => Response}</tt> pairs allowing you to generate
@@ -135,11 +135,11 @@ module ActiveResource
135
135
  #
136
136
  # Request.new(:#{method}, path, nil, request_headers)
137
137
  #
138
- # @matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
138
+ # @matz = { :person => { :id => 1, :name => "Matz" } }.to_json
139
139
  #
140
- # create_matz = ActiveResource::Request.new(:post, '/people.xml', @matz, {})
141
- # created_response = ActiveResource::Response.new("", 201, {"Location" => "/people/1.xml"})
142
- # get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
140
+ # create_matz = ActiveResource::Request.new(:post, '/people.json', @matz, {})
141
+ # created_response = ActiveResource::Response.new("", 201, {"Location" => "/people/1.json"})
142
+ # get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil)
143
143
  # ok_response = ActiveResource::Response.new("", 200, {})
144
144
  #
145
145
  # pairs = {create_matz => created_response, get_matz => ok_response}
@@ -154,12 +154,12 @@ module ActiveResource
154
154
  # === Example
155
155
  #
156
156
  # ActiveResource::HttpMock.respond_to do |mock|
157
- # mock.send(:get, "/people/1", {}, "XML1")
157
+ # mock.send(:get, "/people/1", {}, "JSON1")
158
158
  # end
159
159
  # ActiveResource::HttpMock.responses.length #=> 1
160
160
  #
161
161
  # ActiveResource::HttpMock.respond_to(false) do |mock|
162
- # mock.send(:get, "/people/2", {}, "XML2")
162
+ # mock.send(:get, "/people/2", {}, "JSON2")
163
163
  # end
164
164
  # ActiveResource::HttpMock.responses.length #=> 2
165
165
  #
@@ -169,11 +169,11 @@ module ActiveResource
169
169
  # === Example
170
170
  #
171
171
  # ActiveResource::HttpMock.respond_to do |mock|
172
- # mock.send(:get, "/people/1", {}, "XML1")
172
+ # mock.send(:get, "/people/1", {}, "JSON1")
173
173
  # end
174
174
  # ActiveResource::HttpMock.responses.length #=> 1
175
175
  #
176
- # get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil)
176
+ # get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil)
177
177
  # ok_response = ActiveResource::Response.new("", 200, {})
178
178
  #
179
179
  # pairs = {get_matz => ok_response}
@@ -3,7 +3,7 @@ module ActiveResource
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
5
  TINY = 0
6
- PRE = "beta1"
6
+ PRE = "rc1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: activeresource
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 3.1.0.beta1
5
+ version: 3.1.0.rc1
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Heinemeier Hansson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-04 00:00:00 -05:00
13
+ date: 2011-05-21 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - "="
23
23
  - !ruby/object:Gem::Version
24
- version: 3.1.0.beta1
24
+ version: 3.1.0.rc1
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 3.1.0.beta1
35
+ version: 3.1.0.rc1
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  description: REST on Rails. Wrap your RESTful web app with Ruby classes and work with them like Active Record models.
@@ -47,7 +47,6 @@ files:
47
47
  - CHANGELOG
48
48
  - README.rdoc
49
49
  - examples/performance.rb
50
- - examples/simple.rb
51
50
  - lib/active_resource/base.rb
52
51
  - lib/active_resource/connection.rb
53
52
  - lib/active_resource/custom_methods.rb
@@ -87,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
86
  version: 1.3.1
88
87
  requirements: []
89
88
 
90
- rubyforge_project: activeresource
89
+ rubyforge_project:
91
90
  rubygems_version: 1.6.2
92
91
  signing_key:
93
92
  specification_version: 3
data/examples/simple.rb DELETED
@@ -1,15 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
- require 'active_resource'
3
- require 'active_support/core_ext/hash/conversions'
4
-
5
- ActiveSupport::XmlMini.backend = ENV['XMLMINI'] || 'REXML'
6
- ActiveResource::HttpMock.respond_to do |mock|
7
- mock.get '/people/1.xml', {}, { :id => 1, :name => 'bob' }.to_xml(:root => 'person')
8
- end
9
-
10
- class Person < ActiveResource::Base
11
- self.site = 'http://localhost/'
12
- end
13
-
14
- bob = Person.find(1)
15
- puts bob.inspect