diff options
Diffstat (limited to 'actionpack')
32 files changed, 154 insertions, 88 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 398cdabca2..7873c23030 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 3.2.2 (unreleased) ## +* Format lookup for partials is derived from the format in which the template is being rendered. Closes #5025 part 2 *Santiago Pastorino* + +* Use the right format when a partial is missing. Closes #5025. *Santiago Pastorino* + * Default responder will now always use your overridden block in `respond_with` to render your response. *Prem Sichanugrist* * check_box helper with :disabled => true will generate a disabled hidden field to conform with the HTML convention where disabled fields are not submitted with the form. diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index 80ecc16d53..55de7e7d8e 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -280,7 +280,7 @@ module ActionController #:nodoc: if format self.content_type ||= format.to_s - lookup_context.freeze_formats([format.to_sym]) + lookup_context.formats = [format.to_sym] collector else head :not_acceptable diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 70fd79bb8b..02a2e3db86 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -14,7 +14,7 @@ module ActionController def render(*args) #:nodoc: raise ::AbstractController::DoubleRenderError if response_body super - self.content_type ||= Mime[formats.first].to_s + self.content_type ||= Mime[lookup_context.rendered_format].to_s response_body end diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index 4ad64bff20..daa1ddd65f 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -267,7 +267,7 @@ module ActionController #:nodoc: end def resource_errors - respond_to?("#{format}_resource_errors") ? send("#{format}_resource_errors") : resource.errors + respond_to?("#{format}_resource_errors", true) ? send("#{format}_resource_errors") : resource.errors end def json_resource_errors diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 33eb7b0746..a78e1e13b0 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -267,8 +267,7 @@ module ActionDispatch def eval_block(block) if block.arity == 1 raise "You are using the old router DSL which has been removed in Rails 3.1. " << - "Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/ " << - "or add the rails_legacy_mapper gem to your Gemfile" + "Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/" end mapper = Mapper.new(self) if default_scope diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 3bb2b98e48..33b508e9b5 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -10,7 +10,7 @@ module ActionView # generate a key, given to view paths, used in the resolver cache lookup. Since # this key is generated just once during the request, it speeds up all cache accesses. class LookupContext #:nodoc: - attr_accessor :prefixes + attr_accessor :prefixes, :rendered_format mattr_accessor :fallbacks @@fallbacks = FallbackFileSystemResolver.instances @@ -180,23 +180,15 @@ module ActionView def initialize(view_paths, details = {}, prefixes = []) @details, @details_key = {}, nil - @frozen_formats, @skip_default_locale = false, false + @skip_default_locale = false @cache = true @prefixes = prefixes + @rendered_format = nil self.view_paths = view_paths initialize_details(details) end - # Freeze the current formats in the lookup context. By freezing them, you - # that next template lookups are not going to modify the formats. The con - # use this, to ensure that formats won't be further modified (as it does - def freeze_formats(formats, unless_frozen=false) #:nodoc: - return if unless_frozen && @frozen_formats - self.formats = formats - @frozen_formats = true - end - # Override formats= to expand ["*/*"] values and automatically # add :html as fallback to :js. def formats=(values) diff --git a/actionpack/lib/action_view/renderer/abstract_renderer.rb b/actionpack/lib/action_view/renderer/abstract_renderer.rb index c0936441ac..0b5d3785d4 100644 --- a/actionpack/lib/action_view/renderer/abstract_renderer.rb +++ b/actionpack/lib/action_view/renderer/abstract_renderer.rb @@ -1,7 +1,7 @@ module ActionView class AbstractRenderer #:nodoc: delegate :find_template, :template_exists?, :with_fallbacks, :update_details, - :with_layout_format, :formats, :freeze_formats, :to => :@lookup_context + :with_layout_format, :formats, :to => :@lookup_context def initialize(lookup_context) @lookup_context = lookup_context diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb index adf87a3f7e..ddde990b72 100644 --- a/actionpack/lib/action_view/renderer/template_renderer.rb +++ b/actionpack/lib/action_view/renderer/template_renderer.rb @@ -8,7 +8,8 @@ module ActionView @details = extract_details(options) extract_format(options[:file] || options[:template], @details) template = determine_template(options) - freeze_formats(template.formats, true) + @lookup_context.rendered_format ||= template.formats.first + @lookup_context.formats = template.formats render_template(template, options[:layout], options[:locals]) end diff --git a/actionpack/lib/action_view/template/handlers.rb b/actionpack/lib/action_view/template/handlers.rb index aa693335e3..192e527a7b 100644 --- a/actionpack/lib/action_view/template/handlers.rb +++ b/actionpack/lib/action_view/template/handlers.rb @@ -26,6 +26,7 @@ module ActionView #:nodoc: # return the rendered template as a string. def register_template_handler(extension, klass) @@template_handlers[extension.to_sym] = klass + @@template_extensions = nil end def template_handler_extensions diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index 25f26dd609..ea495ea9ca 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -44,10 +44,6 @@ module ActionView class_attribute :erb_trim_mode self.erb_trim_mode = '-' - # Default format used by ERB. - class_attribute :default_format - self.default_format = Mime::HTML - # Default implementation used. class_attribute :erb_implementation self.erb_implementation = Erubis diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 777ca11d85..6f76ab9596 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -167,7 +167,7 @@ class PerformActionTest < ActionController::TestCase def test_get_on_priv_should_show_selector use_controller MethodMissingController - assert_deprecated /Using `method_missing` to handle .* use `action_missing` instead/ do + assert_deprecated(/Using `method_missing` to handle .* use `action_missing` instead/) do get :shouldnt_be_called end assert_response :success @@ -178,7 +178,7 @@ class PerformActionTest < ActionController::TestCase use_controller MethodMissingController assert !@controller.__send__(:action_method?, 'method_missing') - assert_deprecated /Using `method_missing` to handle .* use `action_missing` instead/ do + assert_deprecated(/Using `method_missing` to handle .* use `action_missing` instead/) do get :method_missing end assert_response :success @@ -187,7 +187,7 @@ class PerformActionTest < ActionController::TestCase def test_method_missing_should_recieve_symbol use_controller AnotherMethodMissingController - assert_deprecated /Using `method_missing` to handle .* use `action_missing` instead/ do + assert_deprecated(/Using `method_missing` to handle .* use `action_missing` instead/) do get :some_action end assert_kind_of NameError, @controller._exception diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index d0dabb29ca..e8e445532a 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -70,7 +70,7 @@ class ContentTypeTest < ActionController::TestCase end def test_render_changed_charset_default - assert_deprecated /Setting default charset at controller.*config\.action_dispatch\.default_charset/ do + assert_deprecated(/Setting default charset at controller.*config\.action_dispatch\.default_charset/) do begin OldContentTypeController.default_charset = "utf-16" get :render_defaults @@ -111,7 +111,7 @@ class ContentTypeTest < ActionController::TestCase end def test_nil_default_for_erb - assert_deprecated /Setting default charset at controller.*config\.action_dispatch\.default_charset/ do + assert_deprecated(/Setting default charset at controller.*config\.action_dispatch\.default_charset/) do begin OldContentTypeController.default_charset = nil get :render_default_for_erb diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 3922e3628d..b96987410f 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2574,7 +2574,6 @@ class TestUnicodePaths < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do match "/#{Rack::Utils.escape("ほげ")}" => lambda { |env| - path_params = env['action_dispatch.request.path_parameters'] [200, { 'Content-Type' => 'text/plain' }, []] }, :as => :unicode_path end diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index ec69d50d26..949deefa9d 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'rbconfig' module StaticTests def test_serves_dynamic_content @@ -30,32 +31,84 @@ module StaticTests assert_html "/foo/index.html", get("/foo") end - def test_serves_static_file_with_encoded_pchar - assert_html "/foo/foo!bar.html", get("/foo/foo%21bar.html") - assert_html "/foo/foo$bar.html", get("/foo/foo%24bar.html") - assert_html "/foo/foo&bar.html", get("/foo/foo%26bar.html") - assert_html "/foo/foo'bar.html", get("/foo/foo%27bar.html") - assert_html "/foo/foo(bar).html", get("/foo/foo%28bar%29.html") - assert_html "/foo/foo*bar.html", get("/foo/foo%2Abar.html") - assert_html "/foo/foo+bar.html", get("/foo/foo%2Bbar.html") - assert_html "/foo/foo,bar.html", get("/foo/foo%2Cbar.html") - assert_html "/foo/foo;bar.html", get("/foo/foo%3Bbar.html") - assert_html "/foo/foo:bar.html", get("/foo/foo%3Abar.html") - assert_html "/foo/foo@bar.html", get("/foo/foo%40bar.html") - end - - def test_serves_static_file_with_unencoded_pchar - assert_html "/foo/foo!bar.html", get("/foo/foo!bar.html") - assert_html "/foo/foo$bar.html", get("/foo/foo$bar.html") - assert_html "/foo/foo&bar.html", get("/foo/foo&bar.html") - assert_html "/foo/foo'bar.html", get("/foo/foo'bar.html") - assert_html "/foo/foo(bar).html", get("/foo/foo(bar).html") - assert_html "/foo/foo*bar.html", get("/foo/foo*bar.html") - assert_html "/foo/foo+bar.html", get("/foo/foo+bar.html") - assert_html "/foo/foo,bar.html", get("/foo/foo,bar.html") - assert_html "/foo/foo;bar.html", get("/foo/foo;bar.html") - assert_html "/foo/foo:bar.html", get("/foo/foo:bar.html") - assert_html "/foo/foo@bar.html", get("/foo/foo@bar.html") + def test_serves_static_file_with_exclamation_mark_in_filename + with_static_file "/foo/foo!bar.html" do |file| + assert_html file, get("/foo/foo%21bar.html") + assert_html file, get("/foo/foo!bar.html") + end + end + + def test_serves_static_file_with_dollar_sign_in_filename + with_static_file "/foo/foo$bar.html" do |file| + assert_html file, get("/foo/foo%24bar.html") + assert_html file, get("/foo/foo$bar.html") + end + end + + def test_serves_static_file_with_ampersand_in_filename + with_static_file "/foo/foo&bar.html" do |file| + assert_html file, get("/foo/foo%26bar.html") + assert_html file, get("/foo/foo&bar.html") + end + end + + def test_serves_static_file_with_apostrophe_in_filename + with_static_file "/foo/foo'bar.html" do |file| + assert_html file, get("/foo/foo%27bar.html") + assert_html file, get("/foo/foo'bar.html") + end + end + + def test_serves_static_file_with_parentheses_in_filename + with_static_file "/foo/foo(bar).html" do |file| + assert_html file, get("/foo/foo%28bar%29.html") + assert_html file, get("/foo/foo(bar).html") + end + end + + def test_serves_static_file_with_plus_sign_in_filename + with_static_file "/foo/foo+bar.html" do |file| + assert_html file, get("/foo/foo%2Bbar.html") + assert_html file, get("/foo/foo+bar.html") + end + end + + def test_serves_static_file_with_comma_in_filename + with_static_file "/foo/foo,bar.html" do |file| + assert_html file, get("/foo/foo%2Cbar.html") + assert_html file, get("/foo/foo,bar.html") + end + end + + def test_serves_static_file_with_semi_colon_in_filename + with_static_file "/foo/foo;bar.html" do |file| + assert_html file, get("/foo/foo%3Bbar.html") + assert_html file, get("/foo/foo;bar.html") + end + end + + def test_serves_static_file_with_at_symbol_in_filename + with_static_file "/foo/foo@bar.html" do |file| + assert_html file, get("/foo/foo%40bar.html") + assert_html file, get("/foo/foo@bar.html") + end + end + + # Windows doesn't allow \ / : * ? " < > | in filenames + unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ + def test_serves_static_file_with_colon + with_static_file "/foo/foo:bar.html" do |file| + assert_html file, get("/foo/foo%3Abar.html") + assert_html file, get("/foo/foo:bar.html") + end + end + + def test_serves_static_file_with_asterisk + with_static_file "/foo/foo*bar.html" do |file| + assert_html file, get("/foo/foo%2Abar.html") + assert_html file, get("/foo/foo*bar.html") + end + end end private @@ -68,6 +121,14 @@ module StaticTests def get(path) Rack::MockRequest.new(@app).request("GET", path) end + + def with_static_file(file) + path = "#{FIXTURE_LOAD_PATH}/public" + file + File.open(path, "wb+") { |f| f.write(file) } + yield file + ensure + File.delete(path) + end end class StaticTest < ActiveSupport::TestCase @@ -81,4 +142,4 @@ class StaticTest < ActiveSupport::TestCase end include StaticTests -end
\ No newline at end of file +end diff --git a/actionpack/test/fixtures/public/foo/foo!bar.html b/actionpack/test/fixtures/public/foo/foo!bar.html deleted file mode 100644 index 2928f2717f..0000000000 --- a/actionpack/test/fixtures/public/foo/foo!bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo!bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo$bar.html b/actionpack/test/fixtures/public/foo/foo$bar.html deleted file mode 100644 index 4f837df01d..0000000000 --- a/actionpack/test/fixtures/public/foo/foo$bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo$bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo&bar.html b/actionpack/test/fixtures/public/foo/foo&bar.html deleted file mode 100644 index c194e8de87..0000000000 --- a/actionpack/test/fixtures/public/foo/foo&bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo&bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo'bar.html b/actionpack/test/fixtures/public/foo/foo'bar.html deleted file mode 100644 index 25c3275736..0000000000 --- a/actionpack/test/fixtures/public/foo/foo'bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo'bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo(bar).html b/actionpack/test/fixtures/public/foo/foo(bar).html deleted file mode 100644 index 94fa4cb944..0000000000 --- a/actionpack/test/fixtures/public/foo/foo(bar).html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo(bar).html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo*bar.html b/actionpack/test/fixtures/public/foo/foo*bar.html deleted file mode 100644 index 79d5194c8d..0000000000 --- a/actionpack/test/fixtures/public/foo/foo*bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo*bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo+bar.html b/actionpack/test/fixtures/public/foo/foo+bar.html deleted file mode 100644 index 0fdc2ecabc..0000000000 --- a/actionpack/test/fixtures/public/foo/foo+bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo+bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo,bar.html b/actionpack/test/fixtures/public/foo/foo,bar.html deleted file mode 100644 index f040fce197..0000000000 --- a/actionpack/test/fixtures/public/foo/foo,bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo,bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo:bar.html b/actionpack/test/fixtures/public/foo/foo:bar.html deleted file mode 100644 index 7900a2642b..0000000000 --- a/actionpack/test/fixtures/public/foo/foo:bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo:bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo;bar.html b/actionpack/test/fixtures/public/foo/foo;bar.html deleted file mode 100644 index 2248376954..0000000000 --- a/actionpack/test/fixtures/public/foo/foo;bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo;bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo=bar.html b/actionpack/test/fixtures/public/foo/foo=bar.html deleted file mode 100644 index 206f69e286..0000000000 --- a/actionpack/test/fixtures/public/foo/foo=bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo=bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/public/foo/foo@bar.html b/actionpack/test/fixtures/public/foo/foo@bar.html deleted file mode 100644 index 4e8e90f9b8..0000000000 --- a/actionpack/test/fixtures/public/foo/foo@bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/foo@bar.html
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/one.html.erb b/actionpack/test/fixtures/test/one.html.erb new file mode 100644 index 0000000000..0151874809 --- /dev/null +++ b/actionpack/test/fixtures/test/one.html.erb @@ -0,0 +1 @@ +<%= render :partial => "test/two" %> world
\ No newline at end of file diff --git a/actionpack/test/fixtures/with_format.json.erb b/actionpack/test/fixtures/with_format.json.erb new file mode 100644 index 0000000000..a7f480ab1d --- /dev/null +++ b/actionpack/test/fixtures/with_format.json.erb @@ -0,0 +1 @@ +<%= render :partial => 'missing', :formats => [:json] %> diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index c65f707da0..96b14a0acd 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -78,9 +78,9 @@ class LookupContextTest < ActiveSupport::TestCase end test "found templates respects given formats if one cannot be found from template or handler" do - ActionView::Template::Handlers::ERB.expects(:default_format).returns(nil) + ActionView::Template::Handlers::Builder.expects(:default_format).returns(nil) @lookup_context.formats = [:text] - template = @lookup_context.find("hello_world", %w(test)) + template = @lookup_context.find("hello", %w(test)) assert_equal [:text], template.formats end diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb index ec777d15c4..80d6f130ed 100644 --- a/actionpack/test/template/record_tag_helper_test.rb +++ b/actionpack/test/template/record_tag_helper_test.rb @@ -1,15 +1,15 @@ require 'abstract_unit' require 'controller/fake_models' -class Post +class RecordTagPost extend ActiveModel::Naming include ActiveModel::Conversion - attr_writer :id, :body + attr_writer :id, :body, :persisted def initialize @id = nil @body = nil - super + @persisted = false end def id @@ -17,8 +17,11 @@ class Post end def body - super || @body || "What a wonderful world!" + @body || "What a wonderful world!" end + + def persisted?; @persisted end + end class RecordTagHelperTest < ActionView::TestCase @@ -28,30 +31,30 @@ class RecordTagHelperTest < ActionView::TestCase def setup super - @post = Post.new + @post = RecordTagPost.new @post.persisted = true end def test_content_tag_for - expected = %(<li class="post bar" id="post_45"></li>) + expected = %(<li class="record_tag_post bar" id="record_tag_post_45"></li>) actual = content_tag_for(:li, @post, :class => 'bar') { } assert_dom_equal expected, actual end def test_content_tag_for_prefix - expected = %(<ul class="archived_post" id="archived_post_45"></ul>) + expected = %(<ul class="archived_record_tag_post" id="archived_record_tag_post_45"></ul>) actual = content_tag_for(:ul, @post, :archived) { } assert_dom_equal expected, actual end def test_content_tag_for_with_extra_html_tags - expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>) + expected = %(<tr class="record_tag_post bar" id="record_tag_post_45" style='background-color: #f0f0f0'></tr>) actual = content_tag_for(:tr, @post, {:class => "bar", :style => "background-color: #f0f0f0"}) { } assert_dom_equal expected, actual end def test_block_not_in_erb_multiple_calls - expected = %(<div class="post bar" id="post_45">#{@post.body}</div>) + expected = %(<div class="record_tag_post bar" id="record_tag_post_45">#{@post.body}</div>) actual = div_for(@post, :class => "bar") { @post.body } assert_dom_equal expected, actual actual = div_for(@post, :class => "bar") { @post.body } @@ -59,29 +62,29 @@ class RecordTagHelperTest < ActionView::TestCase end def test_block_works_with_content_tag_for_in_erb - expected = %(<tr class="post" id="post_45">#{@post.body}</tr>) + expected = %(<tr class="record_tag_post" id="record_tag_post_45">#{@post.body}</tr>) actual = render_erb("<%= content_tag_for(:tr, @post) do %><%= @post.body %><% end %>") assert_dom_equal expected, actual end def test_div_for_in_erb - expected = %(<div class="post bar" id="post_45">#{@post.body}</div>) + expected = %(<div class="record_tag_post bar" id="record_tag_post_45">#{@post.body}</div>) actual = render_erb("<%= div_for(@post, :class => 'bar') do %><%= @post.body %><% end %>") assert_dom_equal expected, actual end def test_content_tag_for_collection - post_1 = Post.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true } - post_2 = Post.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true } - expected = %(<li class="post" id="post_101">Hello!</li>\n<li class="post" id="post_102">World!</li>) + post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true } + post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true } + expected = %(<li class="record_tag_post" id="record_tag_post_101">Hello!</li>\n<li class="record_tag_post" id="record_tag_post_102">World!</li>) actual = content_tag_for(:li, [post_1, post_2]) { |post| concat post.body } assert_dom_equal expected, actual end def test_div_for_collection - post_1 = Post.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true } - post_2 = Post.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true } - expected = %(<div class="post" id="post_101">Hello!</div>\n<div class="post" id="post_102">World!</div>) + post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true } + post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true } + expected = %(<div class="record_tag_post" id="record_tag_post_101">Hello!</div>\n<div class="record_tag_post" id="record_tag_post_102">World!</div>) actual = div_for([post_1, post_2]) { |post| concat post.body } assert_dom_equal expected, actual end @@ -92,8 +95,8 @@ class RecordTagHelperTest < ActionView::TestCase end def test_content_tag_for_collection_is_html_safe - post_1 = Post.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true } - post_2 = Post.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true } + post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true } + post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true } result = content_tag_for(:li, [post_1, post_2]) { |post| concat post.body } assert result.html_safe? end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index b1a866b148..503bbb207e 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -51,6 +51,18 @@ module RenderTestCases assert_match "<error>No Comment</error>", @view.render(:template => "comments/empty", :formats => [:xml]) end + def test_render_partial_implicitly_use_format_of_the_rendered_template + @view.lookup_context.formats = [:json] + assert_equal "Hello world", @view.render(:template => "test/one", :formats => [:html]) + end + + def test_render_template_with_a_missing_partial_of_another_format + @view.lookup_context.formats = [:html] + assert_raise ActionView::Template::Error, "Missing partial /missing with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder]}" do + @view.render(:template => "with_format", :formats => [:json]) + end + end + def test_render_file_with_locale assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => [:de]) assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => :de) @@ -329,6 +341,12 @@ module RenderTestCases ActionView::Template.register_template_handler :foo, CustomHandler assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end + + def test_render_knows_about_types_registered_when_extensions_are_checked_earlier_in_initialization + ActionView::Template::Handlers.extensions + ActionView::Template.register_template_handler :foo, CustomHandler + assert ActionView::Template::Handlers.extensions.include?(:foo) + end def test_render_ignores_templates_with_malformed_template_handlers ActiveSupport::Deprecation.silence do diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 13d30a93ce..dd45a08b01 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -11,6 +11,8 @@ class TestERBTemplate < ActiveSupport::TestCase def find_template(*args) end + + attr_accessor :formats end class Context |