Displaying 20 results from an estimated 40000 matches similar to: "rescue_from and assert_raise"
2009 Feb 10
2
rescue_from for NoMethodError
Hi everyone,
I was just trying to catch some exceptions in my app,
for "Record Not Found" I used this
in my application.rb file
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
rescue_from ActionController::NoMethodError, :with => :show_error
private
def record_not_found
render :text => "404 Not Found", :status =>
2008 Apr 30
7
rescue_from issue with AWS - uninitialized constant
The new rescue_from in edge rails seems to conflict with
ActionWebService, which I need for various other purposes. When I
define, for example (with AWS gem installed):
<b>rescue_from ActionController::RoutingError, :with
=> :page_not_found</b>
I get the exception:
<b>uninitialized constant
ActionWebService::Dispatcher::ActionController::Base</b>
OK, so AWS
2007 Oct 21
7
exact exceptions in rescue_from
rescue_from stores exception class names in a hash table, and
associates them with handlers.
When an exception is raised there''s a name lookup, and if an entry is
found its handler is invoked. In particular rescue_from does not
emulate Ruby''s rescue semantics with regard to inheritance.
Which is the rationale? Don''t you think taking is_a? and declaration
order
2007 Dec 22
8
Rails 2.0 rescue_from
I am trying to use the new Rails 2.0 macro : rescue_from
class PostsController < ApplicationController
rescue_from ActiveRecord::RecordNotFound, :with => :deny_access
...
def show
@post = Post.find_by_id(params[:id])
raise ActiveRecord::RecordNotFound if @post.nil? #illegal access
.....
end
def deny_access
respond_to do |format|
format.html
end
end
but the
2006 Nov 22
1
Using assert_raise
When Im writing tests and I do:
assert_raise RuntimeError, raise("raising")
Then I run the test is says the test failed and I have 1 error:
RuntimeError: hey
Should assert_raise catch that error and say the test passed?
Thanks for your time and help.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because
2008 Feb 07
2
Catching non-Merb::ControllerExceptions Exceptions
Is there an agreed upon method for handling exceptions thrown by
something outside of Merb? For example, DataMapper now throws a
DataMapper::ObjectNotFoundError when a record isn''t found in the db.
I''d like to catch these exceptions and raise a C:E:NotFound exception
instead, but without having to wrap a lot of code in begin/rescue/end
blocks.
Thanks,
Mike Irwin
2009 Apr 03
0
Truncated development log when using rescue_from
I''m noticing that my development.log messages are not showing the usual
complete logging per request/response when I am catching exceptions from
my controllers using rescue_from. I was wondering if anyone has ever
encountered this issue before. I''m using Rails 2.2.2.
Processing DomainsController#show to xml (for 127.0.0.1 at 2009-04-03
16:41:38) [GET]
Parameters:
2006 Jul 18
2
Testing which RuntimeError is raised
I am just starting to use unit testing. Way cool. But I am not finding
very clear docs on assert_raise. I have managed to write a test that
tells me that the destroy I am trying to test fails with a
RuntimeError (as it should). However, I would really like to test that
it rails for the specific reason I have in my model. How can I get
more specific? Am I going to have to create my own exception
2009 Dec 25
18
rescue_from ActionController::RoutingError II
OK ... so I''m not supposed to use it but ...
Why doesn''t rescue_from ActionController::RoutingError work witht he
code from
http://www.rubyplus.org/episodes/20-Extended-RESTful-Authentication-Rails-2-App.html
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
# See ActionController::RequestForgeryProtection for details
2008 Aug 21
1
rescue_from failing to rescue [from]
Having some weird failures of rescue_from in all my specs. They still
rescue in actual usage, just not in my specs. Made a pastie of the code:
http://pastie.org/257399 This is with latest [as of 1:00 PM Eastern time
zone] rspec/rspec-rails/edge. Thanks in advance for any replies on this.
RSL
--
Posted via http://www.ruby-forum.com/.
2008 Sep 02
4
Rescue rails errors
Hi all,
Sometime, I get the following error in my application:
ActionController::InvalidAuthenticityToken in
ManageController#site_servers
ActionController::InvalidAuthenticityToken
I tried to put the code in manage controller between begin ... rescue
... end but it didn''t catch the error.
So I tried in the application.rb controller, I put the forgery code
between begin ... rescue ...
2006 Dec 28
0
problem with assert_raise in Unit Test
I''m running a simple unit test to validate that ActiveRecord raises an
exception when I try and update a column with a duplicate foreign key.
Inside the unit test,
charge.time_logs << time_logs(:first)
will generate
ActiveRecord::StatementInvalid: Mysql::Error: #23000Duplicate entry
''20'' for key 2: UPDATE time_logs SET `task_id` = 1, `date_created` =
NULL,
2008 Aug 01
1
rescue_from ActionController::MethodNotAllowed
Hello,
I''m having some trouble handing ActionController::MethodNotAllowed
errors. Basically, the following is defined in my controllers, but
obviously I''m missing something. Thanks in advance for any light you
can shed.
- - - - - - - - - - - - - - - - - - - -
class UsersController < ApplicationController
rescue_from ActionController::MethodNotAllowed, :with
=>
2013 Nov 12
7
Hook into Exception Chain
Hi there,
I''m using Log4r in my rails projects. On log.error an email is sent using
the EmailOutputter.
I know changed the EmailOutputter to include a global var in the subject
(MDC) since the subject is normally static.
I want to set this var to the exception message, so it is sent as the
subject.
Can anyone tell me how to do this in rails?
Basically:
raise e or some other cause
2006 May 06
6
assert_raises --> how does it work?
Hi,
I have this code fragment:
def test_delete_concept
assert_not_nil Concept.find(concepts(:entreprise).id)
get :delete_concept, {:concept_id => concepts(:entreprise).id}
assert_raises :RecordNotFound,
Concept.find(concepts(:entreprise).id)
end
basicaly, on the first line, I make sure that the concept exist in the
DB. On the second line I delete the concept fron the DB.
2009 Mar 20
1
bypass_rescue and its inverse
Hey,
I''ve just started using rspec-rails 1.2 and the bypass rescue
declaration is wonderful - by default I tend to write controller which
raise exceptions (in exceptional circumstances), along with before-
filters as guard clauses, so being able to switch off rescue from
(which I properly spec separately) is a real boon.
Such a boon, in fact, that I immediately shoved it into a
2008 Nov 17
2
Can't seem to test http error codes
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 =
2006 Jan 28
1
Unit Tests Behavior
Hi,
Working on unit tests and I have a few cascade delete constraints I am
testing.
The unit tests stop at the first assert_raise test. Is this typical?
def test_destroy_all_cascade_delete
assert_equal 1, Iep.find(:first).client_id
assert_equal 1, Encounter.find(:first).client_id
@client.destroy
assert_raise(ActiveRecord::RecordNotFound) { Iep.find(1) } <--
2010 Aug 09
0
Exceptions in functional tests (rescue_action_in_public! broken?)
In 2.3, exceptions raised by controllers under functional tests were by
default propagated to the test, but by using rescue_action_in_public! a test
could trigger the production, public behavior and then use assert_response
or similar to test the expected result. This was implemented via
coordination between ActionController::Rescue and
ActionController::TestCase::RaiseActionExceptions.
This
2010 Jul 26
2
Exception Pages when behind a proxy
I am not sure if this desired feature or not but when we are behind a
local proxy ie. Nginx/Varnish then the new ShowException middleware
doesn''t seem to properly detect the remote IP address and it appears
as if every browser gets a local error page with a stack trace, etc.
I''ve opened up a ticket on the rails bug tracker but I also would like
to verify that this is in fact a