Forum: Ruby on Rails How to test a failing transaction

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Nick S. (Guest)
on 2006-01-07 21:52

I was wondering if somebody knows how I can make a transaction fail, so
I can test my rescue code. So a very basic transaction:

        Listing.transaction(@ad) do

            flash[:notice] = 'Ad was successfully created.'
            redirect_to :action => 'list'
            render :action => 'new'
      rescue => error
        flash[:warning] = 'An error has occurred'
        redirect_to :action => 'new'

But I want to test that I get redirected to 'new' and have a flash
message. All suggestions are welcome.

Kind regards,

Rick O. (Guest)
on 2006-01-07 22:40
(Received via mailing list)
On 1/7/06, Nick S. <removed_email_address@domain.invalid> wrote:
>             redirect_to :action => 'list'
> message. All suggestions are welcome.
> Kind regards,
> Nick

use! and pass in some data to  make the data invalid in your
test.  Be sure to use the uses_transaction method in your unit test
(or turn off transactional fixtures) when testing this.  You typically
can't have nested transactions (depending on DB I believe).

This topic is locked and can not be replied to.