Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

cookies hash in ActionDispatch::TestProcess should be indifferent access

#5761

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.

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

State: committed
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. David Trasbo
    David Trasbo
    • State changed from new to open
    • Importance changed from to Low

    +1

    I'd even say that cookies not being indifferent access is unexpected behavior.

    David, are you still planning on making a patch for this? I'd be happy to.

    October 10th, 2010 @ 06:28 PM

  2. David Chelimsky
    David Chelimsky

    @DavidTrasbo, please have at it. Thanks!

    October 10th, 2010 @ 06:32 PM

  3. David Trasbo
  4. Andrea Campi
    Andrea Campi
    • Tag set to actionpack, patch, tests

    +1 on the patch.

    October 16th, 2010 @ 09:35 PM

  5. Repository
    Repository
    • State changed from open to committed

    November 7th, 2010 @ 07:04 PM