Topic: test_destroy fails in functionaltest

def test_destroy
    assert_nothing_raised {
      User.find(1)
    }

    post :destroy, :id => 1
    assert_response :redirect
    assert_redirected_to :action => 'list'

    assert_raise(ActiveRecord::RecordNotFound) {
      User.find(1)
    }
  end
here i got error like

Exception: Mysql::Error: #23000Cannot delete or update a parent row: a foreign key constraint fails (`contact_market/user_friends`, CONSTRAINT `friend` FOREIGN KEY (`friend`) REFERENCES `users` (`id`)):             DELETE FROM users
            WHERE `id` = 1

C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract_adapter.rb:128:in `log'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:243:in `execute'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:258:in `update'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:47:in `delete'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1558:in `destroy_without_callbacks'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:321:in `destroy_without_transactions'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:125:in `destroy'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'

Re: test_destroy fails in functionaltest

swapna,

Could you provide the following info:

1. your [bold]fixtures[/bold] line at the top of your functional test
2. a description of your database schema, especially the layout of your users table

Also, did you know that you can use the 'code' BBCode tag for ease of displaying code in this forum?


c.