Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1176

Regression in 2.1.9

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.2.0
    • Affects Version/s: None
    • Component/s: None
    • None

      The following code was working with 2.1.8, but was broken in 2.1.9 (of course it breaks other specs as well):

      Factory.define :user do |user|
        user.sequence(:name) {|n| "Factory User #{n}"}
        user.sequence(:email) {|n| "user#{n}@example.com"}
        user.password 'password'
        user.password_confirmation 'password'
      
        user.after_build do |u|
          u.businesses = [Factory(:business, :owners => [u])] if u.businesses.empty?
          u.confirmed_at = Time.now
        end
      end
      

      and the corresponding factory spec:

      describe 'User' do
          let(:user) { Factory(:user) }
      
          it "is valid" do
            user.should be_valid
          end
      
          it "has a business" do
            b = user.businesses
            b.should_not be_empty
            b.first.should be_a_kind_of(Business)
            b.first.owner.should == user
          end
      
        end
      

      Note: Business#owners and User#businesses are 'references_and_referenced_in_many', Business#owner is 'owners.first'

      By using git bisect I found that the following commit is the culprit:

      <pre>
      commit 524970690416acde1de62a6f3ef41e2c01e93065
      Author: Durran Jordan
      Date: Thu Aug 18 16:35:48 2011 +0200

      Setting a many to many to nil or empty does not delete the related documents. Fixes MONGOID-1155
      </pre>

      After reverting the change, all spec failures went away.

            Assignee:
            Unassigned Unassigned
            Reporter:
            romanbsd Roman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: