Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7029447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:32:26+00:00 2026-05-28T00:32:26+00:00

In my app I have a model that has after_create and after_destroy methods that

  • 0

In my app I have a model that has after_create and after_destroy methods that create a directory and then destroy it respectively on the filesystem.

I’ve noticed in my RSpec request specs that the model records get created find (thus the directories get created), but I’m assuming the records are just deleted after each spec rather than destroyed, thus the directories hang around instead of being deleted. Either that or perhaps RSpec just rolls back the database transaction around the whole spec?

My question is, how can I make RSpec safely destroy these records so that the filesystem stays in sync?

I’ve tried:

after(:each) do
  Entity.destroy_all
end

and that works, but I’m not sure it’s the best way.

Perhaps I could be doing it better in my model itself so that if I detect a transaction rollback I can delete the directory then too? I’ve never heard of this functionality though bar perhaps in a begin rescue ensure block.

Any tips?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:32:27+00:00Added an answer on May 28, 2026 at 12:32 am

    Turns out that you can turn off transactions for certain spec’s like ones that need to completely add the record and run certain after callbacks. I also modified by after_create to an after_commit(:on => :create) (not 100% sure on the syntax, just taking that from memory) to add and remove filesystem elements because that’s the safest way to ensure that the record exists in the database before making the filesystem changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing app that has many, many models. I'd like to log
In my CakePHP 1.2.5 app, I have a Profile model that belongsTo a User
I have a very strange error happening in an App that has been working
I have a Ruby on Rails app that has a scheduled job I execute
I have an app that opens a non-modal form from the main form. The
I have a script that imports a models.py from an app, but it will
I have written a small app that puts my bluetooth in discoverable mode for
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class
I am working with Google App Engine and Python. I have a model with
I have a Comment model in my app but am encountering a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.