Rails and Functional Testing parameter pain

Eric PughNovember 8, 2006

Ruby on Rails once again lived up to my expectations that it is incredibly powerful, but can als cause real pain!

I had a functional test that proved that my action for dropping days from a calender of estimates worked. However, then when running the action through the webapp, it never actually dropped the days!

Well, thanks to Jamie Orchard Hays and Chris Hapgood at our local RubyJam, we discovered an “oddity” in how rails works. My action had logic like this:

date = params[:date]
....
if (estimate.date == date)
      estimate.destroy
end

And the estimates were never destoyed! But in my functional test call the estimates were destroyed:

dropdate = @sprint.start_date + 2

get :drop_day,{:id => @sprint.id, :date=> dropdate},{:current_user => @user}

So, it turns out that in my functional tests I was passing in dropdate as an actual Ruby Date object, but in the real web action, the date was coming in as a String! Therefore the call:

estimate.date == date

was never true! I changed my call for getting date to:

date = params[:date].to_date

and that fixed everything. However, what I think should ALSO have happened was the call to get :drop_day method should have converted everything to String, or whatever else you would expect params[] to return.




More blog articles:


Let's do a project together!

We provide tailored search, discovery and analytics solutions using Solr and Elasticsearch. Learn more about our service offerings