From 6e671a8536f17b6f23b5251652015ce8c1557f1f Mon Sep 17 00:00:00 2001 From: Grant Hutchins & Peter Jaros Date: Fri, 8 Jul 2011 17:54:15 -0400 Subject: Let ActiveModel instances define partial paths. Deprecate ActiveModel::Name#partial_path. Now you should call #to_path directly on ActiveModel instances. --- activemodel/test/cases/conversion_test.rb | 9 ++++++++- activemodel/test/cases/naming_test.rb | 16 ++++++++++++---- activemodel/test/models/helicopter.rb | 3 +++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 activemodel/test/models/helicopter.rb (limited to 'activemodel/test') diff --git a/activemodel/test/cases/conversion_test.rb b/activemodel/test/cases/conversion_test.rb index 7669bf5f65..2eccc4e56d 100644 --- a/activemodel/test/cases/conversion_test.rb +++ b/activemodel/test/cases/conversion_test.rb @@ -1,5 +1,6 @@ require 'cases/helper' require 'models/contact' +require 'models/helicopter' class ConversionTest < ActiveModel::TestCase test "to_model default implementation returns self" do @@ -22,4 +23,10 @@ class ConversionTest < ActiveModel::TestCase test "to_param default implementation returns a string of ids for persisted records" do assert_equal "1", Contact.new(:id => 1).to_param end -end \ No newline at end of file + + 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" + end +end diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb index f814fcc56c..bafe4f3c0c 100644 --- a/activemodel/test/cases/naming_test.rb +++ b/activemodel/test/cases/naming_test.rb @@ -26,7 +26,9 @@ class NamingTest < ActiveModel::TestCase end def test_partial_path - assert_equal 'post/track_backs/track_back', @model_name.partial_path + assert_deprecated(/#partial_path.*#to_path/) do + assert_equal 'post/track_backs/track_back', @model_name.partial_path + end end def test_human @@ -56,7 +58,9 @@ class NamingWithNamespacedModelInIsolatedNamespaceTest < ActiveModel::TestCase end def test_partial_path - assert_equal 'blog/posts/post', @model_name.partial_path + assert_deprecated(/#partial_path.*#to_path/) do + assert_equal 'blog/posts/post', @model_name.partial_path + end end def test_human @@ -98,7 +102,9 @@ class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase end def test_partial_path - assert_equal 'blog/posts/post', @model_name.partial_path + assert_deprecated(/#partial_path.*#to_path/) do + assert_equal 'blog/posts/post', @model_name.partial_path + end end def test_human @@ -136,7 +142,9 @@ class NamingWithSuppliedModelNameTest < ActiveModel::TestCase end def test_partial_path - assert_equal 'articles/article', @model_name.partial_path + assert_deprecated(/#partial_path.*#to_path/) do + assert_equal 'articles/article', @model_name.partial_path + end end def test_human diff --git a/activemodel/test/models/helicopter.rb b/activemodel/test/models/helicopter.rb new file mode 100644 index 0000000000..a52b6fb4dd --- /dev/null +++ b/activemodel/test/models/helicopter.rb @@ -0,0 +1,3 @@ +class Helicopter + include ActiveModel::Conversion +end -- cgit v1.2.3