in application.rb rescue_from ActiveRecord::RecordNotFound { |e| http_status_code (:missing, e) } def http_status_code(status, exception) @exception = exception respond_to do |format| format.html { render :template => "shared/status_# {status.to_s}", :status => status } format.any { head status } end end in a controller project = Project.find(params[:id]) in my test def test_bad_project put :update, :id => KNOWN_BAD_ID assert_response(:missing) end The result is that I get a 500 every time. Any clues as to whats'' going on? There''s nothing in the log to explain the 500 I get during tests; the application controller seems to be detecting the exception and setting the status to 404, but my tests get 500. Dave --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 17 Nov 2008, at 16:39, davetron5000 wrote:> > in application.rb > > rescue_from ActiveRecord::RecordNotFound { |e| http_status_code > (:missing, e) } > > def http_status_code(status, exception) > @exception = exception > respond_to do |format| > format.html { render :template => "shared/status_# > {status.to_s}", :status => status } > format.any { head status } > end > end >IIRC the test harness snarfs the exception before it gets to your exception handler. Fred> in a controller > > project = Project.find(params[:id]) > > in my test > > def test_bad_project > put :update, :id => KNOWN_BAD_ID > assert_response(:missing) > end > > The result is that I get a 500 every time. > > Any clues as to whats'' going on? There''s nothing in the log to > explain the 500 I get during tests; the application controller seems > to be detecting the exception and setting the status to 404, but my > tests get 500. > > Dave > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The exception handler IS getting called (I put log statements in and they appear in test.log). In previous versions of rails, there seemed to be some sort of magic where a non-200 http response gets turned into a 500 for development, but not production. Is that the case, and if so, how do I deal with this? I need to test that the correct http responses are being sent... Dave On Nov 17, 11:54 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 17 Nov 2008, at 16:39, davetron5000 wrote: > > > > > in application.rb > > > rescue_from ActiveRecord::RecordNotFound { |e| http_status_code > > (:missing, e) } > > > def http_status_code(status, exception) > > @exception = exception > > respond_to do |format| > > format.html { render :template => "shared/status_# > > {status.to_s}", :status => status } > > format.any { head status } > > end > > end > > IIRC the test harness snarfs the exception before it gets to your > exception handler. > > Fred > > > in a controller > > > project = Project.find(params[:id]) > > > in my test > > > def test_bad_project > > put :update, :id => KNOWN_BAD_ID > > assert_response(:missing) > > end > > > The result is that I get a 500 every time. > > > Any clues as to whats'' going on? There''s nothing in the log to > > explain the 500 I get during tests; the application controller seems > > to be detecting the exception and setting the status to 404, but my > > tests get 500. > > > Dave--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---