aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-17 12:00:23 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-17 12:54:19 -0700
commit4fad953f90f82e860a69d67745887b40d5b15475 (patch)
treef66c81f08091549160ce064dce257017f5567282
parentde388ba864ab47cbb3d92b3a36af254540788ed5 (diff)
downloadrails-4fad953f90f82e860a69d67745887b40d5b15475.tar.gz
rails-4fad953f90f82e860a69d67745887b40d5b15475.tar.bz2
rails-4fad953f90f82e860a69d67745887b40d5b15475.zip
Fixing pending tests and fixed some formats / partial rendering semantics
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb14
-rwxr-xr-xactionpack/lib/action_dispatch/http/request.rb10
-rw-r--r--actionpack/lib/action_view/base.rb2
-rw-r--r--actionpack/lib/action_view/template/handlers/rjs.rb1
-rw-r--r--actionpack/lib/action_view/template/path.rb3
-rw-r--r--actionpack/lib/action_view/template/template.rb2
-rw-r--r--actionpack/lib/action_view/template/text.rb2
-rw-r--r--actionpack/test/controller/layout_test.rb22
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb4
-rw-r--r--actionpack/test/lib/fixture_template.rb2
-rw-r--r--actionpack/test/new_base/render_rjs_test.rb46
-rw-r--r--actionpack/test/template/render_test.rb23
12 files changed, 74 insertions, 57 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index 25156a4c75..dda6604bdd 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -2,7 +2,19 @@ require 'set'
require 'active_support/core_ext/class/attribute_accessors'
module Mime
- SET = []
+ class Mimes < Array
+ def symbols
+ @symbols ||= map {|m| m.to_sym }
+ end
+
+ %w(<< concat shift unshift push pop []= clear compact! collect!
+ delete delete_at delete_if flatten! map! insert reject! reverse!
+ replace slice! sort! uniq!).each do |method|
+ define_method(method) { @symbols = nil; super }
+ end
+ end
+
+ SET = Mimes.new
EXTENSION_LOOKUP = {}
LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k.blank? }
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 140feb9a68..3f23a5af7a 100755
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -180,12 +180,10 @@ module ActionDispatch
else
accepts.dup
end.tap do |ret|
- if defined?(ActionController::Http)
- if ret == ONLY_ALL
- ret.replace Mime::SET
- elsif all = ret.index(Mime::ALL)
- ret.delete_at(all) && ret.insert(all, *Mime::SET)
- end
+ if ret == ONLY_ALL
+ ret.replace Mime::SET
+ elsif all = ret.index(Mime::ALL)
+ ret.delete_at(all) && ret.insert(all, *Mime::SET)
end
end
else
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 4ab568b44c..2d8f51300a 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -258,9 +258,11 @@ module ActionView #:nodoc:
def with_template(current_template)
last_template, self.template = template, current_template
+ old_formats, self.formats = formats, [current_template.mime_type.to_sym] + Mime::SET.symbols
yield
ensure
self.template = last_template
+ self.formats = old_formats
end
def punctuate_body!(part)
diff --git a/actionpack/lib/action_view/template/handlers/rjs.rb b/actionpack/lib/action_view/template/handlers/rjs.rb
index a36744c2b7..b1d15dc209 100644
--- a/actionpack/lib/action_view/template/handlers/rjs.rb
+++ b/actionpack/lib/action_view/template/handlers/rjs.rb
@@ -6,7 +6,6 @@ module ActionView
self.default_format = Mime::JS
def compile(template)
- "@formats = [:html];" +
"controller.response.content_type ||= Mime::JS;" +
"update_page do |page|;#{template.source}\nend"
end
diff --git a/actionpack/lib/action_view/template/path.rb b/actionpack/lib/action_view/template/path.rb
index 478bf96c9a..c3837a9f07 100644
--- a/actionpack/lib/action_view/template/path.rb
+++ b/actionpack/lib/action_view/template/path.rb
@@ -47,8 +47,7 @@ module ActionView
def formats_glob
@formats_glob ||= begin
- formats = Mime::SET.map { |m| m.symbol }
- '{' + formats.map { |l| ".#{l}," }.join + '}'
+ '{' + Mime::SET.symbols.map { |l| ".#{l}," }.join + '}'
end
end
diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb
index e7ea42c2eb..53aaa3dded 100644
--- a/actionpack/lib/action_view/template/template.rb
+++ b/actionpack/lib/action_view/template/template.rb
@@ -20,7 +20,7 @@ module ActionView
handler.respond_to?(:default_format) ? handler.default_format.to_sym.to_s : "html"
end
@mime_type = Mime::Type.lookup_by_extension(format.to_s)
- @details[:formats] = Array.wrap(format && format.to_sym)
+ @details[:formats] = Array.wrap(format.to_sym)
end
def render(view, locals, &blk)
diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb
index fd57b1677e..81944ff546 100644
--- a/actionpack/lib/action_view/template/text.rb
+++ b/actionpack/lib/action_view/template/text.rb
@@ -3,7 +3,7 @@ module ActionView #:nodoc:
def initialize(string, content_type = Mime[:html])
super(string.to_s)
- @content_type = Mime[content_type]
+ @content_type = Mime[content_type] || content_type
end
def details
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index c3d7b0778d..feb2f81cc1 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -165,26 +165,10 @@ class LayoutSetInResponseTest < ActionController::TestCase
assert_nil @controller.template.layout
end
- for_tag(:old_base) do
- # exempt_from_layout is deprecated
- def test_exempt_from_layout_honored_by_render_template
- ActionController::Base.exempt_from_layout :erb
- @controller = RenderWithTemplateOptionController.new
-
- get :hello
- assert_equal "alt/hello.rhtml", @response.body.strip
-
- ensure
- ActionController::Base.exempt_from_layout.delete(ERB)
- end
- end
-
def test_layout_is_picked_from_the_controller_instances_view_path
- pending do
- @controller = PrependsViewPathController.new
- get :hello
- assert_equal 'layouts/alt', @controller.template.layout
- end
+ @controller = PrependsViewPathController.new
+ get :hello
+ assert @controller.template.layout =~ /layouts\/alt\.\w+/
end
def test_absolute_pathed_layout
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb
index 27bdd10ee5..4ea0fedb8f 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -56,7 +56,7 @@ class MimeTypeTest < ActiveSupport::TestCase
test "type convenience methods" do
# Don't test Mime::ALL, since it Mime::ALL#html? == true
- types = Mime::SET.to_a.map{|m| m.to_sym }.uniq - [:all]
+ types = Mime::SET.symbols.uniq - [:all]
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
@@ -76,7 +76,7 @@ class MimeTypeTest < ActiveSupport::TestCase
end
test "verifiable mime types" do
- all_types = Mime::SET.to_a.map{|m| m.to_sym}
+ all_types = Mime::SET.symbols
all_types.uniq!
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb
index 59fb6819ed..4ea451879c 100644
--- a/actionpack/test/lib/fixture_template.rb
+++ b/actionpack/test/lib/fixture_template.rb
@@ -22,7 +22,7 @@ class Template
def formats_regexp
@formats_regexp ||= begin
- formats = Mime::SET.map { |m| m.symbol }
+ formats = Mime::SET.symbols
'(?:' + formats.map { |l| "\\.#{Regexp.escape(l.to_s)}" }.join('|') + ')?'
end
end
diff --git a/actionpack/test/new_base/render_rjs_test.rb b/actionpack/test/new_base/render_rjs_test.rb
new file mode 100644
index 0000000000..fdf3556e8e
--- /dev/null
+++ b/actionpack/test/new_base/render_rjs_test.rb
@@ -0,0 +1,46 @@
+require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+
+module RenderRjs
+
+ class BasicController < ActionController::Base
+
+ self.view_paths = [ActionView::Template::FixturePath.new(
+ "render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')",
+ "render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
+ "render_rjs/basic/_customer.js.erb" => "JS Partial",
+ "render_rjs/basic/_customer.html.erb" => "HTML Partial",
+ "render_rjs/basic/index_locale.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
+ "render_rjs/basic/_customer.da.html.erb" => "Danish HTML Partial",
+ "render_rjs/basic/_customer.da.js.erb" => "Danish JS Partial"
+ )]
+
+ def index
+ render
+ end
+
+ def index_locale
+ old_locale, I18n.locale = I18n.locale, :da
+ end
+
+ end
+
+ class TestBasic < SimpleRouteCase
+ testing BasicController
+
+ test "rendering a partial in an RJS template should pick the JS template over the HTML one" do
+ get :index
+ assert_response("$(\"customer\").update(\"JS Partial\");")
+ end
+
+ test "replacing an element with a partial in an RJS template should pick the HTML template over the JS one" do
+ get :index_html
+ assert_response("$(\"customer\").update(\"HTML Partial\");")
+ end
+
+ test "replacing an element with a partial in an RJS template with a locale should pick the localed HTML template" do
+ get :index_locale, :format => :js
+ assert_response("$(\"customer\").update(\"Danish HTML Partial\");")
+ end
+
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 2ed11aa3c0..45e3dc6f15 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -46,29 +46,6 @@ module RenderTestCases
I18n.locale = old_locale
end
- def test_render_implicit_html_template_from_xhr_request
- old_format = @view.formats
- pending do
- @view.formats = [:js]
- assert_equal "Hello HTML!", @view.render(:file => "test/render_implicit_html_template_from_xhr_request")
- end
- ensure
- @view.formats = old_format
- end
-
- def test_render_implicit_html_template_from_xhr_request_with_localization
- old_locale = I18n.locale
- old_format = @view.formats
- pending do
- I18n.locale = :da
- @view.formats = [:js]
- assert_equal "Hey HTML!\n", @view.render(:file => "test/render_implicit_html_template_from_xhr_request")
- end
- ensure
- I18n.locale = old_locale
- @view.formats = old_format
- end
-
def test_render_file_at_top_level
assert_equal 'Elastica', @view.render(:file => '/shared')
end