activeresource 2.0.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.

@@ -0,0 +1,14 @@
1
+ class BeastResource < ActiveResource::Base
2
+ self.site = 'http://beast.caboo.se'
3
+ site.user = 'foo'
4
+ site.password = 'bar'
5
+ end
6
+
7
+ class Forum < BeastResource
8
+ # taken from BeastResource
9
+ # self.site = 'http://beast.caboo.se'
10
+ end
11
+
12
+ class Topic < BeastResource
13
+ self.site += '/forums/:forum_id'
14
+ end
@@ -0,0 +1,3 @@
1
+ class Person < ActiveResource::Base
2
+ self.site = "http://37s.sunrise.i:3000"
3
+ end
@@ -0,0 +1,4 @@
1
+ class StreetAddress < ActiveResource::Base
2
+ self.site = "http://37s.sunrise.i:3000/people/:person_id/"
3
+ self.element_name = 'address'
4
+ end
@@ -0,0 +1,42 @@
1
+ require "#{File.dirname(__FILE__)}/abstract_unit"
2
+ require "fixtures/person"
3
+
4
+ class FormatTest < Test::Unit::TestCase
5
+ def setup
6
+ @matz = { :id => 1, :name => 'Matz' }
7
+ @david = { :id => 2, :name => 'David' }
8
+
9
+ @programmers = [ @matz, @david ]
10
+ end
11
+
12
+ def test_formats_on_single_element
13
+ for format in [ :json, :xml ]
14
+ using_format(Person, format) do
15
+ ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {}, ActiveResource::Formats[format].encode(@david)
16
+ assert_equal @david[:name], Person.find(1).name
17
+ end
18
+ end
19
+ end
20
+
21
+ def test_formats_on_collection
22
+ for format in [ :json, :xml ]
23
+ using_format(Person, format) do
24
+ ActiveResource::HttpMock.respond_to.get "/people.#{format}", {}, ActiveResource::Formats[format].encode(@programmers)
25
+ remote_programmers = Person.find(:all)
26
+ assert_equal 2, remote_programmers.size
27
+ assert remote_programmers.select { |p| p.name == 'David' }
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ private
34
+ def using_format(klass, mime_type_reference)
35
+ previous_format = klass.format
36
+ klass.format = mime_type_reference
37
+
38
+ yield
39
+ ensure
40
+ klass.format = previous_format
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ class SetterTrap < BasicObject
2
+ class << self
3
+ def rollback_sets(obj)
4
+ returning yield(setter_trap = new(obj)) do
5
+ setter_trap.rollback_sets
6
+ end
7
+ end
8
+ end
9
+
10
+ def initialize(obj)
11
+ @cache = {}
12
+ @obj = obj
13
+ end
14
+
15
+ def respond_to?(method)
16
+ @obj.respond_to?(method)
17
+ end
18
+
19
+ def method_missing(method, *args, &proc)
20
+ @cache[method] ||= @obj.send($`) if method.to_s =~ /=$/
21
+ @obj.send method, *args, &proc
22
+ end
23
+
24
+ def rollback_sets
25
+ @cache.each { |k, v| @obj.send k, v }
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: activeresource
5
+ version: !ruby/object:Gem::Version
6
+ version: 2.0.1
7
+ date: 2007-12-07 00:00:00 -06:00
8
+ summary: Think Active Record for web resources.
9
+ require_paths:
10
+ - lib
11
+ email: david@loudthinking.com
12
+ homepage: http://www.rubyonrails.org
13
+ rubyforge_project: activeresource
14
+ description: Wraps web resources in model classes that can be manipulated through XML over REST.
15
+ autorequire: active_resource
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - David Heinemeier Hansson
31
+ files:
32
+ - Rakefile
33
+ - README
34
+ - CHANGELOG
35
+ - lib/active_resource
36
+ - lib/active_resource/base.rb
37
+ - lib/active_resource/connection.rb
38
+ - lib/active_resource/custom_methods.rb
39
+ - lib/active_resource/formats
40
+ - lib/active_resource/formats/json_format.rb
41
+ - lib/active_resource/formats/xml_format.rb
42
+ - lib/active_resource/formats.rb
43
+ - lib/active_resource/http_mock.rb
44
+ - lib/active_resource/validations.rb
45
+ - lib/active_resource/version.rb
46
+ - lib/active_resource.rb
47
+ - lib/activeresource.rb
48
+ - test/abstract_unit.rb
49
+ - test/authorization_test.rb
50
+ - test/base
51
+ - test/base/custom_methods_test.rb
52
+ - test/base/equality_test.rb
53
+ - test/base/load_test.rb
54
+ - test/base_errors_test.rb
55
+ - test/base_test.rb
56
+ - test/base_test.rb.rej
57
+ - test/connection_test.rb
58
+ - test/debug.log
59
+ - test/fixtures
60
+ - test/fixtures/beast.rb
61
+ - test/fixtures/person.rb
62
+ - test/fixtures/street_address.rb
63
+ - test/format_test.rb
64
+ - test/setter_trap.rb
65
+ test_files: []
66
+
67
+ rdoc_options:
68
+ - --main
69
+ - README
70
+ extra_rdoc_files:
71
+ - README
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ requirements: []
77
+
78
+ dependencies:
79
+ - !ruby/object:Gem::Dependency
80
+ name: activesupport
81
+ version_requirement:
82
+ version_requirements: !ruby/object:Gem::Version::Requirement
83
+ requirements:
84
+ - - "="
85
+ - !ruby/object:Gem::Version
86
+ version: 2.0.1
87
+ version: