This project is archived and is in readonly mode.

#5761 ✓committed
David Chelimsky

cookies hash in ActionDispatch::TestProcess should be indifferent access

Reported by David Chelimsky | October 6th, 2010 @ 02:29 PM

Consider:

class WelcomeController < ApplicationController
  def index
    cookies[:foo] = "bar"
    cookies["baz"] = "bam"
  end
end


class WelcomeControllerTest < ActionController::TestCase
  test "index sets :foo cookie (checked with a String key)" do
    get "index"
    assert_equal "bar", cookies["foo"] # => pass
  end

  test "index sets \"baz\" cookie (checked with a String key)" do
    get "index"
    assert_equal "bam", cookies["baz"] # => pass
  end
    
  test "index sets :foo cookie (checked with a Symbol key)" do
    get "index"
    assert_equal "bar", cookies[:foo] # => fail
  end

  test "index sets \"baz\" cookie (checked with a Symbol key)" do
    get "index"
    assert_equal "bam", cookies[:baz] # => fail
  end
end

The fact that we can set cookies with Symbols or Strings, but test them only with Symbols is confusing, leading to false-negatives when testing for non-nil values and false-positives when testing for nil values.

I'd recommend making converting the cookies hash in ActionDispatch::TestProcess to a HashWithIndifferentAccess. Patch forthcoming.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages