ActionController::TestCase#post repeats print of first parameters for every subsequent post call, even if they are different. #13803

Closed
starrychloe opened this Issue Jan 23, 2014 · 1 comment

Comments

Projects
None yet
2 participants

When calling #post, it will repeatedly print the parameters from the first #post call, even if the parameters are different. This is confusing.

  test "deposit" do
    post :deposit, {id: 4, deposit: "5.00", password: 'abc123', ccv: 100}, {user_id: 4}
    post :deposit, {id: 4, deposit: "6.00", password: 'abc123', ccv: 100}, {user_id: 4}

Notice the deposit changed from 5 to 6? This is what it prints.

UsersControllerTest: test_deposit
--------------------------------------
Processing by UsersController#deposit as HTML
  Parameters: {"deposit"=>"5.00", "password"=>"[FILTERED]", "ccv"=>"100", "id"=>"4"}
"******************** {\"deposit\"=>\"5.00\", \"password\"=>\"abc123\", \"ccv\"=>\"100\", \"id\"=>\"4\", \"controller\"=>\"users\", \"action\"=>\"deposit\"}"
Redirected to http://test.host/users/4/balance
Completed 302 Found in 2756ms (ActiveRecord: 7.0ms)
Processing by UsersController#deposit as HTML
  Parameters: {"deposit"=>"5.00", "password"=>"[FILTERED]", "ccv"=>"100", "id"=>"4"}
"******************** {\"deposit\"=>\"6.00\", \"password\"=>\"abc123\", \"ccv\"=>\"100\", \"id\"=>\"4\", \"controller\"=>\"users\", \"action\"=>\"deposit\"}"

I had to add this debug line in the UsersController to find the problem:

  def deposit
    p "******************** " + params.to_hash.to_s
Member

chancancode commented Jan 26, 2014

@pixeltrix pixeltrix closed this in 3161606 Jan 27, 2014

pixeltrix added a commit that referenced this issue Jan 27, 2014

Clear filtered request attributes between requests in tests
The request attributes filtered_parameters, filtered_env and filtered_path
are memoized for performance reasons. However this can cause unusual
behavior in tests where there are multiple calls to get, post, etc.

Fixes #13803.

(cherry picked from commit 3161606)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment