Forum: Ruby on Rails Problem destroying in unit tests with HABTM

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
51f10739fd903d3b57561a15e4598954?d=identicon&s=25 M Daggett (Guest)
on 2005-12-20 01:41
(Received via mailing list)
Hi converted two of my models to HABTM today but I am having a real
hard time getting my unit tests to pass now. Specifically, when I
destroy a record I get this error:

...many many lines of this above...
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_habtm_shim_for_categories'
  (eval):4:in `destroy_without_callbacks'
  c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/callbacks.rb:321:in
`destroy_witho
  c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/transactions.rb:122:in
`destroy'
  c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/transactions.rb:122:in
`transactio
  c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/transactions.rb:91:in
`transaction
  c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/transactions.rb:118:in
`transactio
  c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/transactions.rb:122:in
`destroy'


I have a category table an asset table and an assets_categories table

My destroy unit tests looks like this:

def test_destroy
	#check to ensure asset belongs to categories
        assert_equal false, @intl_image.categories.empty?
  	@intl_image.categories.clear
       #check to ensure the asset now belongs to no categories
  	assert_equal true, @intl_image.categories.empty?
  	@intl_image.save
  	@intl_image.reload
  	@img = Asset.find(@intl_image.id)
  	@img.destroy

assert_raise(ActiveRecord::RecordNotFound){Asset.find(@intl_image.id)}
end


Any help is greatly appreciated.
Thanks,
Mark

--
This topic is locked and can not be replied to.