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

  • Home
  • SEARCH
  • 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 8064859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:29:35+00:00 2026-06-05T11:29:35+00:00

I have intermittently (on various projects) had problems with rspec reloading an ActiveRecord object

  • 0

I have intermittently (on various projects) had problems with rspec reloading an ActiveRecord object and then having the associated objects cleared, too.

An example of a failing spec that “should” work is as follows (ignore “goodness” of tests, this is a simplified example):

# Message has_many :message_attachments
# MessageAttachment belongs_to :message
describe Message, 'instance' do
  before(:each) do
    @it = Factory(:message)

    (1..3).each do
      @it.message_attachments << Factory(:message_attachment, :message => @it)
    end
  end

  it 'should order correctly' do
    # This test will pass
    @it.message_attachments.collect(&:id).should == [1, 2, 3]
  end

  it 'should reorder correctly' do
    @it.reorder_attachments([6, 4, 5])
    @it.reload
    # @it.message_attachments is [] now.
    @it.message_attachments.collect(&:id).should == [6, 4, 5]
  end
end
  • 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-06-05T11:29:36+00:00Added an answer on June 5, 2026 at 11:29 am

    Strangely, to fix this I have to create the associated object with a defined parent object and also attach it to the parent object’s collection:

    describe Message, 'instance' do
      before(:each) do
        @it = Factory(:message)
    
        (1..3).each do
          ma = Factory(:message_attachment, :message => @it)
          @it.message_attachments << ma
          ma.save
        end
      end
    
      it 'should order correctly' do
        @it.message_attachments.collect(&:id).should == [1, 2, 3]
      end
    
      it 'should reorder correctly' do
        @it.reorder_attachments([6, 4, 5])
        @it.reload
        @it.message_attachments.collect(&:id).should == [6, 4, 5]
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see a number of posts on the various problems folks have with troubleshooting
I'm having problems with jetty crashing intermittently, I'm using Jetty 6.1.24. I'm running a
I have a Windows server that is intermittently losing the ability to lookup DNS
I have a Windows server that is intermittently losing the ability to lookup DNS
I have a .NET client app that intermittently loses connection to a UNC share
have written this little class, which generates a UUID every time an object of
I have an ImageView object that I'm setting the android:src=@drawable/some_xml_file instead of a standard
I have a faulty hard drive that works intermittently. After cold booting, I can
I have some jsp pages that connect to a mysql database and I intermittently
My (Sinatra) app intermittently goes into a bad state that I have only been

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.