mirror of https://github.com/rails/rails
Rename new method to_path to to_partial_path to avoid conflicts with File#to_path and similar.
This commit is contained in:
parent
d701b3fa47
commit
dc8773b19f
|
@ -1227,12 +1227,12 @@ module ActionView
|
|||
parent_builder.multipart = multipart if parent_builder
|
||||
end
|
||||
|
||||
def self._to_path
|
||||
@_to_path ||= name.demodulize.underscore.sub!(/_builder$/, '')
|
||||
def self._to_partial_path
|
||||
@_to_partial_path ||= name.demodulize.underscore.sub!(/_builder$/, '')
|
||||
end
|
||||
|
||||
def to_path
|
||||
self.class._to_path
|
||||
def to_partial_path
|
||||
self.class._to_partial_path
|
||||
end
|
||||
|
||||
def to_model
|
||||
|
|
|
@ -364,10 +364,10 @@ module ActionView
|
|||
def partial_path(object = @object)
|
||||
object = object.to_model if object.respond_to?(:to_model)
|
||||
|
||||
path = if object.respond_to?(:to_path)
|
||||
object.to_path
|
||||
path = if object.respond_to?(:to_partial_path)
|
||||
object.to_partial_path
|
||||
else
|
||||
ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead."
|
||||
ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_partial_path directly instead."
|
||||
object.class.model_name.partial_path
|
||||
end
|
||||
|
||||
|
|
|
@ -1895,7 +1895,7 @@ class FormHelperTest < ActionView::TestCase
|
|||
path = nil
|
||||
|
||||
form_for(@post, :builder => LabelledFormBuilder) do |f|
|
||||
path = f.to_path
|
||||
path = f.to_partial_path
|
||||
''
|
||||
end
|
||||
|
||||
|
|
|
@ -214,14 +214,14 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_partial_using_object_with_deprecated_partial_path
|
||||
assert_deprecated(/#model_name.*#partial_path.*#to_path/) do
|
||||
assert_deprecated(/#model_name.*#partial_path.*#to_partial_path/) do
|
||||
assert_equal "Hello: nertzy",
|
||||
@controller_view.render(CustomerWithDeprecatedPartialPath.new("nertzy"), :greeting => "Hello")
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_partial_using_collection_with_deprecated_partial_path
|
||||
assert_deprecated(/#model_name.*#partial_path.*#to_path/) do
|
||||
assert_deprecated(/#model_name.*#partial_path.*#to_partial_path/) do
|
||||
customers = [
|
||||
CustomerWithDeprecatedPartialPath.new("nertzy"),
|
||||
CustomerWithDeprecatedPartialPath.new("peeja")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
* Deprecate "Model.model_name.partial_path" in favor of "model.to_path" [Grant Hutchins, Peter Jaros]
|
||||
* Deprecate "Model.model_name.partial_path" in favor of "model.to_partial_path" [Grant Hutchins, Peter Jaros]
|
||||
|
||||
* Provide mass_assignment_sanitizer as an easy API to replace the sanitizer behavior. Also support both :logger (default) and :strict sanitizer behavior [Bogdan Gusiev]
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'active_support/inflector'
|
|||
module ActiveModel
|
||||
# == Active Model Conversions
|
||||
#
|
||||
# Handles default conversions: to_model, to_key, to_param, and to_path.
|
||||
# Handles default conversions: to_model, to_key, to_param, and to_partial_path.
|
||||
#
|
||||
# Let's take for example this non-persisted object.
|
||||
#
|
||||
|
@ -54,15 +54,15 @@ module ActiveModel
|
|||
|
||||
# Returns a string identifying the path associated with the object.
|
||||
# ActionPack uses this to find a suitable partial to represent the object.
|
||||
def to_path
|
||||
self.class._to_path
|
||||
def to_partial_path
|
||||
self.class._to_partial_path
|
||||
end
|
||||
|
||||
module ClassMethods #:nodoc:
|
||||
# Provide a class level cache for the to_path. This is an
|
||||
# internal method and should not be accessed directly.
|
||||
def _to_path #:nodoc:
|
||||
@_to_path ||= begin
|
||||
def _to_partial_path #:nodoc:
|
||||
@_to_partial_path ||= begin
|
||||
element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self))
|
||||
collection = ActiveSupport::Inflector.tableize(self)
|
||||
"#{collection}/#{element}".freeze
|
||||
|
|
|
@ -43,14 +43,14 @@ module ActiveModel
|
|||
assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false"
|
||||
end
|
||||
|
||||
# == Responds to <tt>to_path</tt>
|
||||
# == Responds to <tt>to_partial_path</tt>
|
||||
#
|
||||
# Returns a string giving a relative path. This is used for looking up
|
||||
# partials. For example, a BlogPost model might return "blog_posts/blog_post"
|
||||
#
|
||||
def test_to_path
|
||||
assert model.respond_to?(:to_path), "The model should respond to to_path"
|
||||
assert_kind_of String, model.to_path
|
||||
def test_to_partial_path
|
||||
assert model.respond_to?(:to_partial_path), "The model should respond to to_partial_path"
|
||||
assert_kind_of String, model.to_partial_path
|
||||
end
|
||||
|
||||
# == Responds to <tt>valid?</tt>
|
||||
|
|
|
@ -8,7 +8,7 @@ module ActiveModel
|
|||
attr_reader :singular, :plural, :element, :collection, :partial_path, :route_key, :param_key, :i18n_key
|
||||
alias_method :cache_key, :collection
|
||||
|
||||
deprecate :partial_path => "ActiveModel::Name#partial_path is deprecated. Call #to_path on model instances directly instead."
|
||||
deprecate :partial_path => "ActiveModel::Name#partial_path is deprecated. Call #to_partial_path on model instances directly instead."
|
||||
|
||||
def initialize(klass, namespace = nil, name = nil)
|
||||
name ||= klass.name
|
||||
|
|
|
@ -25,8 +25,8 @@ class ConversionTest < ActiveModel::TestCase
|
|||
end
|
||||
|
||||
test "to_path default implementation returns a string giving a relative path" do
|
||||
assert_equal "contacts/contact", Contact.new.to_path
|
||||
assert_equal "helicopters/helicopter", Helicopter.new.to_path,
|
||||
"ActiveModel::Conversion#to_path caching should be class-specific"
|
||||
assert_equal "contacts/contact", Contact.new.to_partial_path
|
||||
assert_equal "helicopters/helicopter", Helicopter.new.to_partial_path,
|
||||
"ActiveModel::Conversion#to_partial_path caching should be class-specific"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ class NamingTest < ActiveModel::TestCase
|
|||
end
|
||||
|
||||
def test_partial_path
|
||||
assert_deprecated(/#partial_path.*#to_path/) do
|
||||
assert_deprecated(/#partial_path.*#to_partial_path/) do
|
||||
assert_equal 'post/track_backs/track_back', @model_name.partial_path
|
||||
end
|
||||
end
|
||||
|
@ -58,7 +58,7 @@ class NamingWithNamespacedModelInIsolatedNamespaceTest < ActiveModel::TestCase
|
|||
end
|
||||
|
||||
def test_partial_path
|
||||
assert_deprecated(/#partial_path.*#to_path/) do
|
||||
assert_deprecated(/#partial_path.*#to_partial_path/) do
|
||||
assert_equal 'blog/posts/post', @model_name.partial_path
|
||||
end
|
||||
end
|
||||
|
@ -102,7 +102,7 @@ class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase
|
|||
end
|
||||
|
||||
def test_partial_path
|
||||
assert_deprecated(/#partial_path.*#to_path/) do
|
||||
assert_deprecated(/#partial_path.*#to_partial_path/) do
|
||||
assert_equal 'blog/posts/post', @model_name.partial_path
|
||||
end
|
||||
end
|
||||
|
@ -142,7 +142,7 @@ class NamingWithSuppliedModelNameTest < ActiveModel::TestCase
|
|||
end
|
||||
|
||||
def test_partial_path
|
||||
assert_deprecated(/#partial_path.*#to_path/) do
|
||||
assert_deprecated(/#partial_path.*#to_partial_path/) do
|
||||
assert_equal 'articles/article', @model_name.partial_path
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue