Rails tip: Functional testing ajax calls

Just a quick heads up for those of you who like to functional test their applications and are stuck trying to figure out how to pre-populate what your controllers see as @request.raw_post:


def test_image_assign
  @request.env['RAW_POST_DATA'] = "img_1"

  post :image_assign,
    :id => @first_article.id,
    :alignment => "right",
    :paragraph_id => 1

  assert_response :success
end

(taken from the Ajax-based image assignment function I blogged about earlier)

Filed Under: Development Rails