activeresource 2.1.2 → 2.2.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 +9 -3
- data/README +1 -1
- data/Rakefile +3 -4
- data/lib/active_resource.rb +7 -10
- data/lib/active_resource/base.rb +170 -117
- data/lib/active_resource/connection.rb +27 -16
- data/lib/active_resource/custom_methods.rb +14 -13
- data/lib/active_resource/formats/json_format.rb +7 -7
- data/lib/active_resource/formats/xml_format.rb +9 -9
- data/lib/active_resource/http_mock.rb +2 -2
- data/lib/active_resource/validations.rb +15 -29
- data/lib/active_resource/version.rb +1 -1
- data/test/authorization_test.rb +8 -8
- data/test/base/custom_methods_test.rb +3 -2
- data/test/base/load_test.rb +2 -2
- data/test/base_test.rb +80 -50
- data/test/connection_test.rb +11 -3
- data/test/format_test.rb +40 -11
- metadata +4 -4
data/test/connection_test.rb
CHANGED
@@ -168,12 +168,20 @@ class ConnectionTest < Test::Unit::TestCase
|
|
168
168
|
assert_equal 200, response.code
|
169
169
|
end
|
170
170
|
|
171
|
-
uses_mocha('test_timeout') do
|
171
|
+
uses_mocha('test_timeout, test_accept_http_header') do
|
172
172
|
def test_timeout
|
173
173
|
@http = mock('new Net::HTTP')
|
174
174
|
@conn.expects(:http).returns(@http)
|
175
175
|
@http.expects(:get).raises(Timeout::Error, 'execution expired')
|
176
|
-
|
176
|
+
assert_raise(ActiveResource::TimeoutError) { @conn.get('/people_timeout.xml') }
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_accept_http_header
|
180
|
+
@http = mock('new Net::HTTP')
|
181
|
+
@conn.expects(:http).returns(@http)
|
182
|
+
path = '/people/1.xml'
|
183
|
+
@http.expects(:get).with(path, {'Accept' => 'application/xhtml+xml'}).returns(ActiveResource::Response.new(@matz, 200, {'Content-Type' => 'text/xhtml'}))
|
184
|
+
assert_nothing_raised(Mocha::ExpectationError) { @conn.get(path, {'Accept' => 'application/xhtml+xml'}) }
|
177
185
|
end
|
178
186
|
end
|
179
187
|
|
@@ -185,6 +193,6 @@ class ConnectionTest < Test::Unit::TestCase
|
|
185
193
|
end
|
186
194
|
|
187
195
|
def handle_response(response)
|
188
|
-
@conn.
|
196
|
+
@conn.__send__(:handle_response, response)
|
189
197
|
end
|
190
198
|
end
|
data/test/format_test.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
require "fixtures/person"
|
3
|
+
require "fixtures/street_address"
|
3
4
|
|
4
5
|
class FormatTest < Test::Unit::TestCase
|
5
6
|
def setup
|
6
7
|
@matz = { :id => 1, :name => 'Matz' }
|
7
8
|
@david = { :id => 2, :name => 'David' }
|
8
|
-
|
9
|
+
|
9
10
|
@programmers = [ @matz, @david ]
|
10
11
|
end
|
11
|
-
|
12
|
+
|
13
|
+
def test_http_format_header_name
|
14
|
+
header_name = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:get]
|
15
|
+
assert_equal 'Accept', header_name
|
16
|
+
|
17
|
+
headers_names = [ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:put], ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:post]]
|
18
|
+
headers_names.each{|header_name| assert_equal 'Content-Type', header_name}
|
19
|
+
end
|
20
|
+
|
12
21
|
def test_formats_on_single_element
|
13
22
|
for format in [ :json, :xml ]
|
14
23
|
using_format(Person, format) do
|
15
|
-
ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {}, ActiveResource::Formats[format].encode(@david)
|
24
|
+
ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
|
16
25
|
assert_equal @david[:name], Person.find(1).name
|
17
26
|
end
|
18
27
|
end
|
@@ -21,7 +30,7 @@ class FormatTest < Test::Unit::TestCase
|
|
21
30
|
def test_formats_on_collection
|
22
31
|
for format in [ :json, :xml ]
|
23
32
|
using_format(Person, format) do
|
24
|
-
ActiveResource::HttpMock.respond_to.get "/people.#{format}", {}, ActiveResource::Formats[format].encode(@programmers)
|
33
|
+
ActiveResource::HttpMock.respond_to.get "/people.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@programmers)
|
25
34
|
remote_programmers = Person.find(:all)
|
26
35
|
assert_equal 2, remote_programmers.size
|
27
36
|
assert remote_programmers.select { |p| p.name == 'David' }
|
@@ -32,7 +41,7 @@ class FormatTest < Test::Unit::TestCase
|
|
32
41
|
def test_formats_on_custom_collection_method
|
33
42
|
for format in [ :json, :xml ]
|
34
43
|
using_format(Person, format) do
|
35
|
-
ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {}, ActiveResource::Formats[format].encode([@david])
|
44
|
+
ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode([@david])
|
36
45
|
remote_programmers = Person.get(:retrieve, :name => 'David')
|
37
46
|
assert_equal 1, remote_programmers.size
|
38
47
|
assert_equal @david[:id], remote_programmers[0]['id']
|
@@ -40,13 +49,13 @@ class FormatTest < Test::Unit::TestCase
|
|
40
49
|
end
|
41
50
|
end
|
42
51
|
end
|
43
|
-
|
52
|
+
|
44
53
|
def test_formats_on_custom_element_method
|
45
54
|
for format in [ :json, :xml ]
|
46
55
|
using_format(Person, format) do
|
47
56
|
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)
|
57
|
+
mock.get "/people/2.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
|
58
|
+
mock.get "/people/2/shallow.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
|
50
59
|
end
|
51
60
|
remote_programmer = Person.find(2).get(:shallow)
|
52
61
|
assert_equal @david[:id], remote_programmer['id']
|
@@ -57,20 +66,40 @@ class FormatTest < Test::Unit::TestCase
|
|
57
66
|
for format in [ :json, :xml ]
|
58
67
|
ryan = ActiveResource::Formats[format].encode({ :name => 'Ryan' })
|
59
68
|
using_format(Person, format) do
|
60
|
-
ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", {}, ryan, 201, 'Location' => "/people/5.#{format}"
|
61
69
|
remote_ryan = Person.new(:name => 'Ryan')
|
70
|
+
ActiveResource::HttpMock.respond_to.post "/people.#{format}", {'Content-Type' => ActiveResource::Formats[format].mime_type}, ryan, 201, {'Location' => "/people/5.#{format}"}
|
71
|
+
remote_ryan.save
|
72
|
+
|
73
|
+
remote_ryan = Person.new(:name => 'Ryan')
|
74
|
+
ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", {'Content-Type' => ActiveResource::Formats[format].mime_type}, ryan, 201, {'Location' => "/people/5.#{format}"}
|
62
75
|
assert_equal ActiveResource::Response.new(ryan, 201, {'Location' => "/people/5.#{format}"}), remote_ryan.post(:register)
|
63
76
|
end
|
64
77
|
end
|
65
78
|
end
|
66
|
-
|
79
|
+
|
67
80
|
def test_setting_format_before_site
|
68
81
|
resource = Class.new(ActiveResource::Base)
|
69
82
|
resource.format = :json
|
70
83
|
resource.site = 'http://37s.sunrise.i:3000'
|
71
84
|
assert_equal ActiveResource::Formats[:json], resource.connection.format
|
72
85
|
end
|
73
|
-
|
86
|
+
|
87
|
+
def test_serialization_of_nested_resource
|
88
|
+
address = { :street => '12345 Street' }
|
89
|
+
person = { :name=> 'Rus', :address => address}
|
90
|
+
|
91
|
+
[:json, :xml].each do |format|
|
92
|
+
encoded_person = ActiveResource::Formats[format].encode(person)
|
93
|
+
assert_match /12345 Street/, encoded_person
|
94
|
+
remote_person = Person.new(person.update({:address => StreetAddress.new(address)}))
|
95
|
+
assert_kind_of StreetAddress, remote_person.address
|
96
|
+
using_format(Person, format) do
|
97
|
+
ActiveResource::HttpMock.respond_to.post "/people.#{format}", {'Content-Type' => ActiveResource::Formats[format].mime_type}, encoded_person, 201, {'Location' => "/people/5.#{format}"}
|
98
|
+
remote_person.save
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
74
103
|
private
|
75
104
|
def using_format(klass, mime_type_reference)
|
76
105
|
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.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -9,7 +9,7 @@ autorequire: active_resource
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-20 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.
|
23
|
+
version: 2.2.2
|
24
24
|
version:
|
25
25
|
description: Wraps web resources in model classes that can be manipulated through XML over REST.
|
26
26
|
email: david@loudthinking.com
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements: []
|
87
87
|
|
88
88
|
rubyforge_project: activeresource
|
89
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 1.3.1
|
90
90
|
signing_key:
|
91
91
|
specification_version: 2
|
92
92
|
summary: Think Active Record for web resources.
|