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

Ticket #7372: test_session_indifferent_fixed_for_session_args.diff

File test_session_indifferent_fixed_for_session_args.diff, 3.0 kB (added by mhackett, 2 years ago)

New version of patch (same as [6086]) plus fix for bug introduced with session arguments to process method.

  • test/controller/test_test.rb

    old new  
    33 
    44class TestTest < Test::Unit::TestCase 
    55  class TestController < ActionController::Base 
     6    def no_op 
     7      render :text => 'dummy' 
     8    end 
     9 
    610    def set_flash 
    711      flash["test"] = ">#{flash["test"]}<" 
    812      render :text => 'ignore me' 
    913    end 
    1014 
     15    def set_session 
     16      session['string'] = 'A wonder' 
     17      session[:symbol] = 'it works' 
     18      render :text => 'Success' 
     19    end 
     20 
    1121    def render_raw_post 
    1222      raise Test::Unit::AssertionFailedError, "#raw_post is blank" if request.raw_post.blank? 
    1323      render :text => request.raw_post 
     
    111121    assert_equal '>value<', flash['test'] 
    112122  end 
    113123 
     124  def test_process_with_session 
     125    process :set_session 
     126    assert_equal 'A wonder', session['string'], "A value stored in the session should be available by string key" 
     127    assert_equal 'A wonder', session[:string], "Test session hash should allow indifferent access" 
     128    assert_equal 'it works', session['symbol'], "Test session hash should allow indifferent access" 
     129    assert_equal 'it works', session[:symbol], "Test session hash should allow indifferent access" 
     130  end 
     131 
     132  def test_process_with_session_arg 
     133    process :no_op, nil, { 'string' => 'value1', :symbol => 'value2' } 
     134    assert_equal 'value1', session['string'] 
     135    assert_equal 'value1', session[:string] 
     136    assert_equal 'value2', session['symbol'] 
     137    assert_equal 'value2', session[:symbol] 
     138  end 
     139 
    114140  def test_process_with_request_uri_with_no_params 
    115141    process :test_uri 
    116142    assert_equal "/test_test/test/test_uri", @response.body 
  • lib/action_controller/test_process.rb

    old new  
    283283 
    284284    def initialize(attributes = nil) 
    285285      @session_id = '' 
    286       @attributes = attributes 
     286      @attributes = attributes.nil? ? nil : attributes.stringify_keys 
    287287      @saved_attributes = nil 
    288288    end 
    289289 
     
    292292    end 
    293293 
    294294    def [](key) 
    295       data[key
     295      data[key.to_s
    296296    end 
    297297 
    298298    def []=(key, value) 
    299       data[key] = value 
     299      data[key.to_s] = value 
    300300    end 
    301301 
    302302    def update 
  • CHANGELOG

    old new  
    11*SVN* 
    22 
     3* TestSession initializer also supports indifferent access when a session hash is passed to process.  #7632 [tamc, Arsen7, mhackett] 
     4 
     5* TestSession supports indifferent access so session['foo'] == session[:foo] in your tests.  #7372 [julik, jean.helou] 
     6 
    37* Prefer MIME constants to strings.  #7707 [Dan Kubb] 
    48 
    59* Allow array and hash query parameters. Array route parameters are converted/to/a/path as before.  #6765, #7047, #7462 [bgipsy, Jeremy McAnally, Dan Kubb, brendan]