Is there a standard or better way to verify that an action in rails returns the correct text? For example, I have a simple action that is used to perform an ajax check that does the following:
def get_object_id
if params[:id].blank?
return render(:text => -1, :layout => false)
end
my_object = MyObject.find_by_id(params[:id].strip)
if my_object and my_object.active?
return render(:text => my_object.id, :layout => false)
end
return render(:text => -1, :layout => false)
end
Right now I am using the @response object in my tests ... ie:
def test_get_object_id_returns_invalid_for_non_existent_id
get :get_object_id, :id => 999
assert_response :success
assert_equal "-1", @response.body
end
But, although I'm new to rails, what I have seen so far seems to suggest that there is probably a better way to do this, besides checking @request.body.
So, my question is for you experts rubies: is this the best way?
source
share