mongoid/mongoid — Issue #1589: habt assignment of empty array broken
Author: dblock
Created: 2012-01-12 20:44:15+00:00
State: open

```

require "spec_helper"

class Exhibitor
include Mongoid::Document
has_and_belongs_to_many :artworks
end

class Artwork
include Mongoid::Document
has_and_belongs_to_many :exhibitors
end

describe "Test" do

before do
[ Exhibitor, Artwork ].each(&:delete_all)
end

describe "works" do

it "sometimes" do
exhibitor = Exhibitor.create!
artwork = Artwork.create!
exhibitor.artworks = [ artwork ]
exhibitor.save!
exhibitor.artworks.count.should == 1

exhibitor = Exhibitor.find(exhibitor.id)
exhibitor.artworks.count.should == 1
exhibitor.artworks = [] # assigning to nil here works, maybe acceptable workaround for now
exhibitor.save!
Exhibitor.find(exhibitor.id).artworks.count.should == 0 # returns 1
end

end

end
```