activeresource 2.3.18 → 3.0.0.beta
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 +1 -29
- data/README +7 -7
- data/examples/simple.rb +15 -0
- data/lib/active_resource.rb +17 -17
- data/lib/active_resource/base.rb +320 -66
- data/lib/active_resource/connection.rb +100 -100
- data/lib/active_resource/custom_methods.rb +33 -36
- data/lib/active_resource/exceptions.rb +4 -1
- data/lib/active_resource/formats.rb +4 -4
- data/lib/active_resource/formats/json_format.rb +2 -0
- data/lib/active_resource/formats/xml_format.rb +2 -0
- data/lib/active_resource/http_mock.rb +12 -103
- data/lib/active_resource/observing.rb +21 -0
- data/lib/active_resource/railtie.rb +17 -0
- data/lib/active_resource/railties/subscriber.rb +15 -0
- data/lib/active_resource/schema.rb +55 -0
- data/lib/active_resource/validations.rb +66 -215
- data/lib/active_resource/version.rb +3 -3
- metadata +29 -43
- data/Rakefile +0 -137
- data/lib/activeresource.rb +0 -2
- data/test/abstract_unit.rb +0 -21
- data/test/authorization_test.rb +0 -122
- data/test/base/custom_methods_test.rb +0 -100
- data/test/base/equality_test.rb +0 -52
- data/test/base/load_test.rb +0 -161
- data/test/base_errors_test.rb +0 -98
- data/test/base_test.rb +0 -1087
- data/test/connection_test.rb +0 -238
- data/test/fixtures/beast.rb +0 -14
- data/test/fixtures/customer.rb +0 -3
- data/test/fixtures/person.rb +0 -3
- data/test/fixtures/proxy.rb +0 -4
- data/test/fixtures/street_address.rb +0 -4
- data/test/format_test.rb +0 -112
- data/test/http_mock_test.rb +0 -155
- data/test/setter_trap.rb +0 -26
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeresource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 2
|
7
|
-
- 3
|
8
|
-
- 18
|
9
|
-
version: 2.3.18
|
4
|
+
version: 3.0.0.beta
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- David Heinemeier Hansson
|
@@ -14,24 +9,30 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date:
|
12
|
+
date: 2010-02-04 00:00:00 -08:00
|
18
13
|
default_executable:
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: activesupport
|
22
|
-
|
23
|
-
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
20
|
requirements:
|
25
21
|
- - "="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
version: 2.3.18
|
23
|
+
version: 3.0.0.beta
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activemodel
|
32
27
|
type: :runtime
|
33
|
-
|
34
|
-
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0.beta
|
34
|
+
version:
|
35
|
+
description: REST-model framework (part of Rails).
|
35
36
|
email: david@loudthinking.com
|
36
37
|
executables: []
|
37
38
|
|
@@ -40,9 +41,9 @@ extensions: []
|
|
40
41
|
extra_rdoc_files:
|
41
42
|
- README
|
42
43
|
files:
|
43
|
-
- Rakefile
|
44
|
-
- README
|
45
44
|
- CHANGELOG
|
45
|
+
- README
|
46
|
+
- examples/simple.rb
|
46
47
|
- lib/active_resource/base.rb
|
47
48
|
- lib/active_resource/connection.rb
|
48
49
|
- lib/active_resource/custom_methods.rb
|
@@ -51,26 +52,13 @@ files:
|
|
51
52
|
- lib/active_resource/formats/xml_format.rb
|
52
53
|
- lib/active_resource/formats.rb
|
53
54
|
- lib/active_resource/http_mock.rb
|
55
|
+
- lib/active_resource/observing.rb
|
56
|
+
- lib/active_resource/railtie.rb
|
57
|
+
- lib/active_resource/railties/subscriber.rb
|
58
|
+
- lib/active_resource/schema.rb
|
54
59
|
- lib/active_resource/validations.rb
|
55
60
|
- lib/active_resource/version.rb
|
56
61
|
- lib/active_resource.rb
|
57
|
-
- lib/activeresource.rb
|
58
|
-
- test/abstract_unit.rb
|
59
|
-
- test/authorization_test.rb
|
60
|
-
- test/base/custom_methods_test.rb
|
61
|
-
- test/base/equality_test.rb
|
62
|
-
- test/base/load_test.rb
|
63
|
-
- test/base_errors_test.rb
|
64
|
-
- test/base_test.rb
|
65
|
-
- test/connection_test.rb
|
66
|
-
- test/fixtures/beast.rb
|
67
|
-
- test/fixtures/customer.rb
|
68
|
-
- test/fixtures/person.rb
|
69
|
-
- test/fixtures/proxy.rb
|
70
|
-
- test/fixtures/street_address.rb
|
71
|
-
- test/format_test.rb
|
72
|
-
- test/http_mock_test.rb
|
73
|
-
- test/setter_trap.rb
|
74
62
|
has_rdoc: true
|
75
63
|
homepage: http://www.rubyonrails.org
|
76
64
|
licenses: []
|
@@ -85,22 +73,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
73
|
requirements:
|
86
74
|
- - ">="
|
87
75
|
- !ruby/object:Gem::Version
|
88
|
-
segments:
|
89
|
-
- 0
|
90
76
|
version: "0"
|
77
|
+
version:
|
91
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
79
|
requirements:
|
93
|
-
- - "
|
80
|
+
- - ">"
|
94
81
|
- !ruby/object:Gem::Version
|
95
|
-
|
96
|
-
|
97
|
-
version: "0"
|
82
|
+
version: 1.3.1
|
83
|
+
version:
|
98
84
|
requirements: []
|
99
85
|
|
100
86
|
rubyforge_project: activeresource
|
101
|
-
rubygems_version: 1.3.
|
87
|
+
rubygems_version: 1.3.5
|
102
88
|
signing_key:
|
103
89
|
specification_version: 3
|
104
|
-
summary:
|
90
|
+
summary: REST-model framework (part of Rails).
|
105
91
|
test_files: []
|
106
92
|
|
data/Rakefile
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'rdoc/task'
|
5
|
-
require 'rake/packagetask'
|
6
|
-
require 'rubygems/package_task'
|
7
|
-
|
8
|
-
require File.join(File.dirname(__FILE__), 'lib', 'active_resource', 'version')
|
9
|
-
|
10
|
-
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
11
|
-
PKG_NAME = 'activeresource'
|
12
|
-
PKG_VERSION = ActiveResource::VERSION::STRING + PKG_BUILD
|
13
|
-
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
14
|
-
|
15
|
-
RELEASE_NAME = "REL #{PKG_VERSION}"
|
16
|
-
|
17
|
-
RUBY_FORGE_PROJECT = "activerecord"
|
18
|
-
RUBY_FORGE_USER = "webster132"
|
19
|
-
|
20
|
-
PKG_FILES = FileList[
|
21
|
-
"lib/**/*", "test/**/*", "[A-Z]*", "Rakefile"
|
22
|
-
].exclude(/\bCVS\b|~$/)
|
23
|
-
|
24
|
-
desc "Default Task"
|
25
|
-
task :default => [ :test ]
|
26
|
-
|
27
|
-
# Run the unit tests
|
28
|
-
|
29
|
-
Rake::TestTask.new { |t|
|
30
|
-
activesupport_path = "#{File.dirname(__FILE__)}/../activesupport/lib"
|
31
|
-
t.libs << activesupport_path if File.directory?(activesupport_path)
|
32
|
-
t.libs << "test"
|
33
|
-
t.pattern = 'test/**/*_test.rb'
|
34
|
-
t.verbose = true
|
35
|
-
t.warning = true
|
36
|
-
}
|
37
|
-
|
38
|
-
|
39
|
-
# Generate the RDoc documentation
|
40
|
-
|
41
|
-
RDoc::Task.new { |rdoc|
|
42
|
-
rdoc.rdoc_dir = 'doc'
|
43
|
-
rdoc.title = "Active Resource -- Object-oriented REST services"
|
44
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
45
|
-
rdoc.options << '--charset' << 'utf-8'
|
46
|
-
rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
|
47
|
-
rdoc.rdoc_files.include('README', 'CHANGELOG')
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
-
rdoc.rdoc_files.exclude('lib/activeresource.rb')
|
50
|
-
}
|
51
|
-
|
52
|
-
|
53
|
-
# Create compressed packages
|
54
|
-
|
55
|
-
dist_dirs = [ "lib", "test", "examples", "dev-utils" ]
|
56
|
-
|
57
|
-
spec = Gem::Specification.new do |s|
|
58
|
-
s.platform = Gem::Platform::RUBY
|
59
|
-
s.name = PKG_NAME
|
60
|
-
s.version = PKG_VERSION
|
61
|
-
s.summary = "Think Active Record for web resources."
|
62
|
-
s.description = %q{Wraps web resources in model classes that can be manipulated through XML over REST.}
|
63
|
-
|
64
|
-
s.files = [ "Rakefile", "README", "CHANGELOG" ]
|
65
|
-
dist_dirs.each do |dir|
|
66
|
-
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
67
|
-
end
|
68
|
-
|
69
|
-
s.add_dependency('activesupport', '= 2.3.18' + PKG_BUILD)
|
70
|
-
|
71
|
-
s.require_path = 'lib'
|
72
|
-
|
73
|
-
s.extra_rdoc_files = %w( README )
|
74
|
-
s.rdoc_options.concat ['--main', 'README']
|
75
|
-
|
76
|
-
s.author = "David Heinemeier Hansson"
|
77
|
-
s.email = "david@loudthinking.com"
|
78
|
-
s.homepage = "http://www.rubyonrails.org"
|
79
|
-
s.rubyforge_project = "activeresource"
|
80
|
-
end
|
81
|
-
|
82
|
-
Gem::PackageTask.new(spec) do |p|
|
83
|
-
p.gem_spec = spec
|
84
|
-
p.need_tar = true
|
85
|
-
p.need_zip = true
|
86
|
-
end
|
87
|
-
|
88
|
-
task :lines do
|
89
|
-
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
|
90
|
-
|
91
|
-
for file_name in FileList["lib/active_resource/**/*.rb"]
|
92
|
-
next if file_name =~ /vendor/
|
93
|
-
f = File.open(file_name)
|
94
|
-
|
95
|
-
while line = f.gets
|
96
|
-
lines += 1
|
97
|
-
next if line =~ /^\s*$/
|
98
|
-
next if line =~ /^\s*#/
|
99
|
-
codelines += 1
|
100
|
-
end
|
101
|
-
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
|
102
|
-
|
103
|
-
total_lines += lines
|
104
|
-
total_codelines += codelines
|
105
|
-
|
106
|
-
lines, codelines = 0, 0
|
107
|
-
end
|
108
|
-
|
109
|
-
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
# Publishing ------------------------------------------------------
|
114
|
-
|
115
|
-
desc "Publish the beta gem"
|
116
|
-
task :pgem => [:package] do
|
117
|
-
require 'rake/contrib/sshpublisher'
|
118
|
-
Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
119
|
-
`ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
|
120
|
-
end
|
121
|
-
|
122
|
-
desc "Publish the API documentation"
|
123
|
-
task :pdoc => [:rdoc] do
|
124
|
-
require 'rake/contrib/sshpublisher'
|
125
|
-
Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/ar", "doc").upload
|
126
|
-
end
|
127
|
-
|
128
|
-
desc "Publish the release files to RubyForge."
|
129
|
-
task :release => [ :package ] do
|
130
|
-
`rubyforge login`
|
131
|
-
|
132
|
-
for ext in %w( gem tgz zip )
|
133
|
-
release_command = "rubyforge add_release #{PKG_NAME} #{PKG_NAME} 'REL #{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}"
|
134
|
-
puts release_command
|
135
|
-
system(release_command)
|
136
|
-
end
|
137
|
-
end
|
data/lib/activeresource.rb
DELETED
data/test/abstract_unit.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'active_support/test_case'
|
4
|
-
|
5
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
6
|
-
$:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
|
7
|
-
require 'active_resource'
|
8
|
-
require 'active_resource/http_mock'
|
9
|
-
|
10
|
-
$:.unshift "#{File.dirname(__FILE__)}/../test"
|
11
|
-
require 'setter_trap'
|
12
|
-
|
13
|
-
ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log")
|
14
|
-
|
15
|
-
def uses_gem(gem_name, test_name, version = '> 0')
|
16
|
-
gem gem_name.to_s, version
|
17
|
-
require gem_name.to_s
|
18
|
-
yield
|
19
|
-
rescue LoadError
|
20
|
-
$stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
|
21
|
-
end
|
data/test/authorization_test.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'abstract_unit'
|
2
|
-
|
3
|
-
class AuthorizationTest < Test::Unit::TestCase
|
4
|
-
Response = Struct.new(:code)
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@conn = ActiveResource::Connection.new('http://localhost')
|
8
|
-
@matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
|
9
|
-
@david = { :id => 2, :name => 'David' }.to_xml(:root => 'person')
|
10
|
-
@authenticated_conn = ActiveResource::Connection.new("http://david:test123@localhost")
|
11
|
-
@authorization_request_header = { 'Authorization' => 'Basic ZGF2aWQ6dGVzdDEyMw==' }
|
12
|
-
|
13
|
-
ActiveResource::HttpMock.respond_to do |mock|
|
14
|
-
mock.get "/people/2.xml", @authorization_request_header, @david
|
15
|
-
mock.put "/people/2.xml", @authorization_request_header, nil, 204
|
16
|
-
mock.delete "/people/2.xml", @authorization_request_header, nil, 200
|
17
|
-
mock.post "/people/2/addresses.xml", @authorization_request_header, nil, 201, 'Location' => '/people/1/addresses/5'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_authorization_header
|
22
|
-
authorization_header = @authenticated_conn.__send__(:authorization_header)
|
23
|
-
assert_equal @authorization_request_header['Authorization'], authorization_header['Authorization']
|
24
|
-
authorization = authorization_header["Authorization"].to_s.split
|
25
|
-
|
26
|
-
assert_equal "Basic", authorization[0]
|
27
|
-
assert_equal ["david", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_authorization_header_with_username_but_no_password
|
31
|
-
@conn = ActiveResource::Connection.new("http://david:@localhost")
|
32
|
-
authorization_header = @conn.__send__(:authorization_header)
|
33
|
-
authorization = authorization_header["Authorization"].to_s.split
|
34
|
-
|
35
|
-
assert_equal "Basic", authorization[0]
|
36
|
-
assert_equal ["david"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_authorization_header_with_password_but_no_username
|
40
|
-
@conn = ActiveResource::Connection.new("http://:test123@localhost")
|
41
|
-
authorization_header = @conn.__send__(:authorization_header)
|
42
|
-
authorization = authorization_header["Authorization"].to_s.split
|
43
|
-
|
44
|
-
assert_equal "Basic", authorization[0]
|
45
|
-
assert_equal ["", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_authorization_header_with_decoded_credentials_from_url
|
49
|
-
@conn = ActiveResource::Connection.new("http://my%40email.com:%31%32%33@localhost")
|
50
|
-
authorization_header = @conn.__send__(:authorization_header)
|
51
|
-
authorization = authorization_header["Authorization"].to_s.split
|
52
|
-
|
53
|
-
assert_equal "Basic", authorization[0]
|
54
|
-
assert_equal ["my@email.com", "123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_authorization_header_explicitly_setting_username_and_password
|
58
|
-
@authenticated_conn = ActiveResource::Connection.new("http://@localhost")
|
59
|
-
@authenticated_conn.user = 'david'
|
60
|
-
@authenticated_conn.password = 'test123'
|
61
|
-
authorization_header = @authenticated_conn.__send__(:authorization_header)
|
62
|
-
assert_equal @authorization_request_header['Authorization'], authorization_header['Authorization']
|
63
|
-
authorization = authorization_header["Authorization"].to_s.split
|
64
|
-
|
65
|
-
assert_equal "Basic", authorization[0]
|
66
|
-
assert_equal ["david", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_authorization_header_explicitly_setting_username_but_no_password
|
70
|
-
@conn = ActiveResource::Connection.new("http://@localhost")
|
71
|
-
@conn.user = "david"
|
72
|
-
authorization_header = @conn.__send__(:authorization_header)
|
73
|
-
authorization = authorization_header["Authorization"].to_s.split
|
74
|
-
|
75
|
-
assert_equal "Basic", authorization[0]
|
76
|
-
assert_equal ["david"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_authorization_header_explicitly_setting_password_but_no_username
|
80
|
-
@conn = ActiveResource::Connection.new("http://@localhost")
|
81
|
-
@conn.password = "test123"
|
82
|
-
authorization_header = @conn.__send__(:authorization_header)
|
83
|
-
authorization = authorization_header["Authorization"].to_s.split
|
84
|
-
|
85
|
-
assert_equal "Basic", authorization[0]
|
86
|
-
assert_equal ["", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_get
|
90
|
-
david = @authenticated_conn.get("/people/2.xml")
|
91
|
-
assert_equal "David", david["name"]
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_post
|
95
|
-
response = @authenticated_conn.post("/people/2/addresses.xml")
|
96
|
-
assert_equal "/people/1/addresses/5", response["Location"]
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_put
|
100
|
-
response = @authenticated_conn.put("/people/2.xml")
|
101
|
-
assert_equal 204, response.code
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_delete
|
105
|
-
response = @authenticated_conn.delete("/people/2.xml")
|
106
|
-
assert_equal 200, response.code
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_raises_invalid_request_on_unauthorized_requests
|
110
|
-
assert_raise(ActiveResource::InvalidRequestError) { @conn.post("/people/2.xml") }
|
111
|
-
assert_raise(ActiveResource::InvalidRequestError) { @conn.post("/people/2/addresses.xml") }
|
112
|
-
assert_raise(ActiveResource::InvalidRequestError) { @conn.put("/people/2.xml") }
|
113
|
-
assert_raise(ActiveResource::InvalidRequestError) { @conn.delete("/people/2.xml") }
|
114
|
-
end
|
115
|
-
|
116
|
-
protected
|
117
|
-
def assert_response_raises(klass, code)
|
118
|
-
assert_raise(klass, "Expected response code #{code} to raise #{klass}") do
|
119
|
-
@conn.__send__(:handle_response, Response.new(code))
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'abstract_unit'
|
2
|
-
require 'fixtures/person'
|
3
|
-
require 'fixtures/street_address'
|
4
|
-
|
5
|
-
class CustomMethodsTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
|
8
|
-
@matz_deep = { :id => 1, :name => 'Matz', :other => 'other' }.to_xml(:root => 'person')
|
9
|
-
@matz_array = [{ :id => 1, :name => 'Matz' }].to_xml(:root => 'people')
|
10
|
-
@ryan = { :name => 'Ryan' }.to_xml(:root => 'person')
|
11
|
-
@addy = { :id => 1, :street => '12345 Street' }.to_xml(:root => 'address')
|
12
|
-
@addy_deep = { :id => 1, :street => '12345 Street', :zip => "27519" }.to_xml(:root => 'address')
|
13
|
-
|
14
|
-
ActiveResource::HttpMock.respond_to do |mock|
|
15
|
-
mock.get "/people/1.xml", {}, @matz
|
16
|
-
mock.get "/people/1/shallow.xml", {}, @matz
|
17
|
-
mock.get "/people/1/deep.xml", {}, @matz_deep
|
18
|
-
mock.get "/people/retrieve.xml?name=Matz", {}, @matz_array
|
19
|
-
mock.get "/people/managers.xml", {}, @matz_array
|
20
|
-
mock.post "/people/hire.xml?name=Matz", {}, nil, 201
|
21
|
-
mock.put "/people/1/promote.xml?position=Manager", {}, nil, 204
|
22
|
-
mock.put "/people/promote.xml?name=Matz", {}, nil, 204, {}
|
23
|
-
mock.put "/people/sort.xml?by=name", {}, nil, 204
|
24
|
-
mock.delete "/people/deactivate.xml?name=Matz", {}, nil, 200
|
25
|
-
mock.delete "/people/1/deactivate.xml", {}, nil, 200
|
26
|
-
mock.post "/people/new/register.xml", {}, @ryan, 201, 'Location' => '/people/5.xml'
|
27
|
-
mock.post "/people/1/register.xml", {}, @matz, 201
|
28
|
-
mock.get "/people/1/addresses/1.xml", {}, @addy
|
29
|
-
mock.get "/people/1/addresses/1/deep.xml", {}, @addy_deep
|
30
|
-
mock.put "/people/1/addresses/1/normalize_phone.xml?locale=US", {}, nil, 204
|
31
|
-
mock.put "/people/1/addresses/sort.xml?by=name", {}, nil, 204
|
32
|
-
mock.post "/people/1/addresses/new/link.xml", {}, { :street => '12345 Street' }.to_xml(:root => 'address'), 201, 'Location' => '/people/1/addresses/2.xml'
|
33
|
-
end
|
34
|
-
|
35
|
-
Person.user = nil
|
36
|
-
Person.password = nil
|
37
|
-
end
|
38
|
-
|
39
|
-
def teardown
|
40
|
-
ActiveResource::HttpMock.reset!
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_custom_collection_method
|
44
|
-
# GET
|
45
|
-
assert_equal([{ "id" => 1, "name" => 'Matz' }], Person.get(:retrieve, :name => 'Matz'))
|
46
|
-
|
47
|
-
# POST
|
48
|
-
assert_equal(ActiveResource::Response.new("", 201, {}), Person.post(:hire, :name => 'Matz'))
|
49
|
-
|
50
|
-
# PUT
|
51
|
-
assert_equal ActiveResource::Response.new("", 204, {}),
|
52
|
-
Person.put(:promote, {:name => 'Matz'}, 'atestbody')
|
53
|
-
assert_equal ActiveResource::Response.new("", 204, {}), Person.put(:sort, :by => 'name')
|
54
|
-
|
55
|
-
# DELETE
|
56
|
-
Person.delete :deactivate, :name => 'Matz'
|
57
|
-
|
58
|
-
# Nested resource
|
59
|
-
assert_equal ActiveResource::Response.new("", 204, {}), StreetAddress.put(:sort, :person_id => 1, :by => 'name')
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_custom_element_method
|
63
|
-
# Test GET against an element URL
|
64
|
-
assert_equal Person.find(1).get(:shallow), {"id" => 1, "name" => 'Matz'}
|
65
|
-
assert_equal Person.find(1).get(:deep), {"id" => 1, "name" => 'Matz', "other" => 'other'}
|
66
|
-
|
67
|
-
# Test PUT against an element URL
|
68
|
-
assert_equal ActiveResource::Response.new("", 204, {}), Person.find(1).put(:promote, {:position => 'Manager'}, 'body')
|
69
|
-
|
70
|
-
# Test DELETE against an element URL
|
71
|
-
assert_equal ActiveResource::Response.new("", 200, {}), Person.find(1).delete(:deactivate)
|
72
|
-
|
73
|
-
# With nested resources
|
74
|
-
assert_equal StreetAddress.find(1, :params => { :person_id => 1 }).get(:deep),
|
75
|
-
{ "id" => 1, "street" => '12345 Street', "zip" => "27519" }
|
76
|
-
assert_equal ActiveResource::Response.new("", 204, {}),
|
77
|
-
StreetAddress.find(1, :params => { :person_id => 1 }).put(:normalize_phone, :locale => 'US')
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_custom_new_element_method
|
81
|
-
# Test POST against a new element URL
|
82
|
-
ryan = Person.new(:name => 'Ryan')
|
83
|
-
assert_equal ActiveResource::Response.new(@ryan, 201, {'Location' => '/people/5.xml'}), ryan.post(:register)
|
84
|
-
expected_request = ActiveResource::Request.new(:post, '/people/new/register.xml', @ryan)
|
85
|
-
assert_equal expected_request.body, ActiveResource::HttpMock.requests.first.body
|
86
|
-
|
87
|
-
# Test POST against a nested collection URL
|
88
|
-
addy = StreetAddress.new(:street => '123 Test Dr.', :person_id => 1)
|
89
|
-
assert_equal ActiveResource::Response.new({ :street => '12345 Street' }.to_xml(:root => 'address'),
|
90
|
-
201, {'Location' => '/people/1/addresses/2.xml'}),
|
91
|
-
addy.post(:link)
|
92
|
-
|
93
|
-
matz = Person.new(:id => 1, :name => 'Matz')
|
94
|
-
assert_equal ActiveResource::Response.new(@matz, 201), matz.post(:register)
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_find_custom_resources
|
98
|
-
assert_equal 'Matz', Person.find(:all, :from => :managers).first.name
|
99
|
-
end
|
100
|
-
end
|