activeresource 2.1.0 → 2.1.1

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
+ *2.1.1 (September 4th, 2008)*
2
+
3
+ * Fixed Base#exists? to check status code as integer [#299 state:resolved] (Wes Oldenbeuving)
4
+
5
+
1
6
  *2.1.0 (May 31st, 2008)*
2
7
 
3
8
  * Fixed response logging to use length instead of the entire thing (seangeo) [#27]
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'rake/rdoctask'
5
5
  require 'rake/packagetask'
6
6
  require 'rake/gempackagetask'
7
7
  require 'rake/contrib/sshpublisher'
8
+ require 'rake/contrib/rubyforgepublisher'
8
9
 
9
10
  require File.join(File.dirname(__FILE__), 'lib', 'active_resource', 'version')
10
11
 
@@ -42,9 +43,10 @@ Rake::RDocTask.new { |rdoc|
42
43
  rdoc.title = "Active Resource -- Object-oriented REST services"
43
44
  rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
44
45
  rdoc.options << '--charset' << 'utf-8'
45
- rdoc.template = "#{ENV['template']}.rb" if ENV['template']
46
+ rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
46
47
  rdoc.rdoc_files.include('README', 'CHANGELOG')
47
48
  rdoc.rdoc_files.include('lib/**/*.rb')
49
+ rdoc.rdoc_files.exclude('lib/activeresource.rb')
48
50
  }
49
51
 
50
52
 
@@ -64,7 +66,7 @@ spec = Gem::Specification.new do |s|
64
66
  s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
65
67
  end
66
68
 
67
- s.add_dependency('activesupport', '= 2.1.0' + PKG_BUILD)
69
+ s.add_dependency('activesupport', '= 2.1.1' + PKG_BUILD)
68
70
 
69
71
  s.require_path = 'lib'
70
72
  s.autorequire = 'active_resource'
@@ -114,13 +116,13 @@ end
114
116
 
115
117
  desc "Publish the beta gem"
116
118
  task :pgem => [:package] do
117
- Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
118
- `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
119
+ Rake::SshFilePublisher.new("david@greed.loudthinking.com", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
120
+ `ssh david@greed.loudthinking.com '/u/sites/gems/gemupdate.sh'`
119
121
  end
120
122
 
121
123
  desc "Publish the API documentation"
122
124
  task :pdoc => [:rdoc] do
123
- Rake::SshDirPublisher.new("davidhh@wrath.rubyonrails.org", "public_html/ar", "doc").upload
125
+ Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/ar", "doc").upload
124
126
  end
125
127
 
126
128
  desc "Publish the release files to RubyForge."
@@ -356,6 +356,9 @@ module ActiveResource
356
356
  # Replace :placeholders with '#{embedded options[:lookups]}'
357
357
  prefix_call = value.gsub(/:\w+/) { |key| "\#{options[#{key}]}" }
358
358
 
359
+ # Clear prefix parameters in case they have been cached
360
+ @prefix_parameters = nil
361
+
359
362
  # Redefine the new methods.
360
363
  code = <<-end_code
361
364
  def prefix_source() "#{value}" end
@@ -538,7 +541,7 @@ module ActiveResource
538
541
  prefix_options, query_options = split_options(options[:params])
539
542
  path = element_path(id, prefix_options, query_options)
540
543
  response = connection.head(path, headers)
541
- response.code == 200
544
+ response.code.to_i == 200
542
545
  end
543
546
  # id && !find_single(id, options).nil?
544
547
  rescue ActiveResource::ResourceNotFound
@@ -840,8 +843,13 @@ module ActiveResource
840
843
  #
841
844
  # my_group.to_xml(:skip_instruct => true)
842
845
  # # => <subsidiary_group> [...] </subsidiary_group>
843
- def to_xml(options={})
844
- attributes.to_xml({:root => self.class.element_name}.merge(options))
846
+ def encode(options={})
847
+ case self.class.format
848
+ when ActiveResource::Formats[:xml]
849
+ self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options))
850
+ else
851
+ self.class.format.encode(attributes, options)
852
+ end
845
853
  end
846
854
 
847
855
  # A method to reload the attributes of this object from the remote web service.
@@ -926,14 +934,14 @@ module ActiveResource
926
934
 
927
935
  # Update the resource on the remote service.
928
936
  def update
929
- returning connection.put(element_path(prefix_options), to_xml, self.class.headers) do |response|
937
+ returning connection.put(element_path(prefix_options), encode, self.class.headers) do |response|
930
938
  load_attributes_from_response(response)
931
939
  end
932
940
  end
933
941
 
934
942
  # Create (i.e., save to the remote service) the new resource.
935
943
  def create
936
- returning connection.post(collection_path, to_xml, self.class.headers) do |response|
944
+ returning connection.post(collection_path, encode, self.class.headers) do |response|
937
945
  self.id = id_from_response(response)
938
946
  load_attributes_from_response(response)
939
947
  end
@@ -988,7 +996,11 @@ module ActiveResource
988
996
  self.class.const_get(resource_name)
989
997
  end
990
998
  rescue NameError
991
- resource = self.class.const_set(resource_name, Class.new(ActiveResource::Base))
999
+ if self.class.const_defined?(resource_name)
1000
+ resource = self.class.const_get(resource_name)
1001
+ else
1002
+ resource = self.class.const_set(resource_name, Class.new(ActiveResource::Base))
1003
+ end
992
1004
  resource.prefix = self.class.prefix
993
1005
  resource.site = self.class.site
994
1006
  resource
@@ -63,6 +63,13 @@ module ActiveResource
63
63
  # This class is used by ActiveResource::Base to interface with REST
64
64
  # services.
65
65
  class Connection
66
+
67
+ HTTP_FORMAT_HEADER_NAMES = { :get => 'Accept',
68
+ :put => 'Content-Type',
69
+ :post => 'Content-Type',
70
+ :delete => 'Accept'
71
+ }
72
+
66
73
  attr_reader :site, :user, :password, :timeout
67
74
  attr_accessor :format
68
75
 
@@ -106,25 +113,25 @@ module ActiveResource
106
113
  # Execute a GET request.
107
114
  # Used to get (find) resources.
108
115
  def get(path, headers = {})
109
- format.decode(request(:get, path, build_request_headers(headers)).body)
116
+ format.decode(request(:get, path, build_request_headers(headers, :get)).body)
110
117
  end
111
118
 
112
119
  # Execute a DELETE request (see HTTP protocol documentation if unfamiliar).
113
120
  # Used to delete resources.
114
121
  def delete(path, headers = {})
115
- request(:delete, path, build_request_headers(headers))
122
+ request(:delete, path, build_request_headers(headers, :delete))
116
123
  end
117
124
 
118
125
  # Execute a PUT request (see HTTP protocol documentation if unfamiliar).
119
126
  # Used to update resources.
120
127
  def put(path, body = '', headers = {})
121
- request(:put, path, body.to_s, build_request_headers(headers))
128
+ request(:put, path, body.to_s, build_request_headers(headers, :put))
122
129
  end
123
130
 
124
131
  # Execute a POST request.
125
132
  # Used to create new resources.
126
133
  def post(path, body = '', headers = {})
127
- request(:post, path, body.to_s, build_request_headers(headers))
134
+ request(:post, path, body.to_s, build_request_headers(headers, :post))
128
135
  end
129
136
 
130
137
  # Execute a HEAD request.
@@ -187,12 +194,12 @@ module ActiveResource
187
194
  end
188
195
 
189
196
  def default_header
190
- @default_header ||= { 'Content-Type' => format.mime_type }
197
+ @default_header ||= {}
191
198
  end
192
199
 
193
200
  # Builds headers for request to remote service.
194
- def build_request_headers(headers)
195
- authorization_header.update(default_header).update(headers)
201
+ def build_request_headers(headers, http_method=nil)
202
+ authorization_header.update(default_header).update(headers).update(http_format_header(http_method))
196
203
  end
197
204
 
198
205
  # Sets authorization header
@@ -200,6 +207,10 @@ module ActiveResource
200
207
  (@user || @password ? { 'Authorization' => 'Basic ' + ["#{@user}:#{ @password}"].pack('m').delete("\r\n") } : {})
201
208
  end
202
209
 
210
+ def http_format_header(http_method)
211
+ {HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type}
212
+ end
213
+
203
214
  def logger #:nodoc:
204
215
  ActiveResource::Base.logger
205
216
  end
@@ -30,7 +30,7 @@ module ActiveResource
30
30
  # Person.get(:active) # GET /people/active.xml
31
31
  # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]
32
32
  #
33
- module CustomMethods
33
+ module CustomMethods
34
34
  def self.included(base)
35
35
  base.class_eval do
36
36
  extend ActiveResource::CustomMethods::ClassMethods
@@ -83,24 +83,25 @@ module ActiveResource
83
83
  "#{prefix(prefix_options)}#{collection_name}/#{method_name}.#{format.extension}#{query_string(query_options)}"
84
84
  end
85
85
  end
86
-
86
+
87
87
  module InstanceMethods
88
88
  def get(method_name, options = {})
89
89
  connection.get(custom_method_element_url(method_name, options), self.class.headers)
90
90
  end
91
-
92
- def post(method_name, options = {}, body = '')
91
+
92
+ def post(method_name, options = {}, body = nil)
93
+ request_body = body.nil? ? encode : body
93
94
  if new?
94
- connection.post(custom_method_new_element_url(method_name, options), (body.nil? ? to_xml : body), self.class.headers)
95
+ connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers)
95
96
  else
96
- connection.post(custom_method_element_url(method_name, options), body, self.class.headers)
97
+ connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers)
97
98
  end
98
99
  end
99
-
100
+
100
101
  def put(method_name, options = {}, body = '')
101
102
  connection.put(custom_method_element_url(method_name, options), body, self.class.headers)
102
103
  end
103
-
104
+
104
105
  def delete(method_name, options = {})
105
106
  connection.delete(custom_method_element_url(method_name, options), self.class.headers)
106
107
  end
@@ -110,7 +111,7 @@ module ActiveResource
110
111
  def custom_method_element_url(method_name, options = {})
111
112
  "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.#{self.class.format.extension}#{self.class.send!(:query_string, options)}"
112
113
  end
113
-
114
+
114
115
  def custom_method_new_element_url(method_name, options = {})
115
116
  "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.#{self.class.format.extension}#{self.class.send!(:query_string, options)}"
116
117
  end
@@ -2,22 +2,22 @@ module ActiveResource
2
2
  module Formats
3
3
  module JsonFormat
4
4
  extend self
5
-
5
+
6
6
  def extension
7
7
  "json"
8
8
  end
9
-
9
+
10
10
  def mime_type
11
11
  "application/json"
12
12
  end
13
-
14
- def encode(hash)
13
+
14
+ def encode(hash, options={})
15
15
  hash.to_json
16
16
  end
17
-
17
+
18
18
  def decode(json)
19
19
  ActiveSupport::JSON.decode(json)
20
20
  end
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -2,23 +2,23 @@ module ActiveResource
2
2
  module Formats
3
3
  module XmlFormat
4
4
  extend self
5
-
5
+
6
6
  def extension
7
7
  "xml"
8
8
  end
9
-
9
+
10
10
  def mime_type
11
11
  "application/xml"
12
12
  end
13
-
14
- def encode(hash)
15
- hash.to_xml
13
+
14
+ def encode(hash, options={})
15
+ hash.to_xml(options)
16
16
  end
17
-
17
+
18
18
  def decode(xml)
19
19
  from_xml_data(Hash.from_xml(xml))
20
20
  end
21
-
21
+
22
22
  private
23
23
  # Manipulate from_xml Hash, because xml_simple is not exactly what we
24
24
  # want for Active Resource.
@@ -28,7 +28,7 @@ module ActiveResource
28
28
  else
29
29
  data
30
30
  end
31
- end
31
+ end
32
32
  end
33
33
  end
34
- end
34
+ end
@@ -146,7 +146,7 @@ module ActiveResource
146
146
  attr_accessor :path, :method, :body, :headers
147
147
 
148
148
  def initialize(method, path, body = nil, headers = {})
149
- @method, @path, @body, @headers = method, path, body, headers.reverse_merge('Content-Type' => 'application/xml')
149
+ @method, @path, @body, @headers = method, path, body, headers.merge(ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method] => 'application/xml')
150
150
  end
151
151
 
152
152
  def ==(other_request)
@@ -2,7 +2,7 @@ module ActiveResource
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -9,14 +9,18 @@ require 'setter_trap'
9
9
 
10
10
  ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log")
11
11
 
12
+ def uses_gem(gem_name, test_name, version = '> 0')
13
+ require 'rubygems'
14
+ gem gem_name.to_s, version
15
+ require gem_name.to_s
16
+ yield
17
+ rescue LoadError
18
+ $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
19
+ end
20
+
12
21
  # Wrap tests that use Mocha and skip if unavailable.
13
- def uses_mocha(test_name)
14
- unless Object.const_defined?(:Mocha)
15
- require 'mocha'
16
- require 'stubba'
22
+ unless defined? uses_mocha
23
+ def uses_mocha(test_name, &block)
24
+ uses_gem('mocha', test_name, '>= 0.5.5', &block)
17
25
  end
18
- yield
19
- rescue LoadError => load_error
20
- raise unless load_error.message =~ /mocha/i
21
- $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
22
- end
26
+ end
@@ -10,8 +10,7 @@ class CustomMethodsTest < Test::Unit::TestCase
10
10
  @ryan = { :name => 'Ryan' }.to_xml(:root => 'person')
11
11
  @addy = { :id => 1, :street => '12345 Street' }.to_xml(:root => 'address')
12
12
  @addy_deep = { :id => 1, :street => '12345 Street', :zip => "27519" }.to_xml(:root => 'address')
13
- @default_request_headers = { 'Content-Type' => 'application/xml' }
14
-
13
+
15
14
  ActiveResource::HttpMock.respond_to do |mock|
16
15
  mock.get "/people/1.xml", {}, @matz
17
16
  mock.get "/people/1/shallow.xml", {}, @matz
@@ -1,5 +1,6 @@
1
1
  require 'abstract_unit'
2
2
  require "fixtures/person"
3
+ require "fixtures/customer"
3
4
  require "fixtures/street_address"
4
5
  require "fixtures/beast"
5
6
 
@@ -15,6 +16,37 @@ class BaseTest < Test::Unit::TestCase
15
16
  @people_david = [{ :id => 2, :name => 'David' }].to_xml(:root => 'people')
16
17
  @addresses = [{ :id => 1, :street => '12345 Street' }].to_xml(:root => 'addresses')
17
18
 
19
+ # - deep nested resource -
20
+ # - Luis (Customer)
21
+ # - JK (Customer::Friend)
22
+ # - Mateo (Customer::Friend::Brother)
23
+ # - Edith (Customer::Friend::Brother::Child)
24
+ # - Martha (Customer::Friend::Brother::Child)
25
+ # - Felipe (Customer::Friend::Brother)
26
+ # - Bryan (Customer::Friend::Brother::Child)
27
+ # - Luke (Customer::Friend::Brother::Child)
28
+ # - Eduardo (Customer::Friend)
29
+ # - Sebas (Customer::Friend::Brother)
30
+ # - Andres (Customer::Friend::Brother::Child)
31
+ # - Jorge (Customer::Friend::Brother::Child)
32
+ # - Elsa (Customer::Friend::Brother)
33
+ # - Natacha (Customer::Friend::Brother::Child)
34
+ # - Milena (Customer::Friend::Brother)
35
+ #
36
+ @luis = {:id => 1, :name => 'Luis',
37
+ :friends => [{:name => 'JK',
38
+ :brothers => [{:name => 'Mateo',
39
+ :children => [{:name => 'Edith'},{:name => 'Martha'}]},
40
+ {:name => 'Felipe',
41
+ :children => [{:name => 'Bryan'},{:name => 'Luke'}]}]},
42
+ {:name => 'Eduardo',
43
+ :brothers => [{:name => 'Sebas',
44
+ :children => [{:name => 'Andres'},{:name => 'Jorge'}]},
45
+ {:name => 'Elsa',
46
+ :children => [{:name => 'Natacha'}]},
47
+ {:name => 'Milena',
48
+ :children => []}]}]}.to_xml(:root => 'customer')
49
+
18
50
  ActiveResource::HttpMock.respond_to do |mock|
19
51
  mock.get "/people/1.xml", {}, @matz
20
52
  mock.get "/people/2.xml", {}, @david
@@ -46,6 +78,8 @@ class BaseTest < Test::Unit::TestCase
46
78
  mock.head "/people/1/addresses/2.xml", {}, nil, 404
47
79
  mock.head "/people/2/addresses/1.xml", {}, nil, 404
48
80
  mock.head "/people/Greg/addresses/1.xml", {}, nil, 200
81
+ # customer
82
+ mock.get "/customers/1.xml", {}, @luis
49
83
  end
50
84
 
51
85
  Person.user = nil
@@ -450,7 +484,16 @@ class BaseTest < Test::Unit::TestCase
450
484
  assert_equal "the_prefixthe_param_value", person_class.prefix(:the_param => "the_param_value")
451
485
  end
452
486
  end
453
-
487
+
488
+ def test_set_prefix_twice_should_clear_params
489
+ SetterTrap.rollback_sets(Person) do |person_class|
490
+ person_class.prefix = "the_prefix/:the_param1"
491
+ assert_equal Set.new([:the_param1]), person_class.prefix_parameters
492
+ person_class.prefix = "the_prefix/:the_param2"
493
+ assert_equal Set.new([:the_param2]), person_class.prefix_parameters
494
+ end
495
+ end
496
+
454
497
  def test_set_prefix_with_default_value
455
498
  SetterTrap.rollback_sets(Person) do |person_class|
456
499
  person_class.set_prefix
@@ -776,7 +819,7 @@ class BaseTest < Test::Unit::TestCase
776
819
 
777
820
  def test_to_xml
778
821
  matz = Person.find(1)
779
- xml = matz.to_xml
822
+ xml = matz.encode
780
823
  assert xml.starts_with?('<?xml version="1.0" encoding="UTF-8"?>')
781
824
  assert xml.include?('<name>Matz</name>')
782
825
  assert xml.include?('<id type="integer">1</id>')
@@ -788,4 +831,18 @@ class BaseTest < Test::Unit::TestCase
788
831
  matz = Person.find(1)
789
832
  assert_equal '1', matz.to_param
790
833
  end
834
+
835
+ def test_parse_deep_nested_resources
836
+ luis = Customer.find(1)
837
+ assert_kind_of Customer, luis
838
+ luis.friends.each do |friend|
839
+ assert_kind_of Customer::Friend, friend
840
+ friend.brothers.each do |brother|
841
+ assert_kind_of Customer::Friend::Brother, brother
842
+ brother.children.each do |child|
843
+ assert_kind_of Customer::Friend::Brother::Child, child
844
+ end
845
+ end
846
+ end
847
+ end
791
848
  end
@@ -0,0 +1,3 @@
1
+ class Customer < ActiveResource::Base
2
+ self.site = "http://37s.sunrise.i:3000"
3
+ end
@@ -5,14 +5,22 @@ class FormatTest < Test::Unit::TestCase
5
5
  def setup
6
6
  @matz = { :id => 1, :name => 'Matz' }
7
7
  @david = { :id => 2, :name => 'David' }
8
-
8
+
9
9
  @programmers = [ @matz, @david ]
10
10
  end
11
-
11
+
12
+ def test_http_format_header_name
13
+ header_name = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:get]
14
+ assert_equal 'Accept', header_name
15
+
16
+ headers_names = [ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:put], ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:post]]
17
+ headers_names.each{|header_name| assert_equal 'Content-Type', header_name}
18
+ end
19
+
12
20
  def test_formats_on_single_element
13
21
  for format in [ :json, :xml ]
14
22
  using_format(Person, format) do
15
- ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {}, ActiveResource::Formats[format].encode(@david)
23
+ ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
16
24
  assert_equal @david[:name], Person.find(1).name
17
25
  end
18
26
  end
@@ -21,7 +29,7 @@ class FormatTest < Test::Unit::TestCase
21
29
  def test_formats_on_collection
22
30
  for format in [ :json, :xml ]
23
31
  using_format(Person, format) do
24
- ActiveResource::HttpMock.respond_to.get "/people.#{format}", {}, ActiveResource::Formats[format].encode(@programmers)
32
+ ActiveResource::HttpMock.respond_to.get "/people.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@programmers)
25
33
  remote_programmers = Person.find(:all)
26
34
  assert_equal 2, remote_programmers.size
27
35
  assert remote_programmers.select { |p| p.name == 'David' }
@@ -32,7 +40,7 @@ class FormatTest < Test::Unit::TestCase
32
40
  def test_formats_on_custom_collection_method
33
41
  for format in [ :json, :xml ]
34
42
  using_format(Person, format) do
35
- ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {}, ActiveResource::Formats[format].encode([@david])
43
+ ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode([@david])
36
44
  remote_programmers = Person.get(:retrieve, :name => 'David')
37
45
  assert_equal 1, remote_programmers.size
38
46
  assert_equal @david[:id], remote_programmers[0]['id']
@@ -40,13 +48,13 @@ class FormatTest < Test::Unit::TestCase
40
48
  end
41
49
  end
42
50
  end
43
-
51
+
44
52
  def test_formats_on_custom_element_method
45
53
  for format in [ :json, :xml ]
46
54
  using_format(Person, format) do
47
55
  ActiveResource::HttpMock.respond_to do |mock|
48
- mock.get "/people/2.#{format}", {}, ActiveResource::Formats[format].encode(@david)
49
- mock.get "/people/2/shallow.#{format}", {}, ActiveResource::Formats[format].encode(@david)
56
+ mock.get "/people/2.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
57
+ mock.get "/people/2/shallow.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
50
58
  end
51
59
  remote_programmer = Person.find(2).get(:shallow)
52
60
  assert_equal @david[:id], remote_programmer['id']
@@ -57,20 +65,24 @@ class FormatTest < Test::Unit::TestCase
57
65
  for format in [ :json, :xml ]
58
66
  ryan = ActiveResource::Formats[format].encode({ :name => 'Ryan' })
59
67
  using_format(Person, format) do
60
- ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", {}, ryan, 201, 'Location' => "/people/5.#{format}"
61
68
  remote_ryan = Person.new(:name => 'Ryan')
69
+ ActiveResource::HttpMock.respond_to.post "/people.#{format}", {'Content-Type' => ActiveResource::Formats[format].mime_type}, ryan, 201, {'Location' => "/people/5.#{format}"}
70
+ remote_ryan.save
71
+
72
+ remote_ryan = Person.new(:name => 'Ryan')
73
+ ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", {'Content-Type' => ActiveResource::Formats[format].mime_type}, ryan, 201, {'Location' => "/people/5.#{format}"}
62
74
  assert_equal ActiveResource::Response.new(ryan, 201, {'Location' => "/people/5.#{format}"}), remote_ryan.post(:register)
63
75
  end
64
76
  end
65
77
  end
66
-
78
+
67
79
  def test_setting_format_before_site
68
80
  resource = Class.new(ActiveResource::Base)
69
81
  resource.format = :json
70
82
  resource.site = 'http://37s.sunrise.i:3000'
71
83
  assert_equal ActiveResource::Formats[:json], resource.connection.format
72
84
  end
73
-
85
+
74
86
  private
75
87
  def using_format(klass, mime_type_reference)
76
88
  previous_format = klass.format
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeresource
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,17 +9,18 @@ autorequire: active_resource
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-31 00:00:00 -07:00
12
+ date: 2008-09-04 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - "="
21
22
  - !ruby/object:Gem::Version
22
- version: 2.1.0
23
+ version: 2.1.1
23
24
  version:
24
25
  description: Wraps web resources in model classes that can be manipulated through XML over REST.
25
26
  email: david@loudthinking.com
@@ -57,6 +58,7 @@ files:
57
58
  - test/connection_test.rb
58
59
  - test/fixtures
59
60
  - test/fixtures/beast.rb
61
+ - test/fixtures/customer.rb
60
62
  - test/fixtures/person.rb
61
63
  - test/fixtures/street_address.rb
62
64
  - test/format_test.rb
@@ -84,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  requirements: []
85
87
 
86
88
  rubyforge_project: activeresource
87
- rubygems_version: 1.0.1
89
+ rubygems_version: 1.2.0
88
90
  signing_key:
89
91
  specification_version: 2
90
92
  summary: Think Active Record for web resources.