From 582a7f459990487659886b90e54c22e055c65870 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 25 Aug 2012 01:20:51 +0200 Subject: [PATCH] Deprecate Template#mime_type --- actionpack/lib/action_view/template.rb | 6 ++++++ actionpack/test/template/template_test.rb | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index c36b06a83d..379cdc8a25 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/object/try' require 'active_support/core_ext/kernel/singleton_class' +require 'active_support/deprecation' require 'thread' module ActionView @@ -147,6 +148,11 @@ module ActionView handle_render_error(view, e) end + def mime_type + ActiveSupport::Deprecation.warn 'Template#mime_type is deprecated and will be removed in Rails 4.1. Please use type method instead.' + @mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first + end + def type @type ||= Types[@formats.first] if @formats.first end diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 061f5bb53f..86ba5f3b4d 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -59,6 +59,13 @@ class TestERBTemplate < ActiveSupport::TestCase @context = Context.new end + def test_mime_type_is_deprecated + template = new_template + assert_deprecated 'Template#mime_type is deprecated and will be removed' do + template.mime_type + end + end + def test_basic_template @template = new_template assert_equal "Hello", render