activeresource_csi 2.3.5.p6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 Customer < ActiveResource::Base
2
+ self.site = "http://37s.sunrise.i:3000"
3
+ 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 ProxyResource < ActiveResource::Base
2
+ self.site = "http://localhost"
3
+ self.proxy = "http://user:password@proxy.local:3000"
4
+ 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,112 @@
1
+ require 'abstract_unit'
2
+ require "fixtures/person"
3
+ require "fixtures/street_address"
4
+
5
+ class FormatTest < Test::Unit::TestCase
6
+ def setup
7
+ @matz = { :id => 1, :name => 'Matz' }
8
+ @david = { :id => 2, :name => 'David' }
9
+
10
+ @programmers = [ @matz, @david ]
11
+ end
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{ |name| assert_equal 'Content-Type', name }
19
+ end
20
+
21
+ def test_formats_on_single_element
22
+ for format in [ :json, :xml ]
23
+ using_format(Person, format) do
24
+ ActiveResource::HttpMock.respond_to.get "/people/1.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@david)
25
+ assert_equal @david[:name], Person.find(1).name
26
+ end
27
+ end
28
+ end
29
+
30
+ def test_formats_on_collection
31
+ for format in [ :json, :xml ]
32
+ using_format(Person, format) do
33
+ ActiveResource::HttpMock.respond_to.get "/people.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@programmers)
34
+ remote_programmers = Person.find(:all)
35
+ assert_equal 2, remote_programmers.size
36
+ assert remote_programmers.select { |p| p.name == 'David' }
37
+ end
38
+ end
39
+ end
40
+
41
+ def test_formats_on_custom_collection_method
42
+ for format in [ :json, :xml ]
43
+ using_format(Person, format) do
44
+ ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode([@david])
45
+ remote_programmers = Person.get(:retrieve, :name => 'David')
46
+ assert_equal 1, remote_programmers.size
47
+ assert_equal @david[:id], remote_programmers[0]['id']
48
+ assert_equal @david[:name], remote_programmers[0]['name']
49
+ end
50
+ end
51
+ end
52
+
53
+ def test_formats_on_custom_element_method
54
+ for format in [ :json, :xml ]
55
+ using_format(Person, format) do
56
+ ActiveResource::HttpMock.respond_to do |mock|
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)
59
+ end
60
+ remote_programmer = Person.find(2).get(:shallow)
61
+ assert_equal @david[:id], remote_programmer['id']
62
+ assert_equal @david[:name], remote_programmer['name']
63
+ end
64
+ end
65
+
66
+ for format in [ :json, :xml ]
67
+ ryan = ActiveResource::Formats[format].encode({ :name => 'Ryan' })
68
+ using_format(Person, format) do
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}"}
75
+ assert_equal ActiveResource::Response.new(ryan, 201, {'Location' => "/people/5.#{format}"}), remote_ryan.post(:register)
76
+ end
77
+ end
78
+ end
79
+
80
+ def test_setting_format_before_site
81
+ resource = Class.new(ActiveResource::Base)
82
+ resource.format = :json
83
+ resource.site = 'http://37s.sunrise.i:3000'
84
+ assert_equal ActiveResource::Formats[:json], resource.connection.format
85
+ end
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
+
103
+ private
104
+ def using_format(klass, mime_type_reference)
105
+ previous_format = klass.format
106
+ klass.format = mime_type_reference
107
+
108
+ yield
109
+ ensure
110
+ klass.format = previous_format
111
+ end
112
+ end
@@ -0,0 +1,26 @@
1
+ class SetterTrap < ActiveSupport::BasicObject
2
+ class << self
3
+ def rollback_sets(obj)
4
+ trapped = new(obj)
5
+ yield(trapped).tap { trapped.rollback_sets }
6
+ end
7
+ end
8
+
9
+ def initialize(obj)
10
+ @cache = {}
11
+ @obj = obj
12
+ end
13
+
14
+ def respond_to?(method)
15
+ @obj.respond_to?(method)
16
+ end
17
+
18
+ def method_missing(method, *args, &proc)
19
+ @cache[method] ||= @obj.send($`) if method.to_s =~ /=$/
20
+ @obj.send method, *args, &proc
21
+ end
22
+
23
+ def rollback_sets
24
+ @cache.each { |k, v| @obj.send k, v }
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeresource_csi
3
+ version: !ruby/object:Gem::Version
4
+ hash: -2454080792
5
+ prerelease: 6
6
+ segments:
7
+ - 2
8
+ - 3
9
+ - 5
10
+ - p
11
+ - 6
12
+ version: 2.3.5.p6
13
+ platform: ruby
14
+ authors:
15
+ - David Heinemeier Hansson
16
+ autorequire: active_resource
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2013-01-30 00:00:00 -04:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ prerelease: false
25
+ name: activesupport
26
+ type: :runtime
27
+ requirement: &id001 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - "="
31
+ - !ruby/object:Gem::Version
32
+ hash: -2454080792
33
+ segments:
34
+ - 2
35
+ - 3
36
+ - 5
37
+ - p
38
+ - 6
39
+ version: 2.3.5.p6
40
+ version_requirements: *id001
41
+ description: Wraps web resources in model classes that can be manipulated through XML over REST.
42
+ email: david@loudthinking.com
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files:
48
+ - README
49
+ files:
50
+ - Rakefile
51
+ - README
52
+ - CHANGELOG
53
+ - lib/active_resource.rb
54
+ - lib/active_resource/base.rb
55
+ - lib/active_resource/validations.rb
56
+ - lib/active_resource/version.rb
57
+ - lib/active_resource/exceptions.rb
58
+ - lib/active_resource/formats/json_format.rb
59
+ - lib/active_resource/formats/xml_format.rb
60
+ - lib/active_resource/http_mock.rb
61
+ - lib/active_resource/formats.rb
62
+ - lib/active_resource/custom_methods.rb
63
+ - lib/active_resource/connection.rb
64
+ - lib/activeresource.rb
65
+ - test/abstract_unit.rb
66
+ - test/debug.log
67
+ - test/format_test.rb
68
+ - test/authorization_test.rb
69
+ - test/base/custom_methods_test.rb
70
+ - test/base/equality_test.rb
71
+ - test/base/load_test.rb
72
+ - test/base_errors_test.rb
73
+ - test/base_test.rb
74
+ - test/connection_test.rb
75
+ - test/setter_trap.rb
76
+ - test/fixtures/beast.rb
77
+ - test/fixtures/person.rb
78
+ - test/fixtures/customer.rb
79
+ - test/fixtures/street_address.rb
80
+ - test/fixtures/proxy.rb
81
+ has_rdoc: true
82
+ homepage: http://www.rubyonrails.org
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --main
88
+ - README
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">"
104
+ - !ruby/object:Gem::Version
105
+ hash: 25
106
+ segments:
107
+ - 1
108
+ - 3
109
+ - 1
110
+ version: 1.3.1
111
+ requirements: []
112
+
113
+ rubyforge_project: activeresource
114
+ rubygems_version: 1.5.3
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Think Active Record for web resources.
118
+ test_files: []
119
+