diff options
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 4 | ||||
-rw-r--r-- | activeresource/lib/active_resource/custom_methods.rb | 24 | ||||
-rw-r--r-- | activeresource/lib/active_resource/http_mock.rb | 2 | ||||
-rw-r--r-- | activeresource/test/authorization_test.rb | 8 | ||||
-rw-r--r-- | activeresource/test/base/load_test.rb | 6 | ||||
-rw-r--r-- | activeresource/test/base_errors_test.rb | 6 | ||||
-rw-r--r-- | activeresource/test/base_test.rb | 13 | ||||
-rw-r--r-- | activeresource/test/connection_test.rb | 4 | ||||
-rw-r--r-- | activeresource/test/fixtures/person.rb | 2 |
9 files changed, 35 insertions, 34 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index d99a047df1..9fb347d2c3 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -604,7 +604,7 @@ module ActiveResource # next_invoice.customer # # => That Company def dup - returning new do |resource| + returning self.class.new do |resource| resource.attributes = @attributes resource.prefix_options = @prefix_options end @@ -848,7 +848,7 @@ module ActiveResource end def split_options(options = {}) - self.class.send(:split_options, options) + self.class.send!(:split_options, options) end def method_missing(method_symbol, *arguments) #:nodoc: diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index a8857b8461..e08c664307 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -33,23 +33,24 @@ module ActiveResource module CustomMethods def self.included(within) within.class_eval do + extend ActiveResource::CustomMethods::ClassMethods + include ActiveResource::CustomMethods::InstanceMethods + class << self - include ActiveResource::CustomMethods::ClassMethods - alias :orig_delete :delete - + def get(method_name, options = {}) connection.get(custom_method_collection_url(method_name, options), headers) end - + def post(method_name, options = {}, body = '') connection.post(custom_method_collection_url(method_name, options), body, headers) end - + def put(method_name, options = {}, body = '') connection.put(custom_method_collection_url(method_name, options), body, headers) end - + # Need to jump through some hoops to retain the original class 'delete' method def delete(custom_method_name, options = {}) if (custom_method_name.is_a?(Symbol)) @@ -59,12 +60,9 @@ module ActiveResource end end end - end - - within.send(:include, ActiveResource::CustomMethods::InstanceMethods) end - + module ClassMethods def custom_method_collection_url(method_name, options = {}) prefix_options, query_options = split_options(options) @@ -96,12 +94,12 @@ module ActiveResource private def custom_method_element_url(method_name, options = {}) - "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.xml#{self.class.send(:query_string, options)}" + "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.xml#{self.class.send!(:query_string, options)}" end def custom_method_new_element_url(method_name, options = {}) - "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.xml#{self.class.send(:query_string, options)}" + "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.xml#{self.class.send!(:query_string, options)}" end end end -end
\ No newline at end of file +end diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb index c9a2c21f31..37fc1f2bfe 100644 --- a/activeresource/lib/active_resource/http_mock.rb +++ b/activeresource/lib/active_resource/http_mock.rb @@ -75,7 +75,7 @@ module ActiveResource attr_accessor :path, :method, :body, :headers def initialize(method, path, body = nil, headers = {}) - @method, @path, @body, @headers = method, path, body, headers + @method, @path, @body, @headers = method, path, body, headers.dup @headers.update('Content-Type' => 'application/xml') end diff --git a/activeresource/test/authorization_test.rb b/activeresource/test/authorization_test.rb index 1a1a681a59..58bd36cb77 100644 --- a/activeresource/test/authorization_test.rb +++ b/activeresource/test/authorization_test.rb @@ -20,7 +20,7 @@ class AuthorizationTest < Test::Unit::TestCase end def test_authorization_header - authorization_header = @authenticated_conn.send(:authorization_header) + authorization_header = @authenticated_conn.send!(:authorization_header) assert_equal @authorization_request_header['Authorization'], authorization_header['Authorization'] authorization = authorization_header["Authorization"].to_s.split @@ -30,7 +30,7 @@ class AuthorizationTest < Test::Unit::TestCase def test_authorization_header_with_username_but_no_password @conn = ActiveResource::Connection.new("http://david:@localhost") - authorization_header = @conn.send(:authorization_header) + authorization_header = @conn.send!(:authorization_header) authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] @@ -39,7 +39,7 @@ class AuthorizationTest < Test::Unit::TestCase def test_authorization_header_with_password_but_no_username @conn = ActiveResource::Connection.new("http://:test123@localhost") - authorization_header = @conn.send(:authorization_header) + authorization_header = @conn.send!(:authorization_header) authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] @@ -76,7 +76,7 @@ class AuthorizationTest < Test::Unit::TestCase protected def assert_response_raises(klass, code) assert_raise(klass, "Expected response code #{code} to raise #{klass}") do - @conn.send(:handle_response, Response.new(code)) + @conn.send!(:handle_response, Response.new(code)) end end end diff --git a/activeresource/test/base/load_test.rb b/activeresource/test/base/load_test.rb index 28f1cfc97c..622afb2fdf 100644 --- a/activeresource/test/base/load_test.rb +++ b/activeresource/test/base/load_test.rb @@ -61,7 +61,7 @@ class BaseLoadTest < Test::Unit::TestCase end def test_load_collection_with_unknown_resource - Person.send(:remove_const, :Address) if Person.const_defined?(:Address) + Person.send!(:remove_const, :Address) if Person.const_defined?(:Address) assert !Person.const_defined?(:Address), "Address shouldn't exist until autocreated" addresses = silence_warnings { @person.load(:addresses => @addresses).addresses } assert Person.const_defined?(:Address), "Address should have been autocreated" @@ -77,7 +77,7 @@ class BaseLoadTest < Test::Unit::TestCase end def test_load_collection_with_single_unknown_resource - Person.send(:remove_const, :Address) if Person.const_defined?(:Address) + Person.send!(:remove_const, :Address) if Person.const_defined?(:Address) assert !Person.const_defined?(:Address), "Address shouldn't exist until autocreated" addresses = silence_warnings { @person.load(:addresses => [ @first_address ]).addresses } assert Person.const_defined?(:Address), "Address should have been autocreated" @@ -108,4 +108,4 @@ class BaseLoadTest < Test::Unit::TestCase n = Highrise::Note.new(:comments => [{ :name => "1" }]) assert_kind_of Highrise::Comment, n.comments.first end -end
\ No newline at end of file +end diff --git a/activeresource/test/base_errors_test.rb b/activeresource/test/base_errors_test.rb index f9aa58016d..8706326b13 100644 --- a/activeresource/test/base_errors_test.rb +++ b/activeresource/test/base_errors_test.rb @@ -29,13 +29,13 @@ class BaseErrorsTest < Test::Unit::TestCase def test_should_iterate_over_errors errors = [] @person.errors.each { |attribute, message| errors << [attribute, message] } - assert_equal ["name", "can't be blank"], errors.first + assert errors.include?(["name", "can't be blank"]) end def test_should_iterate_over_full_errors errors = [] @person.errors.each_full { |message| errors << message } - assert_equal "Name can't be blank", errors.first + assert errors.include?("Name can't be blank") end def test_should_format_full_errors @@ -45,4 +45,4 @@ class BaseErrorsTest < Test::Unit::TestCase assert full.include?("Name must start with a letter") assert full.include?("Person quota full for today.") end -end
\ No newline at end of file +end diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index a1051e5875..f97b08295a 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -181,7 +181,7 @@ class BaseTest < Test::Unit::TestCase def test_prefix assert_equal "/", Person.prefix - assert_equal Set.new, Person.send(:prefix_parameters) + assert_equal Set.new, Person.send!(:prefix_parameters) end def test_set_prefix @@ -208,7 +208,7 @@ class BaseTest < Test::Unit::TestCase def test_custom_prefix assert_equal '/people//', StreetAddress.prefix assert_equal '/people/1/', StreetAddress.prefix(:person_id => 1) - assert_equal [:person_id].to_set, StreetAddress.send(:prefix_parameters) + assert_equal [:person_id].to_set, StreetAddress.send!(:prefix_parameters) end def test_find_by_id @@ -305,10 +305,10 @@ class BaseTest < Test::Unit::TestCase def test_id_from_response p = Person.new resp = {'Location' => '/foo/bar/1'} - assert_equal '1', p.send(:id_from_response, resp) + assert_equal '1', p.send!(:id_from_response, resp) resp['Location'] << '.xml' - assert_equal '1', p.send(:id_from_response, resp) + assert_equal '1', p.send!(:id_from_response, resp) end def test_create_with_custom_prefix @@ -439,6 +439,9 @@ class BaseTest < Test::Unit::TestCase def test_to_xml matz = Person.find(1) - assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n <name>Matz</name>\n <id type=\"integer\">1</id>\n</person>\n", matz.to_xml + xml = matz.to_xml + assert xml.starts_with?('<?xml version="1.0" encoding="UTF-8"?>') + assert xml.include?('<name>Matz</name>') + assert xml.include?('<id type="integer">1</id>') end end diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index 68d57018bf..09e80f95c1 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -13,7 +13,7 @@ class ConnectionTest < Test::Unit::TestCase @people_empty = [ ].to_xml(:root => 'people-empty-elements') @matz = @matz.to_xml(:root => 'person') @david = @david.to_xml(:root => 'person') - @header = {'key' => 'value'} + @header = {'key' => 'value'}.freeze @default_request_headers = { 'Content-Type' => 'application/xml' } ActiveResource::HttpMock.respond_to do |mock| @@ -156,6 +156,6 @@ class ConnectionTest < Test::Unit::TestCase end def handle_response(response) - @conn.send(:handle_response, response) + @conn.send!(:handle_response, response) end end diff --git a/activeresource/test/fixtures/person.rb b/activeresource/test/fixtures/person.rb index 8e5768586a..e88bb69310 100644 --- a/activeresource/test/fixtures/person.rb +++ b/activeresource/test/fixtures/person.rb @@ -1,3 +1,3 @@ class Person < ActiveResource::Base self.site = "http://37s.sunrise.i:3000" -end
\ No newline at end of file +end |