Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6808: json_layout_patch.diff

File json_layout_patch.diff, 1.7 kB (added by josh, 2 years ago)

Patch that fixes bug along with unit tests.

  • test/controller/render_test.rb

    old new  
    4747    render_json({:hello => 'world'}.to_json, 'alert') 
    4848  end 
    4949 
     50  def render_symbol_json 
     51    render :json => {:hello => 'world'}.to_json 
     52  end 
     53 
    5054  def render_custom_code 
    5155    render_text "hello world", "404 Moved" 
    5256  end 
     
    125129      case action_name 
    126130        when "layout_test":         "layouts/standard" 
    127131        when "builder_layout_test": "layouts/builder" 
     132        when "render_symbol_json":  "layouts/standard"  # to make sure layouts don't interfere 
    128133      end 
    129134    end 
    130135end 
     
    184189    assert_equal 'application/json', @response.content_type 
    185190  end 
    186191 
     192  def test_do_with_render_symbol_json 
     193    get :render_symbol_json 
     194    assert_equal '{hello: "world"}', @response.body 
     195    assert_equal 'application/json', @response.content_type 
     196  end 
     197 
    187198  def test_do_with_render_custom_code 
    188199    get :render_custom_code 
    189200    assert_response 404 
  • lib/action_controller/layout.rb

    old new  
    266266 
    267267      def candidate_for_layout?(options) 
    268268        (options.has_key?(:layout) && options[:layout] != false) ||  
    269         options.values_at(:text, :xml, :file, :inline, :partial, :nothing).compact.empty? && 
     269        options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing).compact.empty? && 
    270270        !template_exempt_from_layout?(default_template_name(options[:action] || options[:template])) 
    271271      end 
    272272