Skip to content

Commit

Permalink
Merge pull request #3810 from lest/fix-warnings
Browse files Browse the repository at this point in the history
fix method redefined warnings in tests
  • Loading branch information
josevalim committed Nov 30, 2011
2 parents 2b96b20 + 6ce924f commit 3b07bb3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 40 deletions.
5 changes: 5 additions & 0 deletions actionpack/test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,8 @@ def stderr_logger
end
end

module RoutingTestHelpers
def url_for(set, options, recall = nil)
set.send(:url_for, options.merge(:only_path => true, :_path_segments => recall))
end
end
6 changes: 0 additions & 6 deletions actionpack/test/controller/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ def rescue_action(e) raise e end

ROUTING = ActionDispatch::Routing

module RoutingTestHelpers
def url_for(set, options, recall = nil)
set.send(:url_for, options.merge(:only_path => true, :_path_segments => recall))
end
end

# See RFC 3986, section 3.3 for allowed path characters.
class UriReservedCharactersRoutingTest < Test::Unit::TestCase
include RoutingTestHelpers
Expand Down
6 changes: 0 additions & 6 deletions actionpack/test/controller/url_for_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
require 'controller/fake_controllers'
require 'active_support/core_ext/object/with_options'

module RoutingTestHelpers
def url_for(set, options, recall = nil)
set.send(:url_for, options.merge(:only_path => true, :_path_segments => recall))
end
end

module ActionPack
class URLForIntegrationTest < ActiveSupport::TestCase
include RoutingTestHelpers
Expand Down
4 changes: 3 additions & 1 deletion activemodel/test/cases/serializable/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def attributes=(hash)
end
end

remove_method :attributes if method_defined?(:attributes)

def attributes
instance_values
end unless method_defined?(:attributes)
end
end

class JsonSerializationTest < ActiveModel::TestCase
Expand Down
2 changes: 2 additions & 0 deletions activemodel/test/cases/serializable/xml_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Contact

attr_accessor :address, :friends

remove_method :attributes if method_defined?(:attributes)

def attributes
instance_values.except("address", "friends")
end
Expand Down
4 changes: 2 additions & 2 deletions activeresource/lib/active_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ class Base
extend ActiveModel::Naming
include CustomMethods, Observing, Validations
include ActiveModel::Conversion
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
include ActiveModel::Serializable::JSON
include ActiveModel::Serializable::XML
end
end
48 changes: 23 additions & 25 deletions activeresource/lib/active_resource/custom_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,37 +85,35 @@ def custom_method_collection_url(method_name, options = {})
end
end

module InstanceMethods
def get(method_name, options = {})
self.class.format.decode(connection.get(custom_method_element_url(method_name, options), self.class.headers).body)
end
def get(method_name, options = {})
self.class.format.decode(connection.get(custom_method_element_url(method_name, options), self.class.headers).body)
end

def post(method_name, options = {}, body = nil)
request_body = body.blank? ? encode : body
if new?
connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers)
else
connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers)
end
def post(method_name, options = {}, body = nil)
request_body = body.blank? ? encode : body
if new?
connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers)
else
connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers)
end
end

def put(method_name, options = {}, body = '')
connection.put(custom_method_element_url(method_name, options), body, self.class.headers)
end
def put(method_name, options = {}, body = '')
connection.put(custom_method_element_url(method_name, options), body, self.class.headers)
end

def delete(method_name, options = {})
connection.delete(custom_method_element_url(method_name, options), self.class.headers)
end
def delete(method_name, options = {})
connection.delete(custom_method_element_url(method_name, options), self.class.headers)
end


private
def custom_method_element_url(method_name, options = {})
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}"
end
private
def custom_method_element_url(method_name, options = {})
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.#{self.class.format.extension}#{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}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}"
end
end
def custom_method_new_element_url(method_name, options = {})
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}"
end
end
end

0 comments on commit 3b07bb3

Please sign in to comment.