diff options
| -rw-r--r-- | actionpack/lib/action_controller/abstract/base.rb | 6 | ||||
| -rw-r--r-- | actionpack/lib/action_controller/abstract/layouts.rb | 16 | ||||
| -rwxr-xr-x | actionpack/lib/action_dispatch/http/request.rb | 10 | ||||
| -rw-r--r-- | actionpack/test/fixtures/test/greeting.html.erb (renamed from actionpack/test/fixtures/test/greeting.erb) | 0 | ||||
| -rw-r--r-- | actionpack/test/new_base/render_layout_test.rb | 32 | ||||
| -rw-r--r-- | actionpack/test/new_base/test_helper.rb | 2 | 
6 files changed, 52 insertions, 14 deletions
diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb index 1f2f096dae..0e4803388a 100644 --- a/actionpack/lib/action_controller/abstract/base.rb +++ b/actionpack/lib/action_controller/abstract/base.rb @@ -68,11 +68,11 @@ module AbstractController        self.response_obj = {}      end -    def process(action_name) -      @_action_name = action_name = action_name.to_s +    def process(action) +      @_action_name = action_name = action.to_s        unless action_name = method_for_action(action_name) -        raise ActionNotFound, "The action '#{action_name}' could not be found" +        raise ActionNotFound, "The action '#{action}' could not be found"        end        process_action(action_name) diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb index 8721e5f4dc..3d6810bda9 100644 --- a/actionpack/lib/action_controller/abstract/layouts.rb +++ b/actionpack/lib/action_controller/abstract/layouts.rb @@ -39,15 +39,15 @@ module AbstractController        def _write_layout_method          case @_layout          when String -          self.class_eval %{def _layout() #{@_layout.inspect} end} +          self.class_eval %{def _layout(details) #{@_layout.inspect} end}          when Symbol -          self.class_eval %{def _layout() #{@_layout} end} +          self.class_eval %{def _layout(details) #{@_layout} end}          when false -          self.class_eval %{def _layout() end} +          self.class_eval %{def _layout(details) end}          else            self.class_eval %{ -            def _layout -              if view_paths.find_by_parts?("#{_implied_layout_name}", {:formats => formats}, "layouts") +            def _layout(details) +              if view_paths.find_by_parts?("#{_implied_layout_name}", details, "layouts")                  "#{_implied_layout_name}"                else                  super @@ -60,7 +60,7 @@ module AbstractController    private -    def _layout() end # This will be overwritten +    def _layout(details) end # This will be overwritten      # :api: plugin      # ==== @@ -79,13 +79,13 @@ module AbstractController      end      def _default_layout(require_layout = false, details = {:formats => formats}) -      if require_layout && _action_has_layout? && !_layout +      if require_layout && _action_has_layout? && !_layout(details)          raise ArgumentError,            "There was no default layout for #{self.class} in #{view_paths.inspect}"        end        begin -        _layout_for_name(_layout, details) if _action_has_layout? +        _layout_for_name(_layout(details), details) if _action_has_layout?        rescue NameError => e          raise NoMethodError,             "You specified #{@_layout.inspect} as the layout, but no such method was found" diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 4831b89bde..259164d118 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -173,9 +173,15 @@ module ActionDispatch      def formats        if ActionController::Base.use_accept_header -        Array(Mime[parameters[:format]] || accepts) +        ret = Array(Mime[parameters[:format]] || accepts) +        if defined?(ActionController::Http) +          if all = ret.index(Mime::ALL) +            ret.delete(Mime::ALL) && ret.insert(all, *Mime::SET) +          end +        end +        ret        else -        [format, Mime[:all]] +        [format]  + Mime::SET        end      end diff --git a/actionpack/test/fixtures/test/greeting.erb b/actionpack/test/fixtures/test/greeting.html.erb index 62fb0293f0..62fb0293f0 100644 --- a/actionpack/test/fixtures/test/greeting.erb +++ b/actionpack/test/fixtures/test/greeting.html.erb diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb index 76bd5175a3..f32c60d683 100644 --- a/actionpack/test/new_base/render_layout_test.rb +++ b/actionpack/test/new_base/render_layout_test.rb @@ -66,4 +66,36 @@ module ControllerLayouts        assert_response "hai(layout_false.html.erb)"      end    end + +  class MismatchFormatController < ::ApplicationController +    self.view_paths = [ActionView::Template::FixturePath.new( +      "layouts/application.html.erb" => "<html><%= yield %></html>", +      "controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg", +      "controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg"       +    )] + +    def explicit +      render :layout => "application" +    end +  end + +  class MismatchFormatTest < SimpleRouteCase +    testing ControllerLayouts::MismatchFormatController + +    test "if JS is selected, an HTML template is not also selected" do +      get :index +      assert_response "$(\"test\").omg();" +    end + +    test "if JS is implicitly selected, an HTML template is not also selected" do +      get :implicit +      assert_response "$(\"test\").omg();" +    end + +    test "if an HTML template is explicitly provides for a JS template, an error is raised" do +      assert_raises ActionView::MissingTemplate do +        get :explicit, {}, "action_dispatch.show_exceptions" => false +      end +    end +  end  end
\ No newline at end of file diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index 89c1290063..d92029df7f 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -67,7 +67,7 @@ class Rack::TestCase < ActionController::IntegrationTest    def get(thing, *args)      if thing.is_a?(Symbol) -      super("#{self.class.testing}/#{thing}") +      super("#{self.class.testing}/#{thing}", *args)      else        super      end  | 
