I'm trying to test an active record object destroy failure but I'm having problems creating a failure situation. I have a before_filter method called 'require_user_payment_info' which validates the @payment_info object before the delete method is called so I can't create a 'bad' @payment_info object before the delete method is called.
Here's the require_user_payment_info method:
@payment_info = credit_card_model.slave.find_by_user_guid(user_guid)
if !@payment_info || @payment_info.user_guid != user_guid
redirect_to(:controller => 'store', :action => 'index') and return false
if((@payment_info.card_expires_year.to_i < Date.today.year) ||
((@payment_info.card_expires_month.to_i < Date.today.month) && (@payment_info.card_expires_year.to_i == Date.today.year)))
@payment_info.card_account_public = "" #clear this out so the user is forced to re-enter the credit card number
flash.now[:error] = t('ui_flash_errors.card_expired_error')
And the actual delete method:
# required to be called via a delete request
redirect_to :action => 'edit' and return if !request.delete?
flash[:notice] = "Delete SUCCESSFUL"
redirect_to :action => 'new'
flash[:error] = "Delete failed"
redirect_to :action => 'edit'