From ab321268f86d9013cbd4ecd0b5f46e7b05ec55a9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 16:10:49 -0700 Subject: No more free lunch --- activeresource/lib/active_resource.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activeresource') diff --git a/activeresource/lib/active_resource.rb b/activeresource/lib/active_resource.rb index db9007060f..2f0c8d1a8e 100644 --- a/activeresource/lib/active_resource.rb +++ b/activeresource/lib/active_resource.rb @@ -30,6 +30,7 @@ rescue LoadError require 'active_support' end end +require 'active_support/core/all' require 'active_resource/formats' require 'active_resource/base' -- cgit v1.2.3 From 6fee981fa4ea2654f825c58b58327fc15fddf3a6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Apr 2009 16:48:58 -0700 Subject: Opt in to JSON --- activeresource/lib/active_resource/formats/json_format.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activeresource') diff --git a/activeresource/lib/active_resource/formats/json_format.rb b/activeresource/lib/active_resource/formats/json_format.rb index 1d88fc5f16..101027d99e 100644 --- a/activeresource/lib/active_resource/formats/json_format.rb +++ b/activeresource/lib/active_resource/formats/json_format.rb @@ -1,3 +1,5 @@ +require 'active_support/json' + module ActiveResource module Formats module JsonFormat -- cgit v1.2.3 From 3c4c6bd0df598f865f49a983b4c65c415af4bcfc Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 23 Apr 2009 00:08:40 -0700 Subject: * Add pluggable JSON backends with support for the JSON gem. [rick] Example: ActiveSupport::JSON.backend = "JSONGem" All internal Rails JSON encoding is now handled by ActiveSupport::JSON.encode(). Use of #to_json is not recommended, as it may clash with other libraries that overwrite it. However, you can recover Rails specific functionality if you really want to use #to_json. gem 'json' ActiveSupport::JSON.backend = "JSONGem" class ActiveRecord::Base alias to_json rails_to_json end --- activeresource/lib/active_resource/base.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activeresource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 6cb5beb789..2e742267ba 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -887,9 +887,12 @@ module ActiveResource # person.to_json(:except => ["first_name"]) # # => {"last_name": "Smith"} def to_json(options={}) - attributes.to_json(options) + ActiveSupport::JSON.encode(attributes, options) end + # For compatibility with ActiveSupport::JSON.encode + alias rails_to_json to_json + # Returns the serialized string representation of the resource in the configured # serialization format specified in ActiveResource::Base.format. The options # applicable depend on the configured encoding format. -- cgit v1.2.3 From 6e3e00219b6910ec39b84844c845e0e237ff15a6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 26 Apr 2009 20:25:36 -0700 Subject: Fix differing rails_to_json arity --- activeresource/lib/active_resource/base.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activeresource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 2e742267ba..f9a461d02e 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -890,9 +890,6 @@ module ActiveResource ActiveSupport::JSON.encode(attributes, options) end - # For compatibility with ActiveSupport::JSON.encode - alias rails_to_json to_json - # Returns the serialized string representation of the resource in the configured # serialization format specified in ActiveResource::Base.format. The options # applicable depend on the configured encoding format. @@ -1064,6 +1061,11 @@ module ActiveResource self.class.__send__(:split_options, options) end + # For compatibility with ActiveSupport::JSON.encode + def rails_to_json(options, *args) + to_json(options) + end + def method_missing(method_symbol, *arguments) #:nodoc: method_name = method_symbol.to_s -- cgit v1.2.3 From a05cfb6df5336aa0369e6b27294dae3c418a75c6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 5 May 2009 21:44:02 -0700 Subject: Prefer sibling Active Support --- activeresource/lib/active_resource.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'activeresource') diff --git a/activeresource/lib/active_resource.rb b/activeresource/lib/active_resource.rb index 2f0c8d1a8e..7a3faf445a 100644 --- a/activeresource/lib/active_resource.rb +++ b/activeresource/lib/active_resource.rb @@ -21,15 +21,9 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ -begin - require 'active_support' -rescue LoadError - activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib" - if File.directory?(activesupport_path) - $:.unshift activesupport_path - require 'active_support' - end -end +activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib" +$:.unshift(activesupport_path) if File.directory?(activesupport_path) +require 'active_support' require 'active_support/core/all' require 'active_resource/formats' -- cgit v1.2.3 From c585e263ab40101eb0fd71a1d24d0d704f4ce026 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 5 May 2009 21:50:53 -0700 Subject: Remove superfluous CGI require --- activeresource/lib/active_resource/base.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activeresource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index f9a461d02e..590d4f6232 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1,5 +1,4 @@ require 'active_resource/connection' -require 'cgi' require 'set' module ActiveResource -- cgit v1.2.3 From 6d4a4fabbbb04c20cee51c4e374045cc75e2ec16 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 6 May 2009 00:14:55 -0700 Subject: Cherry pick Active Support dependencies. Autoload. --- activeresource/lib/active_resource.rb | 11 +--- activeresource/lib/active_resource/base.rb | 16 ++++-- activeresource/lib/active_resource/connection.rb | 60 ++-------------------- .../lib/active_resource/custom_methods.rb | 4 ++ activeresource/lib/active_resource/exceptions.rb | 55 ++++++++++++++++++++ activeresource/lib/active_resource/formats.rb | 8 +-- .../lib/active_resource/formats/xml_format.rb | 2 + activeresource/lib/active_resource/http_mock.rb | 7 ++- activeresource/lib/active_resource/validations.rb | 7 +++ activeresource/test/abstract_unit.rb | 9 ++-- activeresource/test/base_test.rb | 2 +- 11 files changed, 100 insertions(+), 81 deletions(-) create mode 100644 activeresource/lib/active_resource/exceptions.rb (limited to 'activeresource') diff --git a/activeresource/lib/active_resource.rb b/activeresource/lib/active_resource.rb index 7a3faf445a..720abee72e 100644 --- a/activeresource/lib/active_resource.rb +++ b/activeresource/lib/active_resource.rb @@ -24,16 +24,7 @@ activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib" $:.unshift(activesupport_path) if File.directory?(activesupport_path) require 'active_support' -require 'active_support/core/all' - -require 'active_resource/formats' -require 'active_resource/base' -require 'active_resource/validations' -require 'active_resource/custom_methods' module ActiveResource - Base.class_eval do - include Validations - include CustomMethods - end + autoload :Base, 'active_resource/base' end diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 590d4f6232..be022f5c44 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1,7 +1,14 @@ -require 'active_resource/connection' +require 'active_support/core_ext/class/attribute_accessors' +require 'active_support/core_ext/class/inheritable_attributes' +require 'active_support/core_ext/module/attr_accessor_with_default' +require 'active_support/core_ext/module/delegation' +require 'active_support/core_ext/module/aliasing' require 'set' module ActiveResource + autoload :Formats, 'active_resource/formats' + autoload :Connection, 'active_resource/connection' + # ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application. # # For an outline of what Active Resource is capable of, see link:files/vendor/rails/activeresource/README.html. @@ -297,7 +304,7 @@ module ActiveResource # Returns the current format, default is ActiveResource::Formats::XmlFormat. def format - read_inheritable_attribute(:format) || ActiveResource::Formats[:xml] + read_inheritable_attribute(:format) || ActiveResource::Formats::XmlFormat end # Sets the number of seconds after which requests to the REST API should time out. @@ -894,7 +901,7 @@ module ActiveResource # applicable depend on the configured encoding format. def encode(options={}) case self.class.format - when ActiveResource::Formats[:xml] + when ActiveResource::Formats::XmlFormat self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options)) else self.class.format.encode(attributes, options) @@ -1079,3 +1086,6 @@ module ActiveResource end end end + +require 'active_resource/validations' +require 'active_resource/custom_methods' diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 80d5c95b68..6661469c5b 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -1,64 +1,12 @@ +require 'active_resource/exceptions' +require 'active_resource/formats' +require 'active_support/core_ext/benchmark' require 'net/https' require 'date' require 'time' require 'uri' -require 'benchmark' module ActiveResource - class ConnectionError < StandardError # :nodoc: - attr_reader :response - - def initialize(response, message = nil) - @response = response - @message = message - end - - def to_s - "Failed with #{response.code} #{response.message if response.respond_to?(:message)}" - end - end - - # Raised when a Timeout::Error occurs. - class TimeoutError < ConnectionError - def initialize(message) - @message = message - end - def to_s; @message ;end - end - - # 3xx Redirection - class Redirection < ConnectionError # :nodoc: - def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end - end - - # 4xx Client Error - class ClientError < ConnectionError; end # :nodoc: - - # 400 Bad Request - class BadRequest < ClientError; end # :nodoc - - # 401 Unauthorized - class UnauthorizedAccess < ClientError; end # :nodoc - - # 403 Forbidden - class ForbiddenAccess < ClientError; end # :nodoc - - # 404 Not Found - class ResourceNotFound < ClientError; end # :nodoc: - - # 409 Conflict - class ResourceConflict < ClientError; end # :nodoc: - - # 5xx Server Error - class ServerError < ConnectionError; end # :nodoc: - - # 405 Method Not Allowed - class MethodNotAllowed < ClientError # :nodoc: - def allowed_methods - @response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym } - end - end - # Class to handle connections to remote web services. # This class is used by ActiveResource::Base to interface with REST # services. @@ -81,7 +29,7 @@ module ActiveResource # The +site+ parameter is required and will set the +site+ # attribute to the URI for the remote resource service. - def initialize(site, format = ActiveResource::Formats[:xml]) + def initialize(site, format = ActiveResource::Formats::XmlFormat) raise ArgumentError, 'Missing site URI' unless site @user = @password = nil self.site = site diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index 4647e8342c..0d05d06035 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -117,4 +117,8 @@ module ActiveResource end end end + + class Base + include CustomMethods + end end diff --git a/activeresource/lib/active_resource/exceptions.rb b/activeresource/lib/active_resource/exceptions.rb new file mode 100644 index 0000000000..5e4b1d4487 --- /dev/null +++ b/activeresource/lib/active_resource/exceptions.rb @@ -0,0 +1,55 @@ +module ActiveResource + class ConnectionError < StandardError # :nodoc: + attr_reader :response + + def initialize(response, message = nil) + @response = response + @message = message + end + + def to_s + "Failed with #{response.code} #{response.message if response.respond_to?(:message)}" + end + end + + # Raised when a Timeout::Error occurs. + class TimeoutError < ConnectionError + def initialize(message) + @message = message + end + def to_s; @message ;end + end + + # 3xx Redirection + class Redirection < ConnectionError # :nodoc: + def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end + end + + # 4xx Client Error + class ClientError < ConnectionError; end # :nodoc: + + # 400 Bad Request + class BadRequest < ClientError; end # :nodoc + + # 401 Unauthorized + class UnauthorizedAccess < ClientError; end # :nodoc + + # 403 Forbidden + class ForbiddenAccess < ClientError; end # :nodoc + + # 404 Not Found + class ResourceNotFound < ClientError; end # :nodoc: + + # 409 Conflict + class ResourceConflict < ClientError; end # :nodoc: + + # 5xx Server Error + class ServerError < ConnectionError; end # :nodoc: + + # 405 Method Not Allowed + class MethodNotAllowed < ClientError # :nodoc: + def allowed_methods + @response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym } + end + end +end diff --git a/activeresource/lib/active_resource/formats.rb b/activeresource/lib/active_resource/formats.rb index 28864cf588..53b75b34e7 100644 --- a/activeresource/lib/active_resource/formats.rb +++ b/activeresource/lib/active_resource/formats.rb @@ -1,14 +1,14 @@ module ActiveResource module Formats + autoload :XmlFormat, 'active_resource/formats/xml_format' + autoload :JsonFormat, 'active_resource/formats/json_format' + # Lookup the format class from a mime type reference symbol. Example: # # ActiveResource::Formats[:xml] # => ActiveResource::Formats::XmlFormat # ActiveResource::Formats[:json] # => ActiveResource::Formats::JsonFormat def self.[](mime_type_reference) - ActiveResource::Formats.const_get(mime_type_reference.to_s.camelize + "Format") + ActiveResource::Formats.const_get(ActiveSupport::Inflector.camelize(mime_type_reference.to_s) + "Format") end end end - -require 'active_resource/formats/xml_format' -require 'active_resource/formats/json_format' \ No newline at end of file diff --git a/activeresource/lib/active_resource/formats/xml_format.rb b/activeresource/lib/active_resource/formats/xml_format.rb index 86c6cec745..3b2575cfa1 100644 --- a/activeresource/lib/active_resource/formats/xml_format.rb +++ b/activeresource/lib/active_resource/formats/xml_format.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/hash/conversions' + module ActiveResource module Formats module XmlFormat diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb index 7d7e378436..aae2d6508c 100644 --- a/activeresource/lib/active_resource/http_mock.rb +++ b/activeresource/lib/active_resource/http_mock.rb @@ -1,4 +1,5 @@ require 'active_resource/connection' +require 'active_support/core_ext/kernel/reporting' module ActiveResource class InvalidRequestError < StandardError; end #:nodoc: @@ -129,7 +130,11 @@ module ActiveResource def #{method}(path, #{'body, ' if has_body}headers) request = ActiveResource::Request.new(:#{method}, path, #{has_body ? 'body, ' : 'nil, '}headers) self.class.requests << request - self.class.responses.assoc(request).try(:second) || raise(InvalidRequestError.new("No response recorded for \#{request}")) + if response = self.class.responses.assoc(request) + response[1] + else + raise InvalidRequestError.new("No response recorded for \#{request}") + end end EOE end diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb index 8d21f8adbb..da6084fe9f 100644 --- a/activeresource/lib/active_resource/validations.rb +++ b/activeresource/lib/active_resource/validations.rb @@ -1,3 +1,6 @@ +require 'active_resource/exceptions' +require 'active_support/core_ext/array/wrap' + module ActiveResource class ResourceInvalid < ClientError #:nodoc: end @@ -272,4 +275,8 @@ module ActiveResource @errors ||= Errors.new(self) end end + + class Base + include Validations + end end diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb index 0f11ea482a..3398f2dac7 100644 --- a/activeresource/test/abstract_unit.rb +++ b/activeresource/test/abstract_unit.rb @@ -5,19 +5,16 @@ gem 'mocha', '>= 0.9.5' require 'mocha' $:.unshift "#{File.dirname(__FILE__)}/../lib" -$:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib" require 'active_resource' require 'active_resource/http_mock' $:.unshift "#{File.dirname(__FILE__)}/../test" require 'setter_trap' +require 'logger' ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log") -def uses_gem(gem_name, test_name, version = '> 0') - gem gem_name.to_s, version - require gem_name.to_s - yield +begin + require 'ruby-debug' rescue LoadError - $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again." end diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index 6ed6f1a406..a6cef6b2ae 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -853,7 +853,7 @@ class BaseTest < Test::Unit::TestCase def test_to_xml matz = Person.find(1) xml = matz.encode - assert xml.starts_with?('') + assert xml.include?('') assert xml.include?('Matz') assert xml.include?('1') end -- cgit v1.2.3 From 201d8b17552c8c9eb96e2aca2f871e0fd9b96e15 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 6 May 2009 12:19:30 -0700 Subject: Fix tests on 1.8.6 --- activeresource/lib/active_resource/base.rb | 1 + activeresource/test/base/load_test.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'activeresource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index be022f5c44..8a1236c9a8 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -3,6 +3,7 @@ require 'active_support/core_ext/class/inheritable_attributes' require 'active_support/core_ext/module/attr_accessor_with_default' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/module/aliasing' +require 'active_support/core_ext/object/misc' require 'set' module ActiveResource diff --git a/activeresource/test/base/load_test.rb b/activeresource/test/base/load_test.rb index a475fab34e..cd2103acb7 100644 --- a/activeresource/test/base/load_test.rb +++ b/activeresource/test/base/load_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require "fixtures/person" require "fixtures/street_address" +require 'active_support/core_ext/symbol' module Highrise class Note < ActiveResource::Base -- cgit v1.2.3 From 49ed45213607ed6ce7e6c13c319bf55f916a0ac4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 7 May 2009 18:27:50 -0700 Subject: Defer rake/contrib/sshpublisher require so basic tasks don't need the full rake gem --- activeresource/Rakefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activeresource') diff --git a/activeresource/Rakefile b/activeresource/Rakefile index bf7bbb0201..c3cde26b6c 100644 --- a/activeresource/Rakefile +++ b/activeresource/Rakefile @@ -4,7 +4,6 @@ require 'rake/testtask' require 'rake/rdoctask' require 'rake/packagetask' require 'rake/gempackagetask' -require 'rake/contrib/sshpublisher' require File.join(File.dirname(__FILE__), 'lib', 'active_resource', 'version') @@ -117,12 +116,14 @@ end desc "Publish the beta gem" task :pgem => [:package] do + require 'rake/contrib/sshpublisher' Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload `ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'` end desc "Publish the API documentation" task :pdoc => [:rdoc] do + require 'rake/contrib/sshpublisher' Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/ar", "doc").upload end -- cgit v1.2.3 From e8550ee0329586b32de425e905c7af7e65bc78a8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 13 May 2009 01:10:37 -0700 Subject: Cherry-pick core extensions --- activeresource/Rakefile | 7 +++++++ activeresource/lib/active_resource/base.rb | 4 +++- activeresource/test/base/custom_methods_test.rb | 1 + activeresource/test/base/load_test.rb | 1 + activeresource/test/base_test.rb | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) (limited to 'activeresource') diff --git a/activeresource/Rakefile b/activeresource/Rakefile index c3cde26b6c..eb5b1dd1ac 100644 --- a/activeresource/Rakefile +++ b/activeresource/Rakefile @@ -34,6 +34,13 @@ Rake::TestTask.new { |t| t.verbose = true t.warning = true } +task :isolated_test do + ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) + activesupport_path = "#{File.dirname(__FILE__)}/../activesupport/lib" + Dir.glob("test/**/*_test.rb").all? do |file| + system(ruby, "-Ilib:test:#{activesupport_path}", file) + end or raise "Failures" +end # Generate the RDoc documentation diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 8a1236c9a8..dc24e713ff 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1,8 +1,10 @@ +require 'active_support' require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/inheritable_attributes' require 'active_support/core_ext/module/attr_accessor_with_default' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/module/aliasing' +require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/misc' require 'set' @@ -1027,7 +1029,7 @@ module ActiveResource private # Tries to find a resource for a given collection name; if it fails, then the resource is created def find_or_create_resource_for_collection(name) - find_or_create_resource_for(name.to_s.singularize) + find_or_create_resource_for(ActiveSupport::Inflector.singularize(name.to_s)) end # Tries to find a resource in a non empty list of nested modules diff --git a/activeresource/test/base/custom_methods_test.rb b/activeresource/test/base/custom_methods_test.rb index 61887f4ec7..2d81549a65 100644 --- a/activeresource/test/base/custom_methods_test.rb +++ b/activeresource/test/base/custom_methods_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require 'fixtures/person' require 'fixtures/street_address' +require 'active_support/core_ext/hash/conversions' class CustomMethodsTest < Test::Unit::TestCase def setup diff --git a/activeresource/test/base/load_test.rb b/activeresource/test/base/load_test.rb index cd2103acb7..035bd965c2 100644 --- a/activeresource/test/base/load_test.rb +++ b/activeresource/test/base/load_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' require "fixtures/person" require "fixtures/street_address" require 'active_support/core_ext/symbol' +require 'active_support/core_ext/hash/conversions' module Highrise class Note < ActiveResource::Base diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index a6cef6b2ae..82d3b2ae96 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -3,6 +3,7 @@ require "fixtures/person" require "fixtures/customer" require "fixtures/street_address" require "fixtures/beast" +require 'active_support/core_ext/hash/conversions' class BaseTest < Test::Unit::TestCase def setup -- cgit v1.2.3 From 4f291fa528e5faad03def69ae7ac98224ab859db Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 13 May 2009 11:55:19 -0700 Subject: Simple examples for require profiling --- activeresource/examples/simple.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 activeresource/examples/simple.rb (limited to 'activeresource') diff --git a/activeresource/examples/simple.rb b/activeresource/examples/simple.rb new file mode 100644 index 0000000000..b20ef61670 --- /dev/null +++ b/activeresource/examples/simple.rb @@ -0,0 +1,16 @@ +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +require 'active_resource' +require 'active_resource/http_mock' +require 'active_support/core_ext/hash/conversions' + +ActiveSupport::XmlMini.backend = ENV['XMLMINI'] || 'REXML' +ActiveResource::HttpMock.respond_to do |mock| + mock.get '/people/1.xml', {}, { :id => 1, :name => 'bob' }.to_xml(:root => 'person') +end + +class Person < ActiveResource::Base + self.site = 'http://localhost/' +end + +bob = Person.find(1) +puts bob.inspect -- cgit v1.2.3