-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Unknown
-
Affects Version/s: 8.0.10, 8.1.10
-
Component/s: None
-
None
The following tests used to pass in MONGOID_VERSION=7.5.4
require 'bundler/inline' require 'logger' gemfile do source "https://rubygems.org" gem "mongoid", "#{ENV["MONGOID_VERSION"] || '8.0.10'}" gem "debug", "~> 1.7" gem "rspec", require: "rspec/autorun" end require 'mongoid' Mongoid.configure do |config| config.clients.default = { hosts: ['localhost:27017'], database: 'mongoid8_test', } config.log_level = :debug end puts Mongoid::VERSION class Band include Mongoid::Document include Mongoid::Attributes::Dynamic field :name, type: String embeds_many :labels end class Label include Mongoid::Document include Mongoid::Timestamps::Updated::Short field :name, type: String embedded_in :band end Band.delete_all Label.delete_all describe Band do context "when trying to persist the empty list" do context "in an embeds_many relation" do # let(:band) { Band.create } # this seems to work let(:band) { Band.new } before do band.labels = [] band.save! end let(:reloaded_band) { Band.collection.find(_id: band._id).first } it "persists the empty list" do expect(reloaded_band).to have_key(:labels) expect(reloaded_band[:labels]).to eq [] end end context "using before_save callback" do let(:band) { Band.create } before do Band.before_save do self[:labels] ||= [] end end let(:reloaded_band) { Band.collection.find(_id: band._id).first } it "persists the empty list" do expect(reloaded_band).to have_key(:labels) expect(reloaded_band[:labels]).to eq [] end end end end
Might be related to https://jira.mongodb.org/browse/MONGOID-4869