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.

params are strings IRL, integers in test

#4339

If I'm not mistaken, integer parameters from a web server are always delivered to the controller as strings, but the test helpers #get, #post etc allow you to pass in integers. In my experience this leads to a lot of bugs and it might make sense to align the behavior more accurately.

Reported by mikeymicrophone · April 7th, 2010 @ 07:29 PM

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. David Trasbo
    David Trasbo

    This can be duplicated on edge Rails:

    class TestsController < ApplicationController
      def show
        render :text => params[:id].class.to_s
      end
    end
    
    require 'test_helper'
    
    class TestsControllerTest < ActionController::TestCase
      test "id param is a Fixnum" do
        get :show, :id => 42
        assert_equal 'Fixnum', response.body
      end
    end
    

    I definitely think this should be fixed. Since a controller will always receive all parameters as strings in real life, I think all parameters passed from tests should be converted to strings for consistency.

    April 12th, 2010 @ 10:36 AM

  2. Ryan Bigg
  3. Andrew White
  4. Ryan Bigg