In my models
class User < ActiveRecord::Base
has_one :user_detail, dependent: :destroy
end
and
class UserDetail < ActiveRecord::Base
belongs_to :user
end
When I call destroy for an User object, the associated UserDetail object is not being destroyed.
Here's a test (of course, it fails because user_detail
is not nil):
test "associate object should be destroyed" do
user_id = @user.id
@user.destroy
user_detail = UserDetail.find_by(:user_id => user_id)
assert_nil user_detail
end
Does anyone have any idea why this happens?